Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tools/importer-rest-api-specs: flagging fields that are expected to be Computed in the Terraform Schema to be ReadOnly for now #3899

Merged
merged 4 commits into from
Feb 28, 2024

Conversation

tombuildsstuff
Copy link
Contributor

This PR works around an issue described in #3895 where due to an issue when parsing the Swaggers the ReadOnly information is inconsistent - meaning that currently when generating Terraform Resources, an issue exists where fields that should be marked as Computed aren't being picked up as such - the results can be seen in hashicorp/terraform-provider-azurerm#25052.

This issue stems from the fact that we now explicitly differentiate values which are ReadOnly from those which aren't, since we're now canonically using the SDKModel type throughout - meaning that when generating the Terraform Schema for the specified resource we're using the SDKField's ReadOnly property to indicate that the associated Terraform Schema Field should be marked as Computed.

Since the root cause of this issue is an issue when parsing the Swagger definitions - this PR intentionally applies a Data Workaround rather than attempting to patch this within the Terraform side of things - which isn't ideal, but feels like the right place to apply this since we'll need to look into #3895 once the refactoring is completed.

Ultimately this PR means that the changes from hashicorp/terraform-provider-azurerm#25052 become a noop - which'll fix the Terraform Generator.


Changes as a result of this diff:

diff --git a/api-definitions/resource-manager/ContainerService/2022-09-02-preview/Fleets/Model-FleetHubProfile.json b/api-definitions/resource-manager/ContainerService/2022-09-02-preview/Fleets/Model-FleetHubProfile.json
index 34977bf444..50fd861647 100644
--- a/api-definitions/resource-manager/ContainerService/2022-09-02-preview/Fleets/Model-FleetHubProfile.json
+++ b/api-definitions/resource-manager/ContainerService/2022-09-02-preview/Fleets/Model-FleetHubProfile.json
@@ -22,8 +22,8 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
-      "readOnly": false,
+      "optional": false,
+      "readOnly": true,
       "required": false,
       "sensitive": false
     },
@@ -35,8 +35,8 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
-      "readOnly": false,
+      "optional": false,
+      "readOnly": true,
       "required": false,
       "sensitive": false
     }
diff --git a/api-definitions/resource-manager/ContainerService/Terraform/KubernetesFleetManager-Resource-Schema-FleetHubProfile.json b/api-definitions/resource-manager/ContainerService/Terraform/KubernetesFleetManager-Resource-Schema-FleetHubProfile.json
index b51ff56bc1..69bc393e7c 100644
--- a/api-definitions/resource-manager/ContainerService/Terraform/KubernetesFleetManager-Resource-Schema-FleetHubProfile.json
+++ b/api-definitions/resource-manager/ContainerService/Terraform/KubernetesFleetManager-Resource-Schema-FleetHubProfile.json
@@ -10,8 +10,8 @@
       "required": true
     },
     {
+      "computed": true,
       "hclName": "fqdn",
-      "optional": true,
       "name": "Fqdn",
       "objectDefinition": {
         "referenceName": null,
@@ -19,8 +19,8 @@
       }
     },
     {
+      "computed": true,
       "hclName": "kubernetes_version",
-      "optional": true,
       "name": "KubernetesVersion",
       "objectDefinition": {
         "referenceName": null,
diff --git a/api-definitions/resource-manager/ContainerService/Terraform/Tests/KubernetesFleetManager-Resource-Complete-Test.hcl b/api-definitions/resource-manager/ContainerService/Terraform/Tests/KubernetesFleetManager-Resource-Complete-Test.hcl
index 88f2913f0a..01b0ade42d 100644
--- a/api-definitions/resource-manager/ContainerService/Terraform/Tests/KubernetesFleetManager-Resource-Complete-Test.hcl
+++ b/api-definitions/resource-manager/ContainerService/Terraform/Tests/KubernetesFleetManager-Resource-Complete-Test.hcl
@@ -13,9 +13,7 @@ resource "azurerm_kubernetes_fleet_manager" "test" {
     some_key    = "some-value"
   }
   hub_profile {
-    dns_prefix         = "val-${var.random_string}"
-    fqdn               = "val-${var.random_string}"
-    kubernetes_version = "val-${var.random_string}"
+    dns_prefix = "val-${var.random_string}"
   }
 }

diff --git a/api-definitions/resource-manager/DevCenter/2023-04-01/DevCenters/Model-DevCenterProperties.json b/api-definitions/resource-manager/DevCenter/2023-04-01/DevCenters/Model-DevCenterProperties.json
index a5a1c806a7..012d3b2ec8 100644
--- a/api-definitions/resource-manager/DevCenter/2023-04-01/DevCenters/Model-DevCenterProperties.json
+++ b/api-definitions/resource-manager/DevCenter/2023-04-01/DevCenters/Model-DevCenterProperties.json
@@ -9,8 +9,8 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
-      "readOnly": false,
+      "optional": false,
+      "readOnly": true,
       "required": false,
       "sensitive": false
     },
diff --git a/api-definitions/resource-manager/DevCenter/2023-04-01/Projects/Model-ProjectProperties.json b/api-definitions/resource-manager/DevCenter/2023-04-01/Projects/Model-ProjectProperties.json
index 9201af9f76..972a9788e9 100644
--- a/api-definitions/resource-manager/DevCenter/2023-04-01/Projects/Model-ProjectProperties.json
+++ b/api-definitions/resource-manager/DevCenter/2023-04-01/Projects/Model-ProjectProperties.json
@@ -35,8 +35,8 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
-      "readOnly": false,
+      "optional": false,
+      "readOnly": true,
       "required": false,
       "sensitive": false
     },
diff --git a/api-definitions/resource-manager/DevCenter/Terraform/DevCenter-Resource-Schema.json b/api-definitions/resource-manager/DevCenter/Terraform/DevCenter-Resource-Schema.json
index 00e04463b3..e2ae5a9de6 100644
--- a/api-definitions/resource-manager/DevCenter/Terraform/DevCenter-Resource-Schema.json
+++ b/api-definitions/resource-manager/DevCenter/Terraform/DevCenter-Resource-Schema.json
@@ -1,11 +1,11 @@
 {
   "fields": [
     {
+      "computed": true,
       "documentation": {
         "markdown": "The URI of the Dev Center."
       },
       "hclName": "dev_center_uri",
-      "optional": true,
       "name": "DevCenterUri",
       "objectDefinition": {
         "referenceName": null,
diff --git a/api-definitions/resource-manager/DevCenter/Terraform/DevCenterProject-Resource-Schema.json b/api-definitions/resource-manager/DevCenter/Terraform/DevCenterProject-Resource-Schema.json
index c2ee5f35db..ca7d82e341 100644
--- a/api-definitions/resource-manager/DevCenter/Terraform/DevCenterProject-Resource-Schema.json
+++ b/api-definitions/resource-manager/DevCenter/Terraform/DevCenterProject-Resource-Schema.json
@@ -27,12 +27,11 @@
       "required": true
     },
     {
+      "computed": true,
       "documentation": {
         "markdown": "The URI of the Dev Center resource this project is associated with."
       },
-      "forceNew": true,
       "hclName": "dev_center_uri",
-      "optional": true,
       "name": "DevCenterUri",
       "objectDefinition": {
         "referenceName": null,
diff --git a/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenter-Resource-Complete-Test.hcl b/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenter-Resource-Complete-Test.hcl
index 8eb361e65d..b1205abf2f 100644
--- a/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenter-Resource-Complete-Test.hcl
+++ b/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenter-Resource-Complete-Test.hcl
@@ -8,7 +8,6 @@ resource "azurerm_dev_center" "test" {
   location            = azurerm_resource_group.test.location
   name                = "acctestdc-${var.random_string}"
   resource_group_name = azurerm_resource_group.test.name
-  dev_center_uri      = "val-${var.random_string}"
   tags = {
     environment = "terraform-acctests"
     some_key    = "some-value"
diff --git a/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenterProject-Resource-Complete-Test.hcl b/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenterProject-Resource-Complete-Test.hcl
index 3b6fef9a68..c2372e9580 100644
--- a/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenterProject-Resource-Complete-Test.hcl
+++ b/api-definitions/resource-manager/DevCenter/Terraform/Tests/DevCenterProject-Resource-Complete-Test.hcl
@@ -10,7 +10,6 @@ resource "azurerm_dev_center_project" "test" {
   name                       = "acctestdcp-${var.random_string}"
   resource_group_name        = azurerm_resource_group.test.name
   description                = "Description for the Dev Center Project"
-  dev_center_uri             = "val-${var.random_string}"
   maximum_dev_boxes_per_user = 21
   tags = {
     environment = "terraform-acctests"
diff --git a/api-definitions/resource-manager/LoadTestService/2022-12-01/LoadTests/Model-LoadTestProperties.json b/api-definitions/resource-manager/LoadTestService/2022-12-01/LoadTests/Model-LoadTestProperties.json
index b7a9ddb81d..c40414b7d9 100644
--- a/api-definitions/resource-manager/LoadTestService/2022-12-01/LoadTests/Model-LoadTestProperties.json
+++ b/api-definitions/resource-manager/LoadTestService/2022-12-01/LoadTests/Model-LoadTestProperties.json
@@ -9,8 +9,8 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
-      "readOnly": false,
+      "optional": false,
+      "readOnly": true,
       "required": false,
       "sensitive": false
     },
diff --git a/api-definitions/resource-manager/LoadTestService/Terraform/LoadTest-Resource-Schema.json b/api-definitions/resource-manager/LoadTestService/Terraform/LoadTest-Resource-Schema.json
index e3d3ad27c8..60db33a2b0 100644
--- a/api-definitions/resource-manager/LoadTestService/Terraform/LoadTest-Resource-Schema.json
+++ b/api-definitions/resource-manager/LoadTestService/Terraform/LoadTest-Resource-Schema.json
@@ -1,12 +1,11 @@
 {
   "fields": [
     {
+      "computed": true,
       "documentation": {
         "markdown": "Resource data plane URI."
       },
-      "forceNew": true,
       "hclName": "data_plane_uri",
-      "optional": true,
       "name": "DataPlaneURI",
       "objectDefinition": {
         "referenceName": null,
diff --git a/api-definitions/resource-manager/LoadTestService/Terraform/Tests/LoadTest-Resource-Complete-Test.hcl b/api-definitions/resource-manager/LoadTestService/Terraform/Tests/LoadTest-Resource-Complete-Test.hcl
index 77e665f99f..5fa6e22782 100644
--- a/api-definitions/resource-manager/LoadTestService/Terraform/Tests/LoadTest-Resource-Complete-Test.hcl
+++ b/api-definitions/resource-manager/LoadTestService/Terraform/Tests/LoadTest-Resource-Complete-Test.hcl
@@ -8,7 +8,6 @@ resource "azurerm_load_test" "test" {
   location            = azurerm_resource_group.test.location
   name                = "acctestlt-${var.random_string}"
   resource_group_name = azurerm_resource_group.test.name
-  data_plane_uri      = "val-${var.random_string}"
   description         = "Description for the Load Test"
   tags = {
     environment = "terraform-acctests"
diff --git a/api-definitions/resource-manager/ManagedIdentity/2023-01-31/ManagedIdentities/Model-UserAssignedIdentityProperties.json b/api-definitions/resource-manager/ManagedIdentity/2023-01-31/ManagedIdentities/Model-UserAssignedIdentityProperties.json
index 1e0332ff21..4808de720e 100644
--- a/api-definitions/resource-manager/ManagedIdentity/2023-01-31/ManagedIdentities/Model-UserAssignedIdentityProperties.json
+++ b/api-definitions/resource-manager/ManagedIdentity/2023-01-31/ManagedIdentities/Model-UserAssignedIdentityProperties.json
@@ -9,7 +9,7 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
+      "optional": false,
       "readOnly": true,
       "required": false,
       "sensitive": false
@@ -22,7 +22,7 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
+      "optional": false,
       "readOnly": true,
       "required": false,
       "sensitive": false
@@ -35,7 +35,7 @@
         "type": "String",
         "referenceName": null
       },
-      "optional": true,
+      "optional": false,
       "readOnly": true,
       "required": false,
       "sensitive": false

@tombuildsstuff tombuildsstuff added bug Something isn't working tool/importer-rest-api-specs Swagger Data Importer issues labels Feb 28, 2024
@tombuildsstuff tombuildsstuff requested a review from a team February 28, 2024 09:16
@tombuildsstuff tombuildsstuff merged commit 56db595 into main Feb 28, 2024
2 checks passed
@tombuildsstuff tombuildsstuff deleted the b/forcing-readonly-for-existing-resources branch February 28, 2024 10:06
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working tool/importer-rest-api-specs Swagger Data Importer issues
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants