Skip to content

Add existing_reservations to google_compute_region_commitment #8256

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .changelog/11790.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
```release-note:enhancement
compute: added 'existing_reservations' field to 'google_compute_region_commitment' resource
```
Original file line number Diff line number Diff line change
Expand Up @@ -98,6 +98,13 @@ Note that only MACHINE commitments should have a Type specified. Possible values
ForceNew: true,
Description: `An optional description of this resource.`,
},
"existing_reservations": {
Type: schema.TypeString,
Computed: true,
Optional: true,
ForceNew: true,
Description: `Specifies the already existing reservations to attach to the Commitment.`,
},
"license_resource": {
Type: schema.TypeList,
Optional: true,
Expand Down Expand Up @@ -281,6 +288,12 @@ func resourceComputeRegionCommitmentCreate(d *schema.ResourceData, meta interfac
} else if v, ok := d.GetOkExists("auto_renew"); !tpgresource.IsEmptyValue(reflect.ValueOf(autoRenewProp)) && (ok || !reflect.DeepEqual(v, autoRenewProp)) {
obj["autoRenew"] = autoRenewProp
}
existingReservationsProp, err := expandComputeRegionCommitmentExistingReservations(d.Get("existing_reservations"), d, config)
if err != nil {
return err
} else if v, ok := d.GetOkExists("existing_reservations"); !tpgresource.IsEmptyValue(reflect.ValueOf(existingReservationsProp)) && (ok || !reflect.DeepEqual(v, existingReservationsProp)) {
obj["existingReservations"] = existingReservationsProp
}
regionProp, err := expandComputeRegionCommitmentRegion(d.Get("region"), d, config)
if err != nil {
return err
Expand Down Expand Up @@ -428,6 +441,9 @@ func resourceComputeRegionCommitmentRead(d *schema.ResourceData, meta interface{
if err := d.Set("auto_renew", flattenComputeRegionCommitmentAutoRenew(res["autoRenew"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionCommitment: %s", err)
}
if err := d.Set("existing_reservations", flattenComputeRegionCommitmentExistingReservations(res["existingReservations"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionCommitment: %s", err)
}
if err := d.Set("region", flattenComputeRegionCommitmentRegion(res["region"], d, config)); err != nil {
return fmt.Errorf("Error reading RegionCommitment: %s", err)
}
Expand Down Expand Up @@ -590,6 +606,10 @@ func flattenComputeRegionCommitmentAutoRenew(v interface{}, d *schema.ResourceDa
return v
}

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

func flattenComputeRegionCommitmentRegion(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
if v == nil {
return v
Expand Down Expand Up @@ -714,6 +734,10 @@ func expandComputeRegionCommitmentAutoRenew(v interface{}, d tpgresource.Terrafo
return v, nil
}

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

func expandComputeRegionCommitmentRegion(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
f, err := tpgresource.ParseGlobalFieldValue("regions", v.(string), "project", d, config, true)
if err != nil {
Expand Down
4 changes: 4 additions & 0 deletions website/docs/r/compute_region_commitment.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,10 @@ The following arguments are supported:
If the field is set to true, the commitment will be automatically renewed for either
one or three years according to the terms of the existing commitment.

* `existing_reservations` -
(Optional)
Specifies the already existing reservations to attach to the Commitment.

* `region` -
(Optional)
URL of the region where this commitment may be used.
Expand Down