@@ -161,6 +161,16 @@ func WorkbenchInstanceTagsDiffSuppress(_, _, _ string, d *schema.ResourceData) b
161
161
return false
162
162
}
163
163
164
+ func WorkbenchInstanceAcceleratorDiffSuppress (_ , _ , _ string , d * schema.ResourceData ) bool {
165
+ old , new := d .GetChange ("gce_setup.0.accelerator_configs" )
166
+ oldInterface := old .([]interface {})
167
+ newInterface := new .([]interface {})
168
+ if len (oldInterface ) == 0 && len (newInterface ) == 1 && newInterface [0 ] == nil {
169
+ return true
170
+ }
171
+ return false
172
+ }
173
+
164
174
// waitForWorkbenchInstanceActive waits for an workbench instance to become "ACTIVE"
165
175
func waitForWorkbenchInstanceActive (d * schema.ResourceData , config * transport_tpg.Config , timeout time.Duration ) error {
166
176
return retry .Retry (timeout , func () * retry.RetryError {
@@ -267,8 +277,9 @@ func ResourceWorkbenchInstance() *schema.Resource {
267
277
Elem : & schema.Resource {
268
278
Schema : map [string ]* schema.Schema {
269
279
"accelerator_configs" : {
270
- Type : schema .TypeList ,
271
- Optional : true ,
280
+ Type : schema .TypeList ,
281
+ Optional : true ,
282
+ DiffSuppressFunc : WorkbenchInstanceAcceleratorDiffSuppress ,
272
283
Description : `The hardware accelerators used on this instance. If you use accelerators, make sure that your configuration has
273
284
[enough vCPUs and memory to support the 'machine_type' you have selected](https://cloud.google.com/compute/docs/gpus/#gpus-list).
274
285
Currently supports only one accelerator configuration.` ,
@@ -992,38 +1003,28 @@ func resourceWorkbenchInstanceUpdate(d *schema.ResourceData, meta interface{}) e
992
1003
if err != nil {
993
1004
return err
994
1005
}
995
- name := d .Get ("name" ).(string )
996
- if d .HasChange ("gce_setup.0.machine_type" ) || d .HasChange ("gce_setup.0.accelerator_configs" ) || d .HasChange ("gce_setup.0.shielded_instance_config" ) {
997
- state := d .Get ("state" ).(string )
998
-
999
- if state != "STOPPED" {
1000
- dRes , err := modifyWorkbenchInstanceState (config , d , project , billingProject , userAgent , "stop" )
1001
- if err != nil {
1002
- return err
1003
- }
1004
-
1005
- if err := waitForWorkbenchOperation (config , d , project , billingProject , userAgent , dRes ); err != nil {
1006
- return fmt .Errorf ("Error stopping Workbench Instance: %s" , err )
1007
- }
1008
-
1009
- } else {
1010
- log .Printf ("[DEBUG] Workbench Instance %q has state %q." , name , state )
1011
- }
1012
-
1013
- } else {
1014
- log .Printf ("[DEBUG] Workbench Instance %q need not be stopped for the update." , name )
1015
- }
1016
-
1017
1006
// Build custom mask since the notebooks API does not support gce_setup as a valid mask
1007
+ stopInstance := false
1018
1008
newUpdateMask := []string {}
1019
1009
if d .HasChange ("gce_setup.0.machine_type" ) {
1020
1010
newUpdateMask = append (newUpdateMask , "gce_setup.machine_type" )
1011
+ stopInstance = true
1021
1012
}
1022
1013
if d .HasChange ("gce_setup.0.accelerator_configs" ) {
1023
1014
newUpdateMask = append (newUpdateMask , "gce_setup.accelerator_configs" )
1015
+ stopInstance = true
1016
+ }
1017
+ if d .HasChange ("gce_setup.0.shielded_instance_config.0.enable_secure_boot" ) {
1018
+ newUpdateMask = append (newUpdateMask , "gce_setup.shielded_instance_config.enable_secure_boot" )
1019
+ stopInstance = true
1024
1020
}
1025
- if d .HasChange ("gce_setup.0.shielded_instance_config" ) {
1026
- newUpdateMask = append (newUpdateMask , "gce_setup.shielded_instance_config" )
1021
+ if d .HasChange ("gce_setup.0.shielded_instance_config.0.enable_vtpm" ) {
1022
+ newUpdateMask = append (newUpdateMask , "gce_setup.shielded_instance_config.enable_vtpm" )
1023
+ stopInstance = true
1024
+ }
1025
+ if d .HasChange ("gce_setup.0.shielded_instance_config.0.enable_integrity_monitoring" ) {
1026
+ newUpdateMask = append (newUpdateMask , "gce_setup.shielded_instance_config.enable_integrity_monitoring" )
1027
+ stopInstance = true
1027
1028
}
1028
1029
if d .HasChange ("gce_setup.0.metadata" ) {
1029
1030
newUpdateMask = append (newUpdateMask , "gceSetup.metadata" )
@@ -1038,6 +1039,28 @@ func resourceWorkbenchInstanceUpdate(d *schema.ResourceData, meta interface{}) e
1038
1039
return err
1039
1040
}
1040
1041
1042
+ name := d .Get ("name" ).(string )
1043
+ if stopInstance {
1044
+ state := d .Get ("state" ).(string )
1045
+
1046
+ if state != "STOPPED" {
1047
+ dRes , err := modifyWorkbenchInstanceState (config , d , project , billingProject , userAgent , "stop" )
1048
+ if err != nil {
1049
+ return err
1050
+ }
1051
+
1052
+ if err := waitForWorkbenchOperation (config , d , project , billingProject , userAgent , dRes ); err != nil {
1053
+ return fmt .Errorf ("Error stopping Workbench Instance: %s" , err )
1054
+ }
1055
+
1056
+ } else {
1057
+ log .Printf ("[DEBUG] Workbench Instance %q has state %q." , name , state )
1058
+ }
1059
+
1060
+ } else {
1061
+ log .Printf ("[DEBUG] Workbench Instance %q need not be stopped for the update." , name )
1062
+ }
1063
+
1041
1064
// err == nil indicates that the billing_project value was found
1042
1065
if bp , err := tpgresource .GetBillingProject (d , config ); err == nil {
1043
1066
billingProject = bp
@@ -1074,7 +1097,7 @@ func resourceWorkbenchInstanceUpdate(d *schema.ResourceData, meta interface{}) e
1074
1097
state := d .Get ("state" ).(string )
1075
1098
desired_state := d .Get ("desired_state" ).(string )
1076
1099
1077
- if state != desired_state {
1100
+ if state != desired_state || stopInstance {
1078
1101
verb := "start"
1079
1102
if desired_state == "STOPPED" {
1080
1103
verb = "stop"
@@ -1088,6 +1111,13 @@ func resourceWorkbenchInstanceUpdate(d *schema.ResourceData, meta interface{}) e
1088
1111
return fmt .Errorf ("Error waiting to modify Workbench Instance state: %s" , err )
1089
1112
}
1090
1113
1114
+ if verb == "start" {
1115
+ if err := waitForWorkbenchInstanceActive (d , config , d .Timeout (schema .TimeoutUpdate )- time .Minute ); err != nil {
1116
+ return fmt .Errorf ("Workbench instance %q did not reach ACTIVE state: %q" , d .Get ("name" ).(string ), err )
1117
+ }
1118
+
1119
+ }
1120
+
1091
1121
} else {
1092
1122
log .Printf ("[DEBUG] Workbench Instance %q has state %q." , name , state )
1093
1123
}
0 commit comments