@@ -2370,6 +2370,35 @@ func TestComputeInstance_networkIPCustomizedDiff(t *testing.T) {
2370
2370
}
2371
2371
}
2372
2372
2373
+ func TestAccComputeInstance_metadataStartupScript_update (t * testing.T ) {
2374
+ t .Parallel ()
2375
+
2376
+ var instance compute.Instance
2377
+ var instanceName = fmt .Sprintf ("tf-test-%s" , randString (t , 10 ))
2378
+
2379
+ vcrTest (t , resource.TestCase {
2380
+ PreCheck : func () { testAccPreCheck (t ) },
2381
+ Providers : testAccProviders ,
2382
+ CheckDestroy : testAccCheckComputeInstanceDestroyProducer (t ),
2383
+ Steps : []resource.TestStep {
2384
+ {
2385
+ Config : testAccComputeInstance_metadataStartupScript (instanceName , "e2-medium" , "abc" ),
2386
+ Check : resource .ComposeTestCheckFunc (
2387
+ testAccCheckComputeInstanceExists (
2388
+ t , "google_compute_instance.foobar" , & instance ),
2389
+ ),
2390
+ },
2391
+ {
2392
+ Config : testAccComputeInstance_metadataStartupScript (instanceName , "e2-standard-4" , "xyz" ),
2393
+ Check : resource .ComposeTestCheckFunc (
2394
+ testAccCheckComputeInstanceExists (
2395
+ t , "google_compute_instance.foobar" , & instance ),
2396
+ ),
2397
+ },
2398
+ },
2399
+ })
2400
+ }
2401
+
2373
2402
func testAccCheckComputeInstanceUpdateMachineType (t * testing.T , n string ) resource.TestCheckFunc {
2374
2403
return func (s * terraform.State ) error {
2375
2404
rs , ok := s .RootModule ().Resources [n ]
@@ -6205,3 +6234,36 @@ resource "google_compute_instance" "foobar" {
6205
6234
}
6206
6235
` , instance )
6207
6236
}
6237
+
6238
+ func testAccComputeInstance_metadataStartupScript (instance , machineType , metadata string ) string {
6239
+ return fmt .Sprintf (`
6240
+ data "google_compute_image" "my_image" {
6241
+ family = "debian-11"
6242
+ project = "debian-cloud"
6243
+ }
6244
+
6245
+ resource "google_compute_instance" "foobar" {
6246
+ name = "%s"
6247
+ machine_type = "%s"
6248
+ zone = "us-central1-a"
6249
+ can_ip_forward = false
6250
+ tags = ["foo", "bar"]
6251
+
6252
+ boot_disk {
6253
+ initialize_params {
6254
+ image = data.google_compute_image.my_image.self_link
6255
+ }
6256
+ }
6257
+
6258
+ network_interface {
6259
+ network = "default"
6260
+ }
6261
+
6262
+ metadata = {
6263
+ foo = "%s"
6264
+ }
6265
+ metadata_startup_script = "echo hi > /test.txt"
6266
+ allow_stopping_for_update = true
6267
+ }
6268
+ ` , instance , machineType , metadata )
6269
+ }
0 commit comments