@@ -29,6 +29,7 @@ import (
29
29
30
30
"github.com/hashicorp/terraform-provider-google/google/tpgresource"
31
31
transport_tpg "github.com/hashicorp/terraform-provider-google/google/transport"
32
+ "github.com/hashicorp/terraform-provider-google/google/verify"
32
33
)
33
34
34
35
func ResourceColabRuntimeTemplate () * schema.Resource {
@@ -258,6 +259,69 @@ Please refer to the field 'effective_labels' for all of the labels present on th
258
259
},
259
260
},
260
261
},
262
+ "software_config" : {
263
+ Type : schema .TypeList ,
264
+ Optional : true ,
265
+ ForceNew : true ,
266
+ Description : `The notebook software configuration of the notebook runtime.` ,
267
+ MaxItems : 1 ,
268
+ Elem : & schema.Resource {
269
+ Schema : map [string ]* schema.Schema {
270
+ "env" : {
271
+ Type : schema .TypeList ,
272
+ Optional : true ,
273
+ ForceNew : true ,
274
+ Description : `Environment variables to be passed to the container.` ,
275
+ Elem : & schema.Resource {
276
+ Schema : map [string ]* schema.Schema {
277
+ "name" : {
278
+ Type : schema .TypeString ,
279
+ Optional : true ,
280
+ ForceNew : true ,
281
+ Description : `Name of the environment variable. Must be a valid C identifier.` ,
282
+ },
283
+ "value" : {
284
+ Type : schema .TypeString ,
285
+ Optional : true ,
286
+ ForceNew : true ,
287
+ Description : `Variables that reference a $(VAR_NAME) are expanded using the previous defined environment variables in the container and any service environment variables. If a variable cannot be resolved, the reference in the input string will be unchanged. The $(VAR_NAME) syntax can be escaped with a double $$, ie: $$(VAR_NAME). Escaped references will never be expanded, regardless of whether the variable exists or not.` ,
288
+ },
289
+ },
290
+ },
291
+ },
292
+ "post_startup_script_config" : {
293
+ Type : schema .TypeList ,
294
+ Optional : true ,
295
+ ForceNew : true ,
296
+ Description : `Post startup script config.` ,
297
+ MaxItems : 1 ,
298
+ Elem : & schema.Resource {
299
+ Schema : map [string ]* schema.Schema {
300
+ "post_startup_script" : {
301
+ Type : schema .TypeString ,
302
+ Optional : true ,
303
+ ForceNew : true ,
304
+ Description : `Post startup script to run after runtime is started.` ,
305
+ },
306
+ "post_startup_script_behavior" : {
307
+ Type : schema .TypeString ,
308
+ Optional : true ,
309
+ ForceNew : true ,
310
+ ValidateFunc : verify .ValidateEnum ([]string {"RUN_ONCE" , "RUN_EVERY_START" , "DOWNLOAD_AND_RUN_EVERY_START" , "" }),
311
+ Description : `Post startup script behavior that defines download and execution behavior. Possible values: ["RUN_ONCE", "RUN_EVERY_START", "DOWNLOAD_AND_RUN_EVERY_START"]` ,
312
+ },
313
+ "post_startup_script_url" : {
314
+ Type : schema .TypeString ,
315
+ Optional : true ,
316
+ ForceNew : true ,
317
+ Description : `Post startup script url to download. Example: https://bucket/script.sh.` ,
318
+ },
319
+ },
320
+ },
321
+ },
322
+ },
323
+ },
324
+ },
261
325
"effective_labels" : {
262
326
Type : schema .TypeMap ,
263
327
Computed : true ,
@@ -357,6 +421,12 @@ func resourceColabRuntimeTemplateCreate(d *schema.ResourceData, meta interface{}
357
421
} else if v , ok := d .GetOkExists ("encryption_spec" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (encryptionSpecProp )) && (ok || ! reflect .DeepEqual (v , encryptionSpecProp )) {
358
422
obj ["encryptionSpec" ] = encryptionSpecProp
359
423
}
424
+ softwareConfigProp , err := expandColabRuntimeTemplateSoftwareConfig (d .Get ("software_config" ), d , config )
425
+ if err != nil {
426
+ return err
427
+ } else if v , ok := d .GetOkExists ("software_config" ); ! tpgresource .IsEmptyValue (reflect .ValueOf (softwareConfigProp )) && (ok || ! reflect .DeepEqual (v , softwareConfigProp )) {
428
+ obj ["softwareConfig" ] = softwareConfigProp
429
+ }
360
430
labelsProp , err := expandColabRuntimeTemplateEffectiveLabels (d .Get ("effective_labels" ), d , config )
361
431
if err != nil {
362
432
return err
@@ -509,6 +579,9 @@ func resourceColabRuntimeTemplateRead(d *schema.ResourceData, meta interface{})
509
579
if err := d .Set ("encryption_spec" , flattenColabRuntimeTemplateEncryptionSpec (res ["encryptionSpec" ], d , config )); err != nil {
510
580
return fmt .Errorf ("Error reading RuntimeTemplate: %s" , err )
511
581
}
582
+ if err := d .Set ("software_config" , flattenColabRuntimeTemplateSoftwareConfig (res ["softwareConfig" ], d , config )); err != nil {
583
+ return fmt .Errorf ("Error reading RuntimeTemplate: %s" , err )
584
+ }
512
585
if err := d .Set ("terraform_labels" , flattenColabRuntimeTemplateTerraformLabels (res ["labels" ], d , config )); err != nil {
513
586
return fmt .Errorf ("Error reading RuntimeTemplate: %s" , err )
514
587
}
@@ -796,6 +869,77 @@ func flattenColabRuntimeTemplateEncryptionSpecKmsKeyName(v interface{}, d *schem
796
869
return v
797
870
}
798
871
872
+ func flattenColabRuntimeTemplateSoftwareConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
873
+ if v == nil {
874
+ return nil
875
+ }
876
+ original := v .(map [string ]interface {})
877
+ if len (original ) == 0 {
878
+ return nil
879
+ }
880
+ transformed := make (map [string ]interface {})
881
+ transformed ["env" ] =
882
+ flattenColabRuntimeTemplateSoftwareConfigEnv (original ["env" ], d , config )
883
+ transformed ["post_startup_script_config" ] =
884
+ flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfig (original ["postStartupScriptConfig" ], d , config )
885
+ return []interface {}{transformed }
886
+ }
887
+ func flattenColabRuntimeTemplateSoftwareConfigEnv (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
888
+ if v == nil {
889
+ return v
890
+ }
891
+ l := v .([]interface {})
892
+ transformed := make ([]interface {}, 0 , len (l ))
893
+ for _ , raw := range l {
894
+ original := raw .(map [string ]interface {})
895
+ if len (original ) < 1 {
896
+ // Do not include empty json objects coming back from the api
897
+ continue
898
+ }
899
+ transformed = append (transformed , map [string ]interface {}{
900
+ "name" : flattenColabRuntimeTemplateSoftwareConfigEnvName (original ["name" ], d , config ),
901
+ "value" : flattenColabRuntimeTemplateSoftwareConfigEnvValue (original ["value" ], d , config ),
902
+ })
903
+ }
904
+ return transformed
905
+ }
906
+ func flattenColabRuntimeTemplateSoftwareConfigEnvName (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
907
+ return v
908
+ }
909
+
910
+ func flattenColabRuntimeTemplateSoftwareConfigEnvValue (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
911
+ return v
912
+ }
913
+
914
+ func flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfig (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
915
+ if v == nil {
916
+ return nil
917
+ }
918
+ original := v .(map [string ]interface {})
919
+ if len (original ) == 0 {
920
+ return nil
921
+ }
922
+ transformed := make (map [string ]interface {})
923
+ transformed ["post_startup_script" ] =
924
+ flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScript (original ["postStartupScript" ], d , config )
925
+ transformed ["post_startup_script_url" ] =
926
+ flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptUrl (original ["postStartupScriptUrl" ], d , config )
927
+ transformed ["post_startup_script_behavior" ] =
928
+ flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptBehavior (original ["postStartupScriptBehavior" ], d , config )
929
+ return []interface {}{transformed }
930
+ }
931
+ func flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScript (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
932
+ return v
933
+ }
934
+
935
+ func flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptUrl (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
936
+ return v
937
+ }
938
+
939
+ func flattenColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptBehavior (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
940
+ return v
941
+ }
942
+
799
943
func flattenColabRuntimeTemplateTerraformLabels (v interface {}, d * schema.ResourceData , config * transport_tpg.Config ) interface {} {
800
944
if v == nil {
801
945
return v
@@ -1047,6 +1191,114 @@ func expandColabRuntimeTemplateEncryptionSpecKmsKeyName(v interface{}, d tpgreso
1047
1191
return v , nil
1048
1192
}
1049
1193
1194
+ func expandColabRuntimeTemplateSoftwareConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1195
+ l := v .([]interface {})
1196
+ if len (l ) == 0 || l [0 ] == nil {
1197
+ return nil , nil
1198
+ }
1199
+ raw := l [0 ]
1200
+ original := raw .(map [string ]interface {})
1201
+ transformed := make (map [string ]interface {})
1202
+
1203
+ transformedEnv , err := expandColabRuntimeTemplateSoftwareConfigEnv (original ["env" ], d , config )
1204
+ if err != nil {
1205
+ return nil , err
1206
+ } else if val := reflect .ValueOf (transformedEnv ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1207
+ transformed ["env" ] = transformedEnv
1208
+ }
1209
+
1210
+ transformedPostStartupScriptConfig , err := expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfig (original ["post_startup_script_config" ], d , config )
1211
+ if err != nil {
1212
+ return nil , err
1213
+ } else if val := reflect .ValueOf (transformedPostStartupScriptConfig ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1214
+ transformed ["postStartupScriptConfig" ] = transformedPostStartupScriptConfig
1215
+ }
1216
+
1217
+ return transformed , nil
1218
+ }
1219
+
1220
+ func expandColabRuntimeTemplateSoftwareConfigEnv (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1221
+ l := v .([]interface {})
1222
+ req := make ([]interface {}, 0 , len (l ))
1223
+ for _ , raw := range l {
1224
+ if raw == nil {
1225
+ continue
1226
+ }
1227
+ original := raw .(map [string ]interface {})
1228
+ transformed := make (map [string ]interface {})
1229
+
1230
+ transformedName , err := expandColabRuntimeTemplateSoftwareConfigEnvName (original ["name" ], d , config )
1231
+ if err != nil {
1232
+ return nil , err
1233
+ } else if val := reflect .ValueOf (transformedName ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1234
+ transformed ["name" ] = transformedName
1235
+ }
1236
+
1237
+ transformedValue , err := expandColabRuntimeTemplateSoftwareConfigEnvValue (original ["value" ], d , config )
1238
+ if err != nil {
1239
+ return nil , err
1240
+ } else if val := reflect .ValueOf (transformedValue ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1241
+ transformed ["value" ] = transformedValue
1242
+ }
1243
+
1244
+ req = append (req , transformed )
1245
+ }
1246
+ return req , nil
1247
+ }
1248
+
1249
+ func expandColabRuntimeTemplateSoftwareConfigEnvName (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1250
+ return v , nil
1251
+ }
1252
+
1253
+ func expandColabRuntimeTemplateSoftwareConfigEnvValue (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1254
+ return v , nil
1255
+ }
1256
+
1257
+ func expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfig (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1258
+ l := v .([]interface {})
1259
+ if len (l ) == 0 || l [0 ] == nil {
1260
+ return nil , nil
1261
+ }
1262
+ raw := l [0 ]
1263
+ original := raw .(map [string ]interface {})
1264
+ transformed := make (map [string ]interface {})
1265
+
1266
+ transformedPostStartupScript , err := expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScript (original ["post_startup_script" ], d , config )
1267
+ if err != nil {
1268
+ return nil , err
1269
+ } else if val := reflect .ValueOf (transformedPostStartupScript ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1270
+ transformed ["postStartupScript" ] = transformedPostStartupScript
1271
+ }
1272
+
1273
+ transformedPostStartupScriptUrl , err := expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptUrl (original ["post_startup_script_url" ], d , config )
1274
+ if err != nil {
1275
+ return nil , err
1276
+ } else if val := reflect .ValueOf (transformedPostStartupScriptUrl ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1277
+ transformed ["postStartupScriptUrl" ] = transformedPostStartupScriptUrl
1278
+ }
1279
+
1280
+ transformedPostStartupScriptBehavior , err := expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptBehavior (original ["post_startup_script_behavior" ], d , config )
1281
+ if err != nil {
1282
+ return nil , err
1283
+ } else if val := reflect .ValueOf (transformedPostStartupScriptBehavior ); val .IsValid () && ! tpgresource .IsEmptyValue (val ) {
1284
+ transformed ["postStartupScriptBehavior" ] = transformedPostStartupScriptBehavior
1285
+ }
1286
+
1287
+ return transformed , nil
1288
+ }
1289
+
1290
+ func expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScript (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1291
+ return v , nil
1292
+ }
1293
+
1294
+ func expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptUrl (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1295
+ return v , nil
1296
+ }
1297
+
1298
+ func expandColabRuntimeTemplateSoftwareConfigPostStartupScriptConfigPostStartupScriptBehavior (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (interface {}, error ) {
1299
+ return v , nil
1300
+ }
1301
+
1050
1302
func expandColabRuntimeTemplateEffectiveLabels (v interface {}, d tpgresource.TerraformResourceData , config * transport_tpg.Config ) (map [string ]string , error ) {
1051
1303
if v == nil {
1052
1304
return map [string ]string {}, nil
0 commit comments