@@ -87,7 +87,8 @@ character, which cannot be a dash.`,
87
87
},
88
88
"instance_properties" : {
89
89
Type : schema .TypeList ,
90
- Required : true ,
90
+ Computed : true ,
91
+ Optional : true ,
91
92
ForceNew : true ,
92
93
Description : `The instance properties for the reservation.` ,
93
94
MaxItems : 1 ,
@@ -163,6 +164,14 @@ for information on available CPU platforms.`,
163
164
},
164
165
},
165
166
},
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" },
166
175
},
167
176
"in_use_count" : {
168
177
Type : schema .TypeInt ,
@@ -179,12 +188,64 @@ for information on available CPU platforms.`,
179
188
DiffSuppressFunc : tpgresource .CompareSelfLinkOrResourceName ,
180
189
Description : `The zone where the reservation is made.` ,
181
190
},
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
+ },
182
224
"description" : {
183
225
Type : schema .TypeString ,
184
226
Optional : true ,
185
227
ForceNew : true ,
186
228
Description : `An optional description of this resource.` ,
187
229
},
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
+ },
188
249
"share_settings" : {
189
250
Type : schema .TypeList ,
190
251
Computed : true ,
@@ -300,6 +361,24 @@ func resourceComputeReservationCreate(d *schema.ResourceData, meta interface{})
300
361
} else if v , ok := d .GetOkExists ("specific_reservation" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (specificReservationProp )) && (ok || ! reflect .DeepEqual (v , specificReservationProp )) {
301
362
obj ["specificReservation" ] = specificReservationProp
302
363
}
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
+ }
303
382
zoneProp , err := expandComputeReservationZone (d .Get ("zone" ), d , config )
304
383
if err != nil {
305
384
return err
@@ -426,6 +505,12 @@ func resourceComputeReservationRead(d *schema.ResourceData, meta interface{}) er
426
505
if err := d .Set ("specific_reservation" , flattenComputeReservationSpecificReservation (res ["specificReservation" ], d , config )); err != nil {
427
506
return fmt .Errorf ("Error reading Reservation: %s" , err )
428
507
}
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
+ }
429
514
if err := d .Set ("zone" , flattenComputeReservationZone (res ["zone" ], d , config )); err != nil {
430
515
return fmt .Errorf ("Error reading Reservation: %s" , err )
431
516
}
@@ -458,6 +543,18 @@ func resourceComputeReservationUpdate(d *schema.ResourceData, meta interface{})
458
543
} else if v , ok := d .GetOkExists ("share_settings" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (v )) && (ok || ! reflect .DeepEqual (v , shareSettingsProp )) {
459
544
obj ["shareSettings" ] = shareSettingsProp
460
545
}
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
+ }
461
558
462
559
obj , err = resourceComputeReservationUpdateEncoder (d , meta , obj )
463
560
if err != nil {
@@ -476,6 +573,14 @@ func resourceComputeReservationUpdate(d *schema.ResourceData, meta interface{})
476
573
if d .HasChange ("share_settings" ) {
477
574
updateMask = append (updateMask , "shareSettings" )
478
575
}
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
+ }
479
584
// updateMask is a URL parameter but not present in the schema, so ReplaceVars
480
585
// won't set it
481
586
url , err = transport_tpg .AddQueryParams (url , map [string ]string {"updateMask" : strings .Join (updateMask , "," )})
@@ -711,6 +816,8 @@ func flattenComputeReservationSpecificReservation(v interface{}, d *schema.Resou
711
816
flattenComputeReservationSpecificReservationInUseCount (original ["inUseCount" ], d , config )
712
817
transformed ["instance_properties" ] =
713
818
flattenComputeReservationSpecificReservationInstanceProperties (original ["instanceProperties" ], d , config )
819
+ transformed ["source_instance_template" ] =
820
+ flattenComputeReservationSpecificReservationSourceInstanceTemplate (original ["sourceInstanceTemplate" ], d , config )
714
821
return []interface {}{transformed }
715
822
}
716
823
func flattenComputeReservationSpecificReservationCount (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
@@ -854,6 +961,31 @@ func flattenComputeReservationSpecificReservationInstancePropertiesLocalSsdsDisk
854
961
return v // let terraform core handle it otherwise
855
962
}
856
963
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
+
857
989
func flattenComputeReservationZone (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
858
990
if v == nil {
859
991
return v
@@ -962,6 +1094,13 @@ func expandComputeReservationSpecificReservation(v interface{}, d tpgresource.Te
962
1094
transformed ["instanceProperties" ] = transformedInstanceProperties
963
1095
}
964
1096
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
+
965
1104
return transformed , nil
966
1105
}
967
1106
@@ -1095,6 +1234,71 @@ func expandComputeReservationSpecificReservationInstancePropertiesLocalSsdsDiskS
1095
1234
return v , nil
1096
1235
}
1097
1236
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
+
1098
1302
func expandComputeReservationZone (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1099
1303
f , err := tpgresource .ParseGlobalFieldValue ("zones" , v .(string ), "project" , d , config , true )
1100
1304
if err != nil {
0 commit comments