@@ -2999,6 +2999,31 @@ func TestAccComputeInstance_resourcePolicyCollocate(t *testing.T) {
2999
2999
})
3000
3000
}
3001
3001
3002
+ func TestAccComputeInstance_resourcePolicySpread(t *testing.T) {
3003
+ t.Parallel()
3004
+
3005
+ instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
3006
+ var instance compute.Instance
3007
+
3008
+ acctest.VcrTest(t, resource.TestCase{
3009
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
3010
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
3011
+ CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
3012
+ Steps: []resource.TestStep{
3013
+ {
3014
+ Config: testAccComputeInstance_resourcePolicySpread(instanceName, acctest.RandString(t, 10)),
3015
+ Check: resource.ComposeTestCheckFunc(
3016
+ testAccCheckComputeInstanceExists(
3017
+ t, "google_compute_instance.foobar", &instance),
3018
+ testAccCheckComputeInstanceHasStatus(&instance, "RUNNING"),
3019
+ testAccCheckComputeInstanceHasAvailabilityDomain(&instance, 3),
3020
+ ),
3021
+ },
3022
+ computeInstanceImportStep("us-east4-b", instanceName, []string{"allow_stopping_for_update"}),
3023
+ },
3024
+ })
3025
+ }
3026
+
3002
3027
func TestAccComputeInstance_subnetworkUpdate(t *testing.T) {
3003
3028
t.Parallel()
3004
3029
instanceName := fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10))
@@ -4436,6 +4461,23 @@ func testAccCheckComputeInstanceMaxRunDuration(instance *compute.Instance, insta
4436
4461
}
4437
4462
}
4438
4463
4464
+ func testAccCheckComputeInstanceHasAvailabilityDomain(instance *compute.Instance, availabilityDomain int64) resource.TestCheckFunc {
4465
+ return func(s *terraform.State) error {
4466
+ if instance == nil {
4467
+ return fmt.Errorf("instance is nil")
4468
+ }
4469
+ if instance.Scheduling == nil {
4470
+ return fmt.Errorf("no scheduling")
4471
+ }
4472
+
4473
+ if instance.Scheduling.AvailabilityDomain != availabilityDomain {
4474
+ return fmt.Errorf("got the wrong availability domain: have %d; want %d", instance.Scheduling.AvailabilityDomain, availabilityDomain)
4475
+ }
4476
+
4477
+ return nil
4478
+ }
4479
+ }
4480
+
4439
4481
func testAccCheckComputeInstanceLocalSsdRecoveryTimeout(instance *compute.Instance, instanceLocalSsdRecoveryTiemoutWant compute.Duration) resource.TestCheckFunc {
4440
4482
return func(s *terraform.State) error {
4441
4483
if instance == nil {
@@ -9349,6 +9391,50 @@ resource "google_compute_resource_policy" "foo" {
9349
9391
`, instance, instance, suffix)
9350
9392
}
9351
9393
9394
+ func testAccComputeInstance_resourcePolicySpread(instance, suffix string) string {
9395
+ return fmt.Sprintf(`
9396
+ data "google_compute_image" "my_image" {
9397
+ family = "debian-11"
9398
+ project = "debian-cloud"
9399
+ }
9400
+
9401
+ resource "google_compute_instance" "foobar" {
9402
+ name = "%s"
9403
+ machine_type = "e2-standard-4"
9404
+ zone = "us-east4-b"
9405
+ can_ip_forward = false
9406
+ tags = ["foo", "bar"]
9407
+
9408
+ //deletion_protection = false is implicit in this config due to default value
9409
+
9410
+ boot_disk {
9411
+ initialize_params {
9412
+ image = data.google_compute_image.my_image.self_link
9413
+ }
9414
+ }
9415
+
9416
+ network_interface {
9417
+ network = "default"
9418
+ }
9419
+
9420
+ scheduling {
9421
+ availability_domain = 3
9422
+ }
9423
+
9424
+ resource_policies = [google_compute_resource_policy.foo.self_link]
9425
+ }
9426
+
9427
+ resource "google_compute_resource_policy" "foo" {
9428
+ name = "tf-test-policy-%s"
9429
+ region = "us-east4"
9430
+ group_placement_policy {
9431
+ availability_domain_count = 3
9432
+ }
9433
+ }
9434
+
9435
+ `, instance, suffix)
9436
+ }
9437
+
9352
9438
func testAccComputeInstance_subnetworkUpdate(suffix, instance string) string {
9353
9439
return fmt.Sprintf(`
9354
9440
data "google_compute_image" "my_image" {
0 commit comments