From 161220adfef1dbc0001daaad10c29a87d71ee39e Mon Sep 17 00:00:00 2001 From: coder-221 <185867912+coder-221@users.noreply.github.com> Date: Fri, 22 Nov 2024 10:55:37 -0800 Subject: [PATCH] Etag support for ACM service perimeters (#12363) --- mmv1/products/accesscontextmanager/ServicePerimeter.yaml | 8 ++++++++ mmv1/products/accesscontextmanager/ServicePerimeters.yaml | 7 +++++++ ...ontextmanager_serviceperimeters_custom_flatten.go.tmpl | 5 +++++ .../access_context_manager_service_perimeter.go.tmpl | 5 +++++ ..._access_context_manager_service_perimeter_test.go.tmpl | 1 + 5 files changed, 26 insertions(+) create mode 100644 mmv1/templates/terraform/pre_update/access_context_manager_service_perimeter.go.tmpl diff --git a/mmv1/products/accesscontextmanager/ServicePerimeter.yaml b/mmv1/products/accesscontextmanager/ServicePerimeter.yaml index 8ca2e4ae5f81..16ac87ff6828 100644 --- a/mmv1/products/accesscontextmanager/ServicePerimeter.yaml +++ b/mmv1/products/accesscontextmanager/ServicePerimeter.yaml @@ -71,6 +71,7 @@ async: custom_code: constants: 'templates/terraform/constants/access_context_manager.go.tmpl' encoder: 'templates/terraform/encoders/access_level_never_send_parent.go.tmpl' + pre_update: 'templates/terraform/pre_update/access_context_manager_service_perimeter.go.tmpl' custom_import: 'templates/terraform/custom_import/set_access_policy_parent_from_self_link.go.tmpl' # Skipping the sweeper due to the non-standard base_url exclude_sweeper: true @@ -788,3 +789,10 @@ properties: actually enforcing them. This testing is done through analyzing the differences between currently enforced and suggested restrictions. useExplicitDryRunSpec must bet set to True if any of the fields in the spec are set to non-default values. + - name: 'etag' + type: Fingerprint + description: | + An opaque identifier for the current version of the ServicePerimeter. This + identifier does not follow any specific format. If an etag is not provided, the + operation will be performed as if a valid etag is provided. + output: true diff --git a/mmv1/products/accesscontextmanager/ServicePerimeters.yaml b/mmv1/products/accesscontextmanager/ServicePerimeters.yaml index 0d0c4e97a441..4cad388dfb64 100644 --- a/mmv1/products/accesscontextmanager/ServicePerimeters.yaml +++ b/mmv1/products/accesscontextmanager/ServicePerimeters.yaml @@ -100,6 +100,13 @@ properties: description: | Description of the ServicePerimeter and its use. Does not affect behavior. + - name: 'etag' + type: Fingerprint + description: | + An opaque identifier for the current version of the ServicePerimeter. This + identifier does not follow any specific format. If an etag is not provided, the + operation will be performed as if a valid etag is provided. + output: true - name: 'createTime' type: Time description: | diff --git a/mmv1/templates/terraform/custom_flatten/accesscontextmanager_serviceperimeters_custom_flatten.go.tmpl b/mmv1/templates/terraform/custom_flatten/accesscontextmanager_serviceperimeters_custom_flatten.go.tmpl index 231fc3f35c04..c6db1de5f7e7 100644 --- a/mmv1/templates/terraform/custom_flatten/accesscontextmanager_serviceperimeters_custom_flatten.go.tmpl +++ b/mmv1/templates/terraform/custom_flatten/accesscontextmanager_serviceperimeters_custom_flatten.go.tmpl @@ -18,6 +18,7 @@ func flatten{{$.GetPrefix}}{{$.TitlelizeProperty}}(v interface{}, d *schema.Reso "perimeter_type": flattenAccessContextManagerServicePerimetersServicePerimetersPerimeterType(original["perimeterType"], d, config), "status": flattenAccessContextManagerServicePerimetersServicePerimetersStatus(original["status"], d, config), "spec": flattenAccessContextManagerServicePerimetersServicePerimetersSpec(original["spec"], d, config), + "etag": flattenAccessContextManagerServicePerimetersServicePerimetersEtag(original["etag"], d, config), "use_explicit_dry_run_spec": flattenAccessContextManagerServicePerimetersServicePerimetersUseExplicitDryRunSpec(original["useExplicitDryRunSpec"], d, config), }) } @@ -38,6 +39,10 @@ func flattenAccessContextManagerServicePerimetersServicePerimetersName(v interfa return v } +func flattenAccessContextManagerServicePerimetersServicePerimetersEtag(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { + return v +} + func flattenAccessContextManagerServicePerimetersServicePerimetersTitle(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} { return v } diff --git a/mmv1/templates/terraform/pre_update/access_context_manager_service_perimeter.go.tmpl b/mmv1/templates/terraform/pre_update/access_context_manager_service_perimeter.go.tmpl new file mode 100644 index 000000000000..f1204301fd06 --- /dev/null +++ b/mmv1/templates/terraform/pre_update/access_context_manager_service_perimeter.go.tmpl @@ -0,0 +1,5 @@ +if _, ok := d.GetOkExists("etag"); ok { + updateMask = append(updateMask, "etag") + + url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")}) +} diff --git a/mmv1/third_party/terraform/services/accesscontextmanager/resource_access_context_manager_service_perimeter_test.go.tmpl b/mmv1/third_party/terraform/services/accesscontextmanager/resource_access_context_manager_service_perimeter_test.go.tmpl index 38271404e07d..9c340713664a 100644 --- a/mmv1/third_party/terraform/services/accesscontextmanager/resource_access_context_manager_service_perimeter_test.go.tmpl +++ b/mmv1/third_party/terraform/services/accesscontextmanager/resource_access_context_manager_service_perimeter_test.go.tmpl @@ -26,6 +26,7 @@ func testAccAccessContextManagerServicePerimeter_basicTest(t *testing.T) { Steps: []resource.TestStep{ { Config: testAccAccessContextManagerServicePerimeter_basic(org, "my policy", "level", "perimeter"), + Check: resource.TestCheckResourceAttrSet("google_access_context_manager_service_perimeter.test-access", "etag"), }, { ResourceName: "google_access_context_manager_service_perimeter.test-access",