@@ -373,6 +373,63 @@ func TestAccComputeInstance_diskResourcePolicies(t *testing.T) {
373
373
})
374
374
}
375
375
376
+ func TestAccComputeInstance_diskResourcePolicies_attachmentDiff(t *testing.T) {
377
+ t.Parallel()
378
+
379
+ var instance compute.Instance
380
+ context_1 := map[string]interface{}{
381
+ "instance_name": fmt.Sprintf("tf-test-%s", acctest.RandString(t, 10)),
382
+ "random_suffix": acctest.RandString(t, 10),
383
+ "comment": "",
384
+ }
385
+ context_2 := map[string]interface{}{
386
+ "instance_name": context_1["instance_name"],
387
+ "random_suffix": context_1["random_suffix"],
388
+ "comment": "#",
389
+ }
390
+
391
+ acctest.VcrTest(t, resource.TestCase{
392
+ PreCheck: func() { acctest.AccTestPreCheck(t) },
393
+ ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
394
+ CheckDestroy: testAccCheckComputeInstanceDestroyProducer(t),
395
+ Steps: []resource.TestStep{
396
+ {
397
+ Config: testAccComputeInstance_diskResourcePoliciesAttachment(context_1),
398
+ Check: resource.ComposeTestCheckFunc(
399
+ testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
400
+ ),
401
+ },
402
+ {
403
+ ResourceName: "google_compute_instance.foobar",
404
+ ImportState: true,
405
+ ImportStateVerify: true,
406
+ },
407
+ {
408
+ Config: testAccComputeInstance_diskResourcePoliciesAttachment(context_2),
409
+ Check: resource.ComposeTestCheckFunc(
410
+ testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
411
+ ),
412
+ },
413
+ {
414
+ ResourceName: "google_compute_instance.foobar",
415
+ ImportState: true,
416
+ ImportStateVerify: true,
417
+ },
418
+ {
419
+ Config: testAccComputeInstance_diskResourcePoliciesOnePolicy(context_1),
420
+ Check: resource.ComposeTestCheckFunc(
421
+ testAccCheckComputeInstanceExists(t, "google_compute_instance.foobar", &instance),
422
+ ),
423
+ },
424
+ {
425
+ ResourceName: "google_compute_instance.foobar",
426
+ ImportState: true,
427
+ ImportStateVerify: true,
428
+ },
429
+ },
430
+ })
431
+ }
432
+
376
433
func TestAccComputeInstance_machineTypeUrl(t *testing.T) {
377
434
t.Parallel()
378
435
@@ -5161,6 +5218,61 @@ resource "google_compute_instance" "foobar" {
5161
5218
`, context)
5162
5219
}
5163
5220
5221
+ func testAccComputeInstance_diskResourcePoliciesAttachment(context map[string]interface{}) string {
5222
+ return acctest.Nprintf(`
5223
+ data "google_compute_image" "my_image" {
5224
+ family = "debian-11"
5225
+ project = "debian-cloud"
5226
+ }
5227
+
5228
+ resource "google_compute_resource_policy" "test-snapshot-policy" {
5229
+ name = "test-policy-%{random_suffix}"
5230
+ snapshot_schedule_policy {
5231
+ schedule {
5232
+ hourly_schedule {
5233
+ hours_in_cycle = 1
5234
+ start_time = "11:00"
5235
+ }
5236
+ }
5237
+ }
5238
+ }
5239
+
5240
+ resource "google_compute_resource_policy" "test-snapshot-policy2" {
5241
+ name = "test-policy2-%{random_suffix}"
5242
+ snapshot_schedule_policy {
5243
+ schedule {
5244
+ hourly_schedule {
5245
+ hours_in_cycle = 1
5246
+ start_time = "22:00"
5247
+ }
5248
+ }
5249
+ }
5250
+ }
5251
+
5252
+ resource "google_compute_instance" "foobar" {
5253
+ name = "%{instance_name}"
5254
+ machine_type = "e2-medium"
5255
+ zone = "us-central1-a"
5256
+
5257
+ boot_disk {
5258
+ initialize_params {
5259
+ image = data.google_compute_image.my_image.self_link
5260
+ }
5261
+ }
5262
+
5263
+ network_interface {
5264
+ network = "default"
5265
+ }
5266
+ }
5267
+
5268
+ %{comment} resource "google_compute_disk_resource_policy_attachment" "attachment" {
5269
+ %{comment} name = google_compute_resource_policy.test-snapshot-policy2.name
5270
+ %{comment} disk = google_compute_instance.foobar.name
5271
+ %{comment} zone = google_compute_instance.foobar.zone
5272
+ %{comment} }
5273
+ `, context)
5274
+ }
5275
+
5164
5276
func testAccComputeInstance_basic_deletionProtectionFalse(instance string) string {
5165
5277
return fmt.Sprintf(`
5166
5278
data "google_compute_image" "my_image" {
0 commit comments