Skip to content

Commit

Permalink
Etag support for ACM service perimeters (#12363) (#20455)
Browse files Browse the repository at this point in the history
[upstream:161220adfef1dbc0001daaad10c29a87d71ee39e]

Signed-off-by: Modular Magician <magic-modules@google.com>
  • Loading branch information
modular-magician authored Nov 22, 2024
1 parent 157fda6 commit 708b4c7
Show file tree
Hide file tree
Showing 6 changed files with 77 additions and 0 deletions.
3 changes: 3 additions & 0 deletions .changelog/12363.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
accesscontextmanager: added `etag` to `google_access_context_manager_service_perimeter` and `google_access_context_manager_service_perimeters`
```
Original file line number Diff line number Diff line change
Expand Up @@ -909,6 +909,13 @@ bet set to True if any of the fields in the spec are set to non-default values.`
Computed: true,
Description: `Time the AccessPolicy was created in UTC.`,
},
"etag": {
Type: schema.TypeString,
Computed: true,
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.`,
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -963,6 +970,12 @@ func resourceAccessContextManagerServicePerimeterCreate(d *schema.ResourceData,
} else if v, ok := d.GetOkExists("use_explicit_dry_run_spec"); !tpgresource.IsEmptyValue(reflect.ValueOf(useExplicitDryRunSpecProp)) && (ok || !reflect.DeepEqual(v, useExplicitDryRunSpecProp)) {
obj["useExplicitDryRunSpec"] = useExplicitDryRunSpecProp
}
etagProp, err := expandAccessContextManagerServicePerimeterEtag(d.Get("etag"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("etag"); !tpgresource.IsEmptyValue(reflect.ValueOf(etagProp)) && (ok || !reflect.DeepEqual(v, etagProp)) {
obj["etag"] = etagProp
}
parentProp, err := expandAccessContextManagerServicePerimeterParent(d.Get("parent"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -1108,6 +1121,9 @@ func resourceAccessContextManagerServicePerimeterRead(d *schema.ResourceData, me
if err := d.Set("use_explicit_dry_run_spec", flattenAccessContextManagerServicePerimeterUseExplicitDryRunSpec(res["useExplicitDryRunSpec"], d, config)); err != nil {
return fmt.Errorf("Error reading ServicePerimeter: %s", err)
}
if err := d.Set("etag", flattenAccessContextManagerServicePerimeterEtag(res["etag"], d, config)); err != nil {
return fmt.Errorf("Error reading ServicePerimeter: %s", err)
}
if err := d.Set("name", flattenAccessContextManagerServicePerimeterName(res["name"], d, config)); err != nil {
return fmt.Errorf("Error reading ServicePerimeter: %s", err)
}
Expand Down Expand Up @@ -1155,6 +1171,12 @@ func resourceAccessContextManagerServicePerimeterUpdate(d *schema.ResourceData,
} else if v, ok := d.GetOkExists("use_explicit_dry_run_spec"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, useExplicitDryRunSpecProp)) {
obj["useExplicitDryRunSpec"] = useExplicitDryRunSpecProp
}
etagProp, err := expandAccessContextManagerServicePerimeterEtag(d.Get("etag"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("etag"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, etagProp)) {
obj["etag"] = etagProp
}

obj, err = resourceAccessContextManagerServicePerimeterEncoder(d, meta, obj)
if err != nil {
Expand Down Expand Up @@ -1196,12 +1218,21 @@ func resourceAccessContextManagerServicePerimeterUpdate(d *schema.ResourceData,
if d.HasChange("use_explicit_dry_run_spec") {
updateMask = append(updateMask, "useExplicitDryRunSpec")
}

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

url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
}

// err == nil indicates that the billing_project value was found
if bp, err := tpgresource.GetBillingProject(d, config); err == nil {
Expand Down Expand Up @@ -2085,6 +2116,10 @@ func flattenAccessContextManagerServicePerimeterUseExplicitDryRunSpec(v interfac
return v
}

func flattenAccessContextManagerServicePerimeterEtag(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}

func flattenAccessContextManagerServicePerimeterName(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
return v
}
Expand Down Expand Up @@ -3173,6 +3208,10 @@ func expandAccessContextManagerServicePerimeterUseExplicitDryRunSpec(v interface
return v, nil
}

func expandAccessContextManagerServicePerimeterEtag(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandAccessContextManagerServicePerimeterParent(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,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",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -715,6 +715,13 @@ bet set to True if any of the fields in the spec are set to non-default values.`
Computed: true,
Description: `Time the AccessPolicy was created in UTC.`,
},
"etag": {
Type: schema.TypeString,
Computed: true,
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.`,
},
"update_time": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -1116,6 +1123,7 @@ func flattenAccessContextManagerServicePerimetersServicePerimeters(v interface{}
"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),
})
}
Expand All @@ -1136,6 +1144,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
}
Expand Down Expand Up @@ -1939,6 +1951,13 @@ func expandAccessContextManagerServicePerimetersServicePerimeters(v interface{},
transformed["description"] = transformedDescription
}

transformedEtag, err := expandAccessContextManagerServicePerimetersServicePerimetersEtag(original["etag"], d, config)
if err != nil {
return nil, err
} else if val := reflect.ValueOf(transformedEtag); val.IsValid() && !tpgresource.IsEmptyValue(val) {
transformed["etag"] = transformedEtag
}

transformedCreateTime, err := expandAccessContextManagerServicePerimetersServicePerimetersCreateTime(original["create_time"], d, config)
if err != nil {
return nil, err
Expand Down Expand Up @@ -1998,6 +2017,10 @@ func expandAccessContextManagerServicePerimetersServicePerimetersDescription(v i
return v, nil
}

func expandAccessContextManagerServicePerimetersServicePerimetersEtag(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}

func expandAccessContextManagerServicePerimetersServicePerimetersCreateTime(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
return v, nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -860,6 +860,11 @@ In addition to the arguments listed above, the following computed attributes are
* `update_time` -
Time the AccessPolicy was updated in UTC.

* `etag` -
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.


## Timeouts

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -119,6 +119,12 @@ The following arguments are supported:
Description of the ServicePerimeter and its use. Does not affect
behavior.

* `etag` -
(Output)
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.

* `create_time` -
(Output)
Time the AccessPolicy was created in UTC.
Expand Down

0 comments on commit 708b4c7

Please sign in to comment.