Repository: GoogleCloudPlatform/terraform-validator
Pull request #1483 (2023-03-22 23:28:29)

fix(tfv): Fix missing zone in compute instance
<!-- Put a description of what this PR is for here, along with any references to issues that this resolves or contributes to -->
For compute instance resource, the zone field is not converted. 



<!--
Replace each [ ] with [X] to check it. Switch to the preview view to make it easier to click on links.
These steps will speed up the review process, and we appreciate you spending time on them before sending
your code to be reviewed.
-->
If this PR is for Terraform, I acknowledge that I have:

- [X] Searched through the [issue tracker](https://github.com/hashicorp/terraform-provider-google/issues) for an open issue that this either resolves or contributes to, commented on it to claim it, and written "fixes {url}" or "part of {url}" in this PR description. If there were no relevant open issues, I opened one and commented that I would like to work on it (not necessary for very small changes).
- [ ] Ensured that all new fields I added that can be set by a user appear in at least one [example](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/templates/terraform/examples) (for generated resources) or [third_party test](https://github.com/GoogleCloudPlatform/magic-modules/tree/main/mmv1/third_party/terraform/tests) (for handwritten resources or update tests).
- [ ] [Generated Terraform providers](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/docs/content/docs/getting-started/generate-providers.md), and ran [`make test` and `make lint`](https://googlecloudplatform.github.io/magic-modules/docs/getting-started/run-provider-tests/#run-unit-tests) in the generated providers to ensure it passes unit and linter tests.
- [ ] [Ran](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/docs/content/docs/getting-started/run-provider-tests.md) relevant acceptance tests using my own Google Cloud project and credentials (If the acceptance tests do not yet pass or you are unable to run them, please let your reviewer know).
- [X] Read the [Release Notes Guide](https://github.com/GoogleCloudPlatform/magic-modules/blob/main/.ci/RELEASE_NOTES_GUIDE.md) before writing my release note below.

<!-- AUTOCHANGELOG for Downstream PRs.

Please select one of the following "release-note:" headings:
    - release-note:enhancement
    - release-note:bug
    - release-note:note
    - release-note:new-resource
    - release-note:new-datasource
    - release-note:deprecation
    - release-note:breaking-change
    - release-note:none

Unless you choose release-note:none, please add a release note.

See .ci/RELEASE_NOTES_GUIDE.md for writing good release notes.

You can add more release note blocks if you want more than one CHANGELOG
entry for this PR.
-->
**Release Note Template for Downstream PRs (will be copied)**

```release-note:none

```

Derived from https://github.com/GoogleCloudPlatform/magic-modules/pull/7466


Patch:
diff --git a/converters/google/resources/compute_instance.go b/converters/google/resources/compute_instance.go
index a2348749..f07e1756 100644
--- a/converters/google/resources/compute_instance.go
+++ b/converters/google/resources/compute_instance.go
@@ -148,6 +148,7 @@ func expandComputeInstance(project string, d TerraformResourceData, config *Conf
 		MachineType:            machineTypeUrl,
 		Metadata:               metadata,
 		Name:                   d.Get("name").(string),
+		Zone:                   d.Get("zone").(string),
 		NetworkInterfaces:      networkInterfaces,
 		Tags:                   resourceInstanceTags(d),
 		Labels:                 expandLabels(d),


Test patch:
diff --git a/testdata/templates/example_compute_instance.json b/testdata/templates/example_compute_instance.json
index 0f07c68c..14faf1ac 100644
--- a/testdata/templates/example_compute_instance.json
+++ b/testdata/templates/example_compute_instance.json
@@ -65,7 +65,8 @@
             "bar",
             "foo"
           ]
-        }
+        },
+        "zone": "us-central1-a"
       }
     }
   },
diff --git a/testdata/templates/example_compute_instance_iam_binding.json b/testdata/templates/example_compute_instance_iam_binding.json
index 10804711..9d20c2b3 100644
--- a/testdata/templates/example_compute_instance_iam_binding.json
+++ b/testdata/templates/example_compute_instance_iam_binding.json
@@ -57,7 +57,8 @@
             "bar",
             "foo"
           ]
-        }
+        },
+        "zone": "us-central1-a"
       }
     },
     "iam_policy": {
diff --git a/testdata/templates/example_compute_instance_iam_member.json b/testdata/templates/example_compute_instance_iam_member.json
index 40cbd296..ece286c7 100644
--- a/testdata/templates/example_compute_instance_iam_member.json
+++ b/testdata/templates/example_compute_instance_iam_member.json
@@ -57,7 +57,8 @@
             "bar",
             "foo"
           ]
-        }
+        },
+        "zone": "us-central1-a"
       }
     },
     "iam_policy": {
diff --git a/testdata/templates/example_compute_instance_iam_policy.json b/testdata/templates/example_compute_instance_iam_policy.json
index 4b009a2f..2c9c9e21 100644
--- a/testdata/templates/example_compute_instance_iam_policy.json
+++ b/testdata/templates/example_compute_instance_iam_policy.json
@@ -57,7 +57,8 @@
             "bar",
             "foo"
           ]
-        }
+        },
+        "zone": "us-central1-a"
       }
     },
     "iam_policy": {
diff --git a/testdata/templates/full_compute_instance.json b/testdata/templates/full_compute_instance.json
index d14102b0..689812cb 100644
--- a/testdata/templates/full_compute_instance.json
+++ b/testdata/templates/full_compute_instance.json
@@ -135,7 +135,8 @@
             "bar",
             "foo"
           ]
-        }
+        },
+        "zone": "us-central1-a"
       }
     }
   },
@@ -157,7 +158,7 @@
             "boot": true,
             "diskEncryptionKey": {
               "kmsKeyName": "test-kms_key_self_link"
-      	    },
+            },
             "mode": "READ_WRITE"
           }
         ],
@@ -172,7 +173,8 @@
         "scheduling": {
           "automaticRestart": true
         },
-        "tags": {}
+        "tags": {},
+        "zone": "us-central1-a"
       }
     }
   }
diff --git a/testdata/templates/instance.json b/testdata/templates/instance.json
index a5f3f22c..516d64d8 100644
--- a/testdata/templates/instance.json
+++ b/testdata/templates/instance.json
@@ -65,7 +65,8 @@
             "bar",
             "foo"
           ]
-        }
+        },
+        "zone": "us-central1-a"
       }
     }
   }