From f6824ebdae16def4538009c28adc3f3ef1bcca0b Mon Sep 17 00:00:00 2001 From: Cameron Thornton Date: Fri, 27 Sep 2024 14:58:18 -0500 Subject: [PATCH 1/2] Convert from Ruby to Go fix unit test expecting hardcoded values fix ordering scratch disks in the state Remove hardcoded values that are handled by the API --- .../compute/resource_compute_instance_template.go.tmpl | 7 ------- ...ompute_region_instance_template_internal_test.go.tmpl | 9 +++++---- 2 files changed, 5 insertions(+), 11 deletions(-) diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl index 85df5950a4b8..88c1a5359ba1 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template.go.tmpl @@ -1207,9 +1207,6 @@ func buildDisks(d *schema.ResourceData, config *transport_tpg.Config) ([]*comput // Build the disk var disk compute.AttachedDisk - disk.Type = "PERSISTENT" - disk.Mode = "READ_WRITE" - disk.Interface = "SCSI" disk.Boot = i == 0 disk.AutoDelete = d.Get(prefix + ".auto_delete").(bool) @@ -1620,10 +1617,6 @@ func reorderDisks(configDisks []interface{}, apiDisks []map[string]interface{}) disksByDeviceName[v.(string)] = i } else if v := disk["type"]; v.(string) == "SCRATCH" { iface := disk["interface"].(string) - if iface == "" { - // apply-time default - iface = "SCSI" - } scratchDisksByInterface[iface] = append(scratchDisksByInterface[iface], i) } else if v := disk["source"]; v.(string) != "" { attachedDisksBySource[v.(string)] = i diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_internal_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_internal_test.go.tmpl index a643e4719836..bb235b036588 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_internal_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_region_instance_template_internal_test.go.tmpl @@ -22,8 +22,9 @@ func TestComputeRegionInstanceTemplate_reorderDisks(t *testing.T) { cDeviceName := map[string]interface{}{ "device_name": "disk-1", } - cScratch := map[string]interface{}{ + cScratchScsi := map[string]interface{}{ "type": "SCRATCH", + "interface": "SCSI", } cSource := map[string]interface{}{ "source": "disk-source", @@ -81,7 +82,7 @@ func TestComputeRegionInstanceTemplate_reorderDisks(t *testing.T) { aBoot, aScratchNvme, aSource, aScratchScsi, aFallThrough, aDeviceName, }, ConfigDisks: []interface{}{ - cBoot, cFallThrough, cDeviceName, cScratch, cSource, cScratchNvme, + cBoot, cFallThrough, cDeviceName, cScratchScsi, cSource, cScratchNvme, }, ExpectedResult: []map[string]interface{}{ aBoot, aFallThrough, aDeviceName, aScratchScsi, aSource, aScratchNvme, @@ -92,7 +93,7 @@ func TestComputeRegionInstanceTemplate_reorderDisks(t *testing.T) { aBoot, aNoMatch, aScratchNvme, aScratchScsi, aFallThrough, aDeviceName, }, ConfigDisks: []interface{}{ - cBoot, cFallThrough, cDeviceName, cScratch, cSource, cScratchNvme, + cBoot, cFallThrough, cDeviceName, cScratchScsi, cSource, cScratchNvme, }, ExpectedResult: []map[string]interface{}{ aBoot, aFallThrough, aDeviceName, aScratchScsi, aScratchNvme, aNoMatch, @@ -103,7 +104,7 @@ func TestComputeRegionInstanceTemplate_reorderDisks(t *testing.T) { aBoot, aScratchNvme, aFallThrough, aSource, aScratchScsi, aFallThrough2, aDeviceName, }, ConfigDisks: []interface{}{ - cBoot, cFallThrough, cDeviceName, cScratch, cFallThrough, cSource, cScratchNvme, + cBoot, cFallThrough, cDeviceName, cScratchScsi, cFallThrough, cSource, cScratchNvme, }, ExpectedResult: []map[string]interface{}{ aBoot, aFallThrough, aDeviceName, aScratchScsi, aFallThrough2, aSource, aScratchNvme, From f47d0c169cc806915ee8e9f6e7c004ff8d82b5f4 Mon Sep 17 00:00:00 2001 From: Karol Gorczyk Date: Wed, 9 Oct 2024 14:22:45 +0200 Subject: [PATCH 2/2] add global templates, fix file generation --- ...esource_compute_instance_template_internal_test.go | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_internal_test.go b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_internal_test.go index 1ff79ef03e2a..f917b6b601e9 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_internal_test.go +++ b/mmv1/third_party/terraform/services/compute/resource_compute_instance_template_internal_test.go @@ -19,8 +19,9 @@ func TestComputeInstanceTemplate_reorderDisks(t *testing.T) { cDeviceName := map[string]interface{}{ "device_name": "disk-1", } - cScratch := map[string]interface{}{ - "type": "SCRATCH", + cScratchScsi := map[string]interface{}{ + "type": "SCRATCH", + "interface": "SCSI", } cSource := map[string]interface{}{ "source": "disk-source", @@ -78,7 +79,7 @@ func TestComputeInstanceTemplate_reorderDisks(t *testing.T) { aBoot, aScratchNvme, aSource, aScratchScsi, aFallThrough, aDeviceName, }, ConfigDisks: []interface{}{ - cBoot, cFallThrough, cDeviceName, cScratch, cSource, cScratchNvme, + cBoot, cFallThrough, cDeviceName, cScratchScsi, cSource, cScratchNvme, }, ExpectedResult: []map[string]interface{}{ aBoot, aFallThrough, aDeviceName, aScratchScsi, aSource, aScratchNvme, @@ -89,7 +90,7 @@ func TestComputeInstanceTemplate_reorderDisks(t *testing.T) { aBoot, aNoMatch, aScratchNvme, aScratchScsi, aFallThrough, aDeviceName, }, ConfigDisks: []interface{}{ - cBoot, cFallThrough, cDeviceName, cScratch, cSource, cScratchNvme, + cBoot, cFallThrough, cDeviceName, cScratchScsi, cSource, cScratchNvme, }, ExpectedResult: []map[string]interface{}{ aBoot, aFallThrough, aDeviceName, aScratchScsi, aScratchNvme, aNoMatch, @@ -100,7 +101,7 @@ func TestComputeInstanceTemplate_reorderDisks(t *testing.T) { aBoot, aScratchNvme, aFallThrough, aSource, aScratchScsi, aFallThrough2, aDeviceName, }, ConfigDisks: []interface{}{ - cBoot, cFallThrough, cDeviceName, cScratch, cFallThrough, cSource, cScratchNvme, + cBoot, cFallThrough, cDeviceName, cScratchScsi, cFallThrough, cSource, cScratchNvme, }, ExpectedResult: []map[string]interface{}{ aBoot, aFallThrough, aDeviceName, aScratchScsi, aFallThrough2, aSource, aScratchNvme,