@@ -372,6 +372,63 @@ func TestAccComputeInstance_diskResourcePolicies(t *testing.T) {
372
372
})
373
373
}
374
374
375
+ func TestAccComputeInstance_diskResourcePolicies_attachmentDiff(t *testing.T) {
376
+ t.Parallel()
377
+
378
+ var instance compute.Instance
379
+ context_1 := map[string]interface{}{
380
+ "instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
381
+ "random_suffix": acctest.RandString(t, 10),
382
+ "comment": "",
383
+ }
384
+ context_2 := map[string]interface{}{
385
+ "instance_name": context_1["instance_name"],
386
+ "random_suffix": context_1["random_suffix"],
387
+ "comment": "#",
388
+ }
389
+
390
+ acctest.VcrTest(t, resource.TestCase{
391
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
392
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
393
+ CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
394
+ Steps: []resource.TestStep{
395
+ {
396
+ Config: testAccComputeInstance_diskResourcePoliciesAttachment(context_1),
397
+ Check: resource.ComposeTestCheckFunc(
398
+ testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
399
+ ),
400
+ },
401
+ {
402
+ ResourceName: "google_compute_instance.foobar",
403
+ ImportState: true,
404
+ ImportStateVerify: true,
405
+ },
406
+ {
407
+ Config: testAccComputeInstance_diskResourcePoliciesAttachment(context_2),
408
+ Check: resource.ComposeTestCheckFunc(
409
+ testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
410
+ ),
411
+ },
412
+ {
413
+ ResourceName: "google_compute_instance.foobar",
414
+ ImportState: true,
415
+ ImportStateVerify: true,
416
+ },
417
+ {
418
+ Config: testAccComputeInstance_diskResourcePoliciesOnePolicy(context_1),
419
+ Check: resource.ComposeTestCheckFunc(
420
+ testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
421
+ ),
422
+ },
423
+ {
424
+ ResourceName: "google_compute_instance.foobar",
425
+ ImportState: true,
426
+ ImportStateVerify: true,
427
+ },
428
+ },
429
+ })
430
+ }
431
+
375
432
func TestAccComputeInstance_machineTypeUrl(t *testing.T) {
376
433
t.Parallel()
377
434
@@ -5327,6 +5384,61 @@ resource "google_compute_instance" "foobar" {
5327
5384
`, context)
5328
5385
}
5329
5386
5387
+ func testAccComputeInstance_diskResourcePoliciesAttachment(context map[string]interface{}) string {
5388
+ return acctest.Nprintf(`
5389
+ data "google_compute_image" "my_image" {
5390
+ family = "debian-11"
5391
+ project = "debian-cloud"
5392
+ }
5393
+
5394
+ resource "google_compute_resource_policy" "test-snapshot-policy" {
5395
+ name = "test-policy-%{random_suffix}"
5396
+ snapshot_schedule_policy {
5397
+ schedule {
5398
+ hourly_schedule {
5399
+ hours_in_cycle = 1
5400
+ start_time = "11:00"
5401
+ }
5402
+ }
5403
+ }
5404
+ }
5405
+
5406
+ resource "google_compute_resource_policy" "test-snapshot-policy2" {
5407
+ name = "test-policy2-%{random_suffix}"
5408
+ snapshot_schedule_policy {
5409
+ schedule {
5410
+ hourly_schedule {
5411
+ hours_in_cycle = 1
5412
+ start_time = "22:00"
5413
+ }
5414
+ }
5415
+ }
5416
+ }
5417
+
5418
+ resource "google_compute_instance" "foobar" {
5419
+ name = "%{instance_name}"
5420
+ machine_type = "e2-medium"
5421
+ zone = "us-central1-a"
5422
+
5423
+ boot_disk {
5424
+ initialize_params {
5425
+ image = data.google_compute_image.my_image.self_link
5426
+ }
5427
+ }
5428
+
5429
+ network_interface {
5430
+ network = "default"
5431
+ }
5432
+ }
5433
+
5434
+ %{comment} resource "google_compute_disk_resource_policy_attachment" "attachment" {
5435
+ %{comment} name = google_compute_resource_policy.test-snapshot-policy2.name
5436
+ %{comment} disk = google_compute_instance.foobar.name
5437
+ %{comment} zone = google_compute_instance.foobar.zone
5438
+ %{comment} }
5439
+ `, context)
5440
+ }
5441
+
5330
5442
func testAccComputeInstance_basic_deletionProtectionFalse(instance string) string {
5331
5443
return fmt.Sprintf(`
5332
5444
data "google_compute_image" "my_image" {
0 commit comments