Skip to content

Commit b352bdb

Browse files
coder-221anoopkverma-google
authored andcommitted
Add etags to acm_service_perimeter_resource (GoogleCloudPlatform#12736)
1 parent a22201d commit b352bdb

File tree

4 files changed

+40
-4
lines changed

4 files changed

+40
-4
lines changed

mmv1/products/accesscontextmanager/ServicePerimeterResource.yaml

+7
Original file line numberDiff line numberDiff line change
@@ -70,6 +70,8 @@ custom_code:
7070
encoder: 'templates/terraform/encoders/access_context_manager_service_perimeter_resource.go.tmpl'
7171
custom_import: 'templates/terraform/custom_import/access_context_manager_service_perimeter_resource.go.tmpl'
7272
post_read: 'templates/terraform/post_read/access_context_manager_service_perimeter_resource.go.tmpl'
73+
pre_create: 'templates/terraform/pre_create/access_context_manager_service_perimeter_resource.go.tmpl'
74+
pre_delete: 'templates/terraform/pre_delete/access_context_manager_service_perimeter_resource.go.tmpl'
7375
exclude_tgc: true
7476
# Skipping the sweeper due to the non-standard base_url and because this is fine-grained under ServicePerimeter
7577
exclude_sweeper: true
@@ -104,3 +106,8 @@ properties:
104106
The name of the Access Policy this resource belongs to.
105107
ignore_read: true
106108
output: true
109+
- name: 'etag'
110+
type: String
111+
output: true
112+
description: |
113+
The perimeter etag is internally used to prevent overwriting the list of perimeter resources on PATCH calls. It is retrieved from the same GET perimeter API call that's used to get the current list of resources. The resource to add or remove is merged into that list and then this etag is sent with the PATCH call along with the updated resource list.
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
// post_read template for access_context_manager_service_perimeter_resource
2-
3-
// this is a placeholder for now but in the future we can use this to access
4-
// the etag from the read response
1+
if err := d.Set("etag", res["etag"]); err != nil {
2+
log.Printf("[ERROR] Unable to set etag: %s", err)
3+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
etag := d.Get("etag").(string)
2+
3+
if etag == "" {
4+
log.Printf("[ERROR] Unable to get etag: %s", err)
5+
return nil
6+
}
7+
obj["etag"] = etag
8+
9+
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
10+
// won't set it
11+
updateMask := []string{"status.resources", "etag"}
12+
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
13+
if err != nil {
14+
return err
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
etag := d.Get("etag").(string)
2+
3+
if etag == "" {
4+
log.Printf("[ERROR] Unable to get etag: %s", err)
5+
return nil
6+
}
7+
obj["etag"] = etag
8+
9+
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
10+
// won't set it
11+
updateMask := []string{"status.resources", "etag"}
12+
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
13+
if err != nil {
14+
return err
15+
}

0 commit comments

Comments
 (0)