Skip to content

Commit 0d42c42

Browse files
Feature gap: Add missed fields for Reservation resource (#14181) (#23561)
[upstream:5fe392557c4bb3ac8ca45a38df86b9d8d4828734] Signed-off-by: Modular Magician <[email protected]>
1 parent 388617f commit 0d42c42

File tree

6 files changed

+692
-4
lines changed

6 files changed

+692
-4
lines changed

.changelog/14181.txt

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
```release-note:enhancement
2+
compute: added `specific_reservation.0.instance_properties.0.maintenance_interval`, `share_settings.0.projects` and `enable_emergent_maintenance` fields to `google_compute_reservation` resource (beta)
3+
```
4+
5+
```release-note:enhancement
6+
compute: added `specific_reservation.0.source_instance_template`, `delete_at_time`, `delete_after_duration.0.seconds`, `delete_after_duration.0.nanos` and `reservation_sharing_policy.0.service_share_type` fields to `google_compute_reservation` resource (ga)
7+
```

google/services/compute/resource_compute_reservation.go

Lines changed: 205 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ character, which cannot be a dash.`,
8787
},
8888
"instance_properties": {
8989
Type: schema.TypeList,
90-
Required: true,
90+
Computed: true,
91+
Optional: true,
9192
ForceNew: true,
9293
Description: `The instance properties for the reservation.`,
9394
MaxItems: 1,
@@ -163,6 +164,14 @@ for information on available CPU platforms.`,
163164
},
164165
},
165166
},
167+
ExactlyOneOf: []string{"specific_reservation.0.instance_properties", "specific_reservation.0.source_instance_template"},
168+
},
169+
"source_instance_template": {
170+
Type: schema.TypeString,
171+
Optional: true,
172+
Description: `Specifies the instance template to create the reservation. If you use this field, you must exclude the
173+
instanceProperties field.`,
174+
ExactlyOneOf: []string{"specific_reservation.0.instance_properties", "specific_reservation.0.source_instance_template"},
166175
},
167176
"in_use_count": {
168177
Type: schema.TypeInt,
@@ -179,12 +188,64 @@ for information on available CPU platforms.`,
179188
DiffSuppressFunc: tpgresource.CompareSelfLinkOrResourceName,
180189
Description: `The zone where the reservation is made.`,
181190
},
191+
"delete_after_duration": {
192+
Type: schema.TypeList,
193+
Optional: true,
194+
Description: `Duration after which the reservation will be auto-deleted by Compute Engine. Cannot be used with delete_at_time.`,
195+
MaxItems: 1,
196+
Elem: &schema.Resource{
197+
Schema: map[string]*schema.Schema{
198+
"nanos": {
199+
Type: schema.TypeInt,
200+
Optional: true,
201+
ForceNew: true,
202+
Description: `Number of nanoseconds for the auto-delete duration.`,
203+
ConflictsWith: []string{"delete_at_time"},
204+
},
205+
"seconds": {
206+
Type: schema.TypeString,
207+
Optional: true,
208+
ForceNew: true,
209+
Description: `Number of seconds for the auto-delete duration.`,
210+
ConflictsWith: []string{"delete_at_time"},
211+
},
212+
},
213+
},
214+
},
215+
"delete_at_time": {
216+
Type: schema.TypeString,
217+
Computed: true,
218+
Optional: true,
219+
ForceNew: true,
220+
Description: `Absolute time in future when the reservation will be auto-deleted by Compute Engine. Timestamp is represented in RFC3339 text format.
221+
Cannot be used with delete_after_duration.`,
222+
ConflictsWith: []string{"delete_after_duration.0.seconds", "delete_after_duration.0.nanos"},
223+
},
182224
"description": {
183225
Type: schema.TypeString,
184226
Optional: true,
185227
ForceNew: true,
186228
Description: `An optional description of this resource.`,
187229
},
230+
"reservation_sharing_policy": {
231+
Type: schema.TypeList,
232+
Computed: true,
233+
Optional: true,
234+
Description: `Sharing policy for reservations with Google Cloud managed services.`,
235+
MaxItems: 1,
236+
Elem: &schema.Resource{
237+
Schema: map[string]*schema.Schema{
238+
"service_share_type": {
239+
Type: schema.TypeString,
240+
Computed: true,
241+
Optional: true,
242+
ForceNew: true,
243+
ValidateFunc: verify.ValidateEnum([]string{"ALLOW_ALL", "DISALLOW_ALL", ""}),
244+
Description: `Sharing config for all Google Cloud services. Possible values: ["ALLOW_ALL", "DISALLOW_ALL"]`,
245+
},
246+
},
247+
},
248+
},
188249
"share_settings": {
189250
Type: schema.TypeList,
190251
Computed: true,
@@ -300,6 +361,24 @@ func resourceComputeReservationCreate(d *schema.ResourceData, meta interface{})
300361
} else if v, ok := d.GetOkExists("specific_reservation"); !tpgresource.IsEmptyValue(reflect.ValueOf(specificReservationProp)) && (ok || !reflect.DeepEqual(v, specificReservationProp)) {
301362
obj["specificReservation"] = specificReservationProp
302363
}
364+
deleteAtTimeProp, err := expandComputeReservationDeleteAtTime(d.Get("delete_at_time"), d, config)
365+
if err != nil {
366+
return err
367+
} else if v, ok := d.GetOkExists("delete_at_time"); !tpgresource.IsEmptyValue(reflect.ValueOf(deleteAtTimeProp)) && (ok || !reflect.DeepEqual(v, deleteAtTimeProp)) {
368+
obj["deleteAtTime"] = deleteAtTimeProp
369+
}
370+
deleteAfterDurationProp, err := expandComputeReservationDeleteAfterDuration(d.Get("delete_after_duration"), d, config)
371+
if err != nil {
372+
return err
373+
} else if v, ok := d.GetOkExists("delete_after_duration"); !tpgresource.IsEmptyValue(reflect.ValueOf(deleteAfterDurationProp)) && (ok || !reflect.DeepEqual(v, deleteAfterDurationProp)) {
374+
obj["deleteAfterDuration"] = deleteAfterDurationProp
375+
}
376+
reservationSharingPolicyProp, err := expandComputeReservationReservationSharingPolicy(d.Get("reservation_sharing_policy"), d, config)
377+
if err != nil {
378+
return err
379+
} else if v, ok := d.GetOkExists("reservation_sharing_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(reservationSharingPolicyProp)) && (ok || !reflect.DeepEqual(v, reservationSharingPolicyProp)) {
380+
obj["reservationSharingPolicy"] = reservationSharingPolicyProp
381+
}
303382
zoneProp, err := expandComputeReservationZone(d.Get("zone"), d, config)
304383
if err != nil {
305384
return err
@@ -426,6 +505,12 @@ func resourceComputeReservationRead(d *schema.ResourceData, meta interface{}) er
426505
if err := d.Set("specific_reservation", flattenComputeReservationSpecificReservation(res["specificReservation"], d, config)); err != nil {
427506
return fmt.Errorf("Error reading Reservation: %s", err)
428507
}
508+
if err := d.Set("delete_at_time", flattenComputeReservationDeleteAtTime(res["deleteAtTime"], d, config)); err != nil {
509+
return fmt.Errorf("Error reading Reservation: %s", err)
510+
}
511+
if err := d.Set("reservation_sharing_policy", flattenComputeReservationReservationSharingPolicy(res["reservationSharingPolicy"], d, config)); err != nil {
512+
return fmt.Errorf("Error reading Reservation: %s", err)
513+
}
429514
if err := d.Set("zone", flattenComputeReservationZone(res["zone"], d, config)); err != nil {
430515
return fmt.Errorf("Error reading Reservation: %s", err)
431516
}
@@ -458,6 +543,18 @@ func resourceComputeReservationUpdate(d *schema.ResourceData, meta interface{})
458543
} else if v, ok := d.GetOkExists("share_settings"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, shareSettingsProp)) {
459544
obj["shareSettings"] = shareSettingsProp
460545
}
546+
deleteAfterDurationProp, err := expandComputeReservationDeleteAfterDuration(d.Get("delete_after_duration"), d, config)
547+
if err != nil {
548+
return err
549+
} else if v, ok := d.GetOkExists("delete_after_duration"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, deleteAfterDurationProp)) {
550+
obj["deleteAfterDuration"] = deleteAfterDurationProp
551+
}
552+
reservationSharingPolicyProp, err := expandComputeReservationReservationSharingPolicy(d.Get("reservation_sharing_policy"), d, config)
553+
if err != nil {
554+
return err
555+
} else if v, ok := d.GetOkExists("reservation_sharing_policy"); !tpgresource.IsEmptyValue(reflect.ValueOf(v)) && (ok || !reflect.DeepEqual(v, reservationSharingPolicyProp)) {
556+
obj["reservationSharingPolicy"] = reservationSharingPolicyProp
557+
}
461558

462559
obj, err = resourceComputeReservationUpdateEncoder(d, meta, obj)
463560
if err != nil {
@@ -476,6 +573,14 @@ func resourceComputeReservationUpdate(d *schema.ResourceData, meta interface{})
476573
if d.HasChange("share_settings") {
477574
updateMask = append(updateMask, "shareSettings")
478575
}
576+
577+
if d.HasChange("delete_after_duration") {
578+
updateMask = append(updateMask, "deleteAfterDuration")
579+
}
580+
581+
if d.HasChange("reservation_sharing_policy") {
582+
updateMask = append(updateMask, "reservationSharingPolicy")
583+
}
479584
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
480585
// won't set it
481586
url, err = transport_tpg.AddQueryParams(url, map[string]string{"updateMask": strings.Join(updateMask, ",")})
@@ -711,6 +816,8 @@ func flattenComputeReservationSpecificReservation(v interface{}, d *schema.Resou
711816
flattenComputeReservationSpecificReservationInUseCount(original["inUseCount"], d, config)
712817
transformed["instance_properties"] =
713818
flattenComputeReservationSpecificReservationInstanceProperties(original["instanceProperties"], d, config)
819+
transformed["source_instance_template"] =
820+
flattenComputeReservationSpecificReservationSourceInstanceTemplate(original["sourceInstanceTemplate"], d, config)
714821
return []interface{}{transformed}
715822
}
716823
func flattenComputeReservationSpecificReservationCount(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
@@ -854,6 +961,31 @@ func flattenComputeReservationSpecificReservationInstancePropertiesLocalSsdsDisk
854961
return v // let terraform core handle it otherwise
855962
}
856963

964+
func flattenComputeReservationSpecificReservationSourceInstanceTemplate(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
965+
return v
966+
}
967+
968+
func flattenComputeReservationDeleteAtTime(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
969+
return v
970+
}
971+
972+
func flattenComputeReservationReservationSharingPolicy(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
973+
if v == nil {
974+
return nil
975+
}
976+
original := v.(map[string]interface{})
977+
if len(original) == 0 {
978+
return nil
979+
}
980+
transformed := make(map[string]interface{})
981+
transformed["service_share_type"] =
982+
flattenComputeReservationReservationSharingPolicyServiceShareType(original["serviceShareType"], d, config)
983+
return []interface{}{transformed}
984+
}
985+
func flattenComputeReservationReservationSharingPolicyServiceShareType(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
986+
return v
987+
}
988+
857989
func flattenComputeReservationZone(v interface{}, d *schema.ResourceData, config *transport_tpg.Config) interface{} {
858990
if v == nil {
859991
return v
@@ -962,6 +1094,13 @@ func expandComputeReservationSpecificReservation(v interface{}, d tpgresource.Te
9621094
transformed["instanceProperties"] = transformedInstanceProperties
9631095
}
9641096

1097+
transformedSourceInstanceTemplate, err := expandComputeReservationSpecificReservationSourceInstanceTemplate(original["source_instance_template"], d, config)
1098+
if err != nil {
1099+
return nil, err
1100+
} else if val := reflect.ValueOf(transformedSourceInstanceTemplate); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1101+
transformed["sourceInstanceTemplate"] = transformedSourceInstanceTemplate
1102+
}
1103+
9651104
return transformed, nil
9661105
}
9671106

@@ -1095,6 +1234,71 @@ func expandComputeReservationSpecificReservationInstancePropertiesLocalSsdsDiskS
10951234
return v, nil
10961235
}
10971236

1237+
func expandComputeReservationSpecificReservationSourceInstanceTemplate(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1238+
return v, nil
1239+
}
1240+
1241+
func expandComputeReservationDeleteAtTime(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1242+
return v, nil
1243+
}
1244+
1245+
func expandComputeReservationDeleteAfterDuration(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1246+
l := v.([]interface{})
1247+
if len(l) == 0 || l[0] == nil {
1248+
return nil, nil
1249+
}
1250+
raw := l[0]
1251+
original := raw.(map[string]interface{})
1252+
transformed := make(map[string]interface{})
1253+
1254+
transformedSeconds, err := expandComputeReservationDeleteAfterDurationSeconds(original["seconds"], d, config)
1255+
if err != nil {
1256+
return nil, err
1257+
} else if val := reflect.ValueOf(transformedSeconds); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1258+
transformed["seconds"] = transformedSeconds
1259+
}
1260+
1261+
transformedNanos, err := expandComputeReservationDeleteAfterDurationNanos(original["nanos"], d, config)
1262+
if err != nil {
1263+
return nil, err
1264+
} else if val := reflect.ValueOf(transformedNanos); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1265+
transformed["nanos"] = transformedNanos
1266+
}
1267+
1268+
return transformed, nil
1269+
}
1270+
1271+
func expandComputeReservationDeleteAfterDurationSeconds(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1272+
return v, nil
1273+
}
1274+
1275+
func expandComputeReservationDeleteAfterDurationNanos(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1276+
return v, nil
1277+
}
1278+
1279+
func expandComputeReservationReservationSharingPolicy(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1280+
l := v.([]interface{})
1281+
if len(l) == 0 || l[0] == nil {
1282+
return nil, nil
1283+
}
1284+
raw := l[0]
1285+
original := raw.(map[string]interface{})
1286+
transformed := make(map[string]interface{})
1287+
1288+
transformedServiceShareType, err := expandComputeReservationReservationSharingPolicyServiceShareType(original["service_share_type"], d, config)
1289+
if err != nil {
1290+
return nil, err
1291+
} else if val := reflect.ValueOf(transformedServiceShareType); val.IsValid() && !tpgresource.IsEmptyValue(val) {
1292+
transformed["serviceShareType"] = transformedServiceShareType
1293+
}
1294+
1295+
return transformed, nil
1296+
}
1297+
1298+
func expandComputeReservationReservationSharingPolicyServiceShareType(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
1299+
return v, nil
1300+
}
1301+
10981302
func expandComputeReservationZone(v interface{}, d tpgresource.TerraformResourceData, config *transport_tpg.Config) (interface{}, error) {
10991303
f, err := tpgresource.ParseGlobalFieldValue("zones", v.(string), "project", d, config, true)
11001304
if err != nil {

google/services/compute/resource_compute_reservation_generated_meta.yaml

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,12 @@ api_resource_type_kind: 'Allocation'
77
fields:
88
- field: 'commitment'
99
- field: 'creation_timestamp'
10+
- field: 'delete_after_duration.nanos'
11+
- field: 'delete_after_duration.seconds'
12+
- field: 'delete_at_time'
1013
- field: 'description'
1114
- field: 'name'
15+
- field: 'reservation_sharing_policy.service_share_type'
1216
- field: 'share_settings.project_map.project_config.project_id'
1317
- field: 'share_settings.share_type'
1418
- field: 'specific_reservation.count'
@@ -19,6 +23,7 @@ fields:
1923
- field: 'specific_reservation.instance_properties.local_ssds.interface'
2024
- field: 'specific_reservation.instance_properties.machine_type'
2125
- field: 'specific_reservation.instance_properties.min_cpu_platform'
26+
- field: 'specific_reservation.source_instance_template'
2227
- field: 'specific_reservation_required'
2328
- field: 'status'
2429
- field: 'zone'

0 commit comments

Comments
 (0)