Skip to content

Commit

Permalink
Add etag to service perimeter dry run resource (#12795)
Browse files Browse the repository at this point in the history
  • Loading branch information
coder-221 authored Jan 22, 2025
1 parent 3342075 commit c11b74b
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -68,9 +68,10 @@ nested_query:
modify_by_patch: true
custom_code:
encoder: 'templates/terraform/encoders/access_context_manager_service_perimeter_dry_run_resource.go.tmpl'
pre_create: 'templates/terraform/pre_create/access_context_manager_dry_run_resource.go.tmpl'
pre_update: 'templates/terraform/pre_create/access_context_manager_dry_run_resource.go.tmpl'
pre_delete: 'templates/terraform/pre_create/access_context_manager_dry_run_resource.go.tmpl'
pre_create: 'templates/terraform/pre_create/access_context_manager_service_perimeter_dry_run_resource.go.tmpl'
pre_update: 'templates/terraform/pre_create/access_context_manager_service_perimeter_dry_run_resource.go.tmpl'
pre_delete: 'templates/terraform/pre_create/access_context_manager_service_perimeter_dry_run_resource.go.tmpl'
post_read: 'templates/terraform/post_read/access_context_manager_service_perimeter_dry_run_resource.go.tmpl'
custom_import: 'templates/terraform/custom_import/access_context_manager_service_perimeter_resource.go.tmpl'
exclude_tgc: true
# Skipping the sweeper due to the non-standard base_url and because this is fine-grained under ServicePerimeter
Expand Down Expand Up @@ -106,3 +107,8 @@ properties:
The name of the Access Policy this resource belongs to.
ignore_read: true
output: true
- name: 'etag'
type: String
output: true
description: |
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 number Diff line number Diff line change
@@ -0,0 +1,3 @@
if err := d.Set("etag", res["etag"]); err != nil {
log.Printf("[ERROR] Unable to set etag: %s", err)
}
Original file line number Diff line number Diff line change
@@ -1 +1,17 @@
obj["use_explicit_dry_run_spec"] = true

etag := d.Get("etag").(string)

if etag == "" {
log.Printf("[ERROR] Unable to get etag: %s", err)
return nil
}
obj["etag"] = etag

// updateMask is a URL parameter but not present in the schema, so ReplaceVars
// won't set it
updateMask := []string{"spec.resources", "etag"}
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
if err != nil {
return err
}

0 comments on commit c11b74b

Please sign in to comment.