From bea7309499004523e404db0f1c5c8a19978e98b9 Mon Sep 17 00:00:00 2001 From: Adam Skubis Date: Fri, 18 Oct 2024 16:52:53 +0000 Subject: [PATCH 1/4] Fix issue with google_compute_(region_)per_instance_config.stateful.ips.ipAddress.address always having diff due to relative vs full path --- mmv1/products/compute/PerInstanceConfig.yaml | 4 +++- mmv1/products/compute/RegionPerInstanceConfig.yaml | 4 +++- 2 files changed, 6 insertions(+), 2 deletions(-) diff --git a/mmv1/products/compute/PerInstanceConfig.yaml b/mmv1/products/compute/PerInstanceConfig.yaml index a4aed0002834..da152858a32d 100644 --- a/mmv1/products/compute/PerInstanceConfig.yaml +++ b/mmv1/products/compute/PerInstanceConfig.yaml @@ -15,7 +15,7 @@ name: 'PerInstanceConfig' description: | A config defined for a single managed instance that belongs to an instance group manager. It preserves the instance name - across instance group manager operations and can define stateful disks or metadata that are unique to the instance. + across instance group manager operations and can define stateful disks, ips or metadata that are unique to the instance. references: guides: 'Official Documentation': 'https://cloud.google.com/compute/docs/instance-groups/stateful-migs#per-instance_configs' @@ -213,6 +213,7 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. + custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' @@ -243,6 +244,7 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. + custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' diff --git a/mmv1/products/compute/RegionPerInstanceConfig.yaml b/mmv1/products/compute/RegionPerInstanceConfig.yaml index 9d0a6340a5ab..6017c6994b64 100644 --- a/mmv1/products/compute/RegionPerInstanceConfig.yaml +++ b/mmv1/products/compute/RegionPerInstanceConfig.yaml @@ -15,7 +15,7 @@ name: 'RegionPerInstanceConfig' description: | A config defined for a single managed instance that belongs to an instance group manager. It preserves the instance name - across instance group manager operations and can define stateful disks or metadata that are unique to the instance. + across instance group manager operations and can define stateful disks, ips or metadata that are unique to the instance. This resource works with regional instance group managers. references: guides: @@ -214,6 +214,7 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. + custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' @@ -244,6 +245,7 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. + custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' From 7ea3391a7158728ff5ea45d222eff294a235be87 Mon Sep 17 00:00:00 2001 From: Adam Skubis Date: Mon, 21 Oct 2024 16:38:36 +0000 Subject: [PATCH 2/4] fix tests to adhere to recommended way of specifying ip in per_instance_config --- ...resource_compute_per_instance_config_test.go.tmpl | 12 ++++++------ ...e_compute_region_per_instance_config_test.go.tmpl | 12 ++++++------ 2 files changed, 12 insertions(+), 12 deletions(-) diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl index 2943de437d62..603d48e4a9d5 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl @@ -442,14 +442,14 @@ resource "google_compute_per_instance_config" "config_one" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.self_link + address = google_compute_address.static_internal_ip.id } auto_delete = "NEVER" interface_name = "nic0" } external_ip { ip_address { - address = google_compute_address.static_external_ip.self_link + address = google_compute_address.static_external_ip.id } auto_delete = "NEVER" interface_name = "nic0" @@ -545,14 +545,14 @@ resource "google_compute_per_instance_config" "default" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.self_link + address = google_compute_address.static_internal_ip.id } auto_delete = "NEVER" interface_name = "nic0" } external_ip { ip_address { - address = google_compute_address.static_external_ip.self_link + address = google_compute_address.static_external_ip.id } auto_delete = "NEVER" interface_name = "nic0" @@ -620,14 +620,14 @@ resource "google_compute_per_instance_config" "default" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.self_link + address = google_compute_address.static_internal_ip.id } auto_delete = "ON_PERMANENT_INSTANCE_DELETION" interface_name = "nic0" } external_ip { ip_address { - address = google_compute_address.static_external_ip.self_link + address = google_compute_address.static_external_ip.id } auto_delete = "ON_PERMANENT_INSTANCE_DELETION" interface_name = "nic0" diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl index 7de4e9725b1d..ad0d94383565 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl @@ -451,14 +451,14 @@ resource "google_compute_region_per_instance_config" "config_one" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.self_link + address = google_compute_address.static_internal_ip.id } auto_delete = "NEVER" interface_name = "nic0" } external_ip { ip_address { - address = google_compute_address.static_external_ip.self_link + address = google_compute_address.static_external_ip.id } auto_delete = "NEVER" interface_name = "nic0" @@ -555,14 +555,14 @@ resource "google_compute_region_per_instance_config" "default" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.self_link + address = google_compute_address.static_internal_ip.id } auto_delete = "NEVER" interface_name = "nic0" } external_ip { ip_address { - address = google_compute_address.static_external_ip.self_link + address = google_compute_address.static_external_ip.id } auto_delete = "NEVER" interface_name = "nic0" @@ -631,14 +631,14 @@ resource "google_compute_region_per_instance_config" "default" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.self_link + address = google_compute_address.static_internal_ip.id } auto_delete = "ON_PERMANENT_INSTANCE_DELETION" interface_name = "nic0" } external_ip { ip_address { - address = google_compute_address.static_external_ip.self_link + address = google_compute_address.static_external_ip.id } auto_delete = "ON_PERMANENT_INSTANCE_DELETION" interface_name = "nic0" From db1f49d89f39143cf00c7b1658275c57325e5dba Mon Sep 17 00:00:00 2001 From: Adam Skubis Date: Mon, 2 Dec 2024 17:11:35 +0000 Subject: [PATCH 3/4] add unit tests for the diff supress function --- mmv1/products/compute/PerInstanceConfig.yaml | 8 +-- .../compute/RegionPerInstanceConfig.yaml | 8 +-- ...e_compute_per_instance_config_test.go.tmpl | 6 +- ...te_region_per_instance_config_test.go.tmpl | 6 +- .../tpgresource/self_link_helpers_test.go | 63 +++++++++++++++++++ 5 files changed, 77 insertions(+), 14 deletions(-) diff --git a/mmv1/products/compute/PerInstanceConfig.yaml b/mmv1/products/compute/PerInstanceConfig.yaml index da152858a32d..99512701b64f 100644 --- a/mmv1/products/compute/PerInstanceConfig.yaml +++ b/mmv1/products/compute/PerInstanceConfig.yaml @@ -213,8 +213,8 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. - custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' - custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' + #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' - name: 'externalIp' @@ -244,7 +244,7 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. - custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' - custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' + #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' diff --git a/mmv1/products/compute/RegionPerInstanceConfig.yaml b/mmv1/products/compute/RegionPerInstanceConfig.yaml index 6017c6994b64..0c55246005eb 100644 --- a/mmv1/products/compute/RegionPerInstanceConfig.yaml +++ b/mmv1/products/compute/RegionPerInstanceConfig.yaml @@ -214,8 +214,8 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. - custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' - custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' + #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' - name: 'externalIp' @@ -245,7 +245,7 @@ properties: type: ResourceRef description: | The URL of the reservation for this IP address. - custom_flatten: 'templates/terraform/custom_flatten/full_to_relative_path.tmpl' - custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' + #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl index 603d48e4a9d5..bca70329851f 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_per_instance_config_test.go.tmpl @@ -442,7 +442,7 @@ resource "google_compute_per_instance_config" "config_one" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.id + address = google_compute_address.static_internal_ip.self_link } auto_delete = "NEVER" interface_name = "nic0" @@ -552,7 +552,7 @@ resource "google_compute_per_instance_config" "default" { } external_ip { ip_address { - address = google_compute_address.static_external_ip.id + address = google_compute_address.static_external_ip.self_link } auto_delete = "NEVER" interface_name = "nic0" @@ -627,7 +627,7 @@ resource "google_compute_per_instance_config" "default" { } external_ip { ip_address { - address = google_compute_address.static_external_ip.id + address = google_compute_address.static_external_ip.self_link } auto_delete = "ON_PERMANENT_INSTANCE_DELETION" interface_name = "nic0" diff --git a/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl b/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl index ad0d94383565..94d3581b70ef 100644 --- a/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl +++ b/mmv1/third_party/terraform/services/compute/resource_compute_region_per_instance_config_test.go.tmpl @@ -458,7 +458,7 @@ resource "google_compute_region_per_instance_config" "config_one" { } external_ip { ip_address { - address = google_compute_address.static_external_ip.id + address = google_compute_address.static_external_ip.self_link } auto_delete = "NEVER" interface_name = "nic0" @@ -555,7 +555,7 @@ resource "google_compute_region_per_instance_config" "default" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.id + address = google_compute_address.static_internal_ip.self_link } auto_delete = "NEVER" interface_name = "nic0" @@ -631,7 +631,7 @@ resource "google_compute_region_per_instance_config" "default" { } internal_ip { ip_address { - address = google_compute_address.static_internal_ip.id + address = google_compute_address.static_internal_ip.self_link } auto_delete = "ON_PERMANENT_INSTANCE_DELETION" interface_name = "nic0" diff --git a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go index d640202c8b52..b38c9bfba9bb 100644 --- a/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go +++ b/mmv1/third_party/terraform/tpgresource/self_link_helpers_test.go @@ -2,6 +2,69 @@ package tpgresource import "testing" +func TestCompareSelfLinkRelativePaths(t *testing.T) { + cases := map[string]struct { + Old, New string + Expect bool + }{ + "name only, same": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "a-network", + Expect: false, + }, + "name only, different": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "another-network", + Expect: false, + }, + "partial path, same": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "projects/your-project/global/networks/a-network", + Expect: true, + }, + "partial path, different name": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "projects/your-project/global/networks/another-network", + Expect: false, + }, + "partial path, different project": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "projects/another-project/global/networks/a-network", + Expect: false, + }, + "full path, different name": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/another-network", + Expect: false, + }, + "full path, different project": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/v1/projects/another-project/global/networks/a-network", + Expect: false, + }, + "beta full path, same": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/beta/projects/your-project/global/networks/a-network", + Expect: true, + }, + "beta full path, different name": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/beta/projects/your-project/global/networks/another-network", + Expect: false, + }, + "beta full path, different project": { + Old: "https://www.googleapis.com/compute/v1/projects/your-project/global/networks/a-network", + New: "https://www.googleapis.com/compute/beta/projects/another-project/global/networks/a-network", + Expect: false, + }, + } + + for tn, tc := range cases { + if CompareSelfLinkRelativePaths("", tc.Old, tc.New, nil) != tc.Expect { + t.Errorf("bad: %s, expected %t for old = %q and new = %q", tn, tc.Expect, tc.Old, tc.New) + } + } +} func TestCompareSelfLinkOrResourceName(t *testing.T) { cases := map[string]struct { Old, New string From 42110aefe5a8e6b72548db58852bd72fa8e71020 Mon Sep 17 00:00:00 2001 From: Adam Skubis Date: Mon, 2 Dec 2024 17:32:28 +0000 Subject: [PATCH 4/4] uncomment test changes --- mmv1/products/compute/PerInstanceConfig.yaml | 4 ++-- mmv1/products/compute/RegionPerInstanceConfig.yaml | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/mmv1/products/compute/PerInstanceConfig.yaml b/mmv1/products/compute/PerInstanceConfig.yaml index 99512701b64f..3db34ab23581 100644 --- a/mmv1/products/compute/PerInstanceConfig.yaml +++ b/mmv1/products/compute/PerInstanceConfig.yaml @@ -214,7 +214,7 @@ properties: description: | The URL of the reservation for this IP address. diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' - #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' - name: 'externalIp' @@ -245,6 +245,6 @@ properties: description: | The URL of the reservation for this IP address. diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' - #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' diff --git a/mmv1/products/compute/RegionPerInstanceConfig.yaml b/mmv1/products/compute/RegionPerInstanceConfig.yaml index 0c55246005eb..879a906a1a92 100644 --- a/mmv1/products/compute/RegionPerInstanceConfig.yaml +++ b/mmv1/products/compute/RegionPerInstanceConfig.yaml @@ -215,7 +215,7 @@ properties: description: | The URL of the reservation for this IP address. diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' - #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink' - name: 'externalIp' @@ -246,6 +246,6 @@ properties: description: | The URL of the reservation for this IP address. diff_suppress_func: 'tpgresource.CompareSelfLinkRelativePaths' - #custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' + custom_expand: 'templates/terraform/custom_expand/resourceref_with_validation.go.tmpl' resource: 'Address' imports: 'selfLink'