@@ -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
@@ -5277,6 +5334,61 @@ resource "google_compute_instance" "foobar" {
5277
5334
`, context)
5278
5335
}
5279
5336
5337
+ func testAccComputeInstance_diskResourcePoliciesAttachment(context map[string]interface{}) string {
5338
+ return acctest.Nprintf(`
5339
+ data "google_compute_image" "my_image" {
5340
+ family = "debian-11"
5341
+ project = "debian-cloud"
5342
+ }
5343
+
5344
+ resource "google_compute_resource_policy" "test-snapshot-policy" {
5345
+ name = "test-policy-%{random_suffix}"
5346
+ snapshot_schedule_policy {
5347
+ schedule {
5348
+ hourly_schedule {
5349
+ hours_in_cycle = 1
5350
+ start_time = "11:00"
5351
+ }
5352
+ }
5353
+ }
5354
+ }
5355
+
5356
+ resource "google_compute_resource_policy" "test-snapshot-policy2" {
5357
+ name = "test-policy2-%{random_suffix}"
5358
+ snapshot_schedule_policy {
5359
+ schedule {
5360
+ hourly_schedule {
5361
+ hours_in_cycle = 1
5362
+ start_time = "22:00"
5363
+ }
5364
+ }
5365
+ }
5366
+ }
5367
+
5368
+ resource "google_compute_instance" "foobar" {
5369
+ name = "%{instance_name}"
5370
+ machine_type = "e2-medium"
5371
+ zone = "us-central1-a"
5372
+
5373
+ boot_disk {
5374
+ initialize_params {
5375
+ image = data.google_compute_image.my_image.self_link
5376
+ }
5377
+ }
5378
+
5379
+ network_interface {
5380
+ network = "default"
5381
+ }
5382
+ }
5383
+
5384
+ %{comment} resource "google_compute_disk_resource_policy_attachment" "attachment" {
5385
+ %{comment} name = google_compute_resource_policy.test-snapshot-policy2.name
5386
+ %{comment} disk = google_compute_instance.foobar.name
5387
+ %{comment} zone = google_compute_instance.foobar.zone
5388
+ %{comment} }
5389
+ `, context)
5390
+ }
5391
+
5280
5392
func testAccComputeInstance_basic_deletionProtectionFalse(instance string) string {
5281
5393
return fmt.Sprintf(`
5282
5394
data "google_compute_image" "my_image" {
0 commit comments