@@ -2986,6 +2986,31 @@ func TestAccComputeInstance_resourcePolicyCollocate(t *testing.T) {
2986
2986
})
2987
2987
}
2988
2988
2989
+ func TestAccComputeInstance_resourcePolicySpread (t * testing.T ) {
2990
+ t .Parallel ()
2991
+
2992
+ instanceName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
2993
+ var instance compute.Instance
2994
+
2995
+ acctest .VcrTest (t , resource.TestCase {
2996
+ PreCheck : func () { acctest .AccTestPreCheck (t ) },
2997
+ ProtoV5ProviderFactories : acctest .ProtoV5ProviderFactories (t ),
2998
+ CheckDestroy : testAccCheckComputeInstanceDestroyProducer (t ),
2999
+ Steps : []resource.TestStep {
3000
+ {
3001
+ Config : testAccComputeInstance_resourcePolicySpread (instanceName , acctest .RandString (t , 10 )),
3002
+ Check : resource .ComposeTestCheckFunc (
3003
+ testAccCheckComputeInstanceExists (
3004
+ t , "google_compute_instance.foobar" , & instance ),
3005
+ testAccCheckComputeInstanceHasStatus (& instance , "RUNNING" ),
3006
+ testAccCheckComputeInstanceHasAvailabilityDomain (& instance , 3 ),
3007
+ ),
3008
+ },
3009
+ computeInstanceImportStep ("us-east4-b" , instanceName , []string {"allow_stopping_for_update" }),
3010
+ },
3011
+ })
3012
+ }
3013
+
2989
3014
func TestAccComputeInstance_subnetworkUpdate (t * testing.T ) {
2990
3015
t .Parallel ()
2991
3016
instanceName := fmt .Sprintf ("tf-test-%s" , acctest .RandString (t , 10 ))
@@ -4408,6 +4433,23 @@ func testAccCheckComputeInstanceMaxRunDuration(instance *compute.Instance, insta
4408
4433
}
4409
4434
}
4410
4435
4436
+ func testAccCheckComputeInstanceHasAvailabilityDomain (instance * compute.Instance , availabilityDomain int64 ) resource.TestCheckFunc {
4437
+ return func (s * terraform.State ) error {
4438
+ if instance == nil {
4439
+ return fmt .Errorf ("instance is nil" )
4440
+ }
4441
+ if instance .Scheduling == nil {
4442
+ return fmt .Errorf ("no scheduling" )
4443
+ }
4444
+
4445
+ if instance .Scheduling .AvailabilityDomain != availabilityDomain {
4446
+ return fmt .Errorf ("got the wrong availability domain: have %d; want %d" , instance .Scheduling .AvailabilityDomain , availabilityDomain )
4447
+ }
4448
+
4449
+ return nil
4450
+ }
4451
+ }
4452
+
4411
4453
func testAccCheckComputeInstanceLocalSsdRecoveryTimeout (instance * compute.Instance , instanceLocalSsdRecoveryTiemoutWant compute.Duration ) resource.TestCheckFunc {
4412
4454
return func (s * terraform.State ) error {
4413
4455
if instance == nil {
@@ -9309,6 +9351,50 @@ resource "google_compute_resource_policy" "foo" {
9309
9351
` , instance , instance , suffix )
9310
9352
}
9311
9353
9354
+ func testAccComputeInstance_resourcePolicySpread (instance , suffix string ) string {
9355
+ return fmt .Sprintf (`
9356
+ data "google_compute_image" "my_image" {
9357
+ family = "debian-11"
9358
+ project = "debian-cloud"
9359
+ }
9360
+
9361
+ resource "google_compute_instance" "foobar" {
9362
+ name = "%s"
9363
+ machine_type = "e2-standard-4"
9364
+ zone = "us-east4-b"
9365
+ can_ip_forward = false
9366
+ tags = ["foo", "bar"]
9367
+
9368
+ //deletion_protection = false is implicit in this config due to default value
9369
+
9370
+ boot_disk {
9371
+ initialize_params {
9372
+ image = data.google_compute_image.my_image.self_link
9373
+ }
9374
+ }
9375
+
9376
+ network_interface {
9377
+ network = "default"
9378
+ }
9379
+
9380
+ scheduling {
9381
+ availability_domain = 3
9382
+ }
9383
+
9384
+ resource_policies = [google_compute_resource_policy.foo.self_link]
9385
+ }
9386
+
9387
+ resource "google_compute_resource_policy" "foo" {
9388
+ name = "tf-test-policy-%s"
9389
+ region = "us-east4"
9390
+ group_placement_policy {
9391
+ availability_domain_count = 3
9392
+ }
9393
+ }
9394
+
9395
+ ` , instance , suffix )
9396
+ }
9397
+
9312
9398
func testAccComputeInstance_subnetworkUpdate (suffix , instance string ) string {
9313
9399
return fmt .Sprintf (`
9314
9400
data "google_compute_image" "my_image" {
0 commit comments