Skip to content

Commit b474740

Browse files
karolgorczli82016
andcommitted
Fix permadiff on boot_disk.initialize_params.resource_policies (GoogleCloudPlatform#11753)
Co-authored-by: Zhenhua Li <[email protected]>
1 parent 4e498ca commit b474740

File tree

2 files changed

+113
-0
lines changed

2 files changed

+113
-0
lines changed

mmv1/third_party/terraform/services/compute/resource_compute_instance.go.tmpl

+1
Original file line numberDiff line numberDiff line change
@@ -316,6 +316,7 @@ func ResourceComputeInstance() *schema.Resource {
316316
Elem: &schema.Schema{Type: schema.TypeString},
317317
Optional: true,
318318
ForceNew: true,
319+
Computed: true,
319320
AtLeastOneOf: initializeParamsKeys,
320321
DiffSuppressFunc: tpgresource.CompareSelfLinkRelativePaths,
321322
MaxItems: 1,

mmv1/third_party/terraform/services/compute/resource_compute_instance_test.go.tmpl

+112
Original file line numberDiff line numberDiff line change
@@ -372,6 +372,63 @@ func TestAccComputeInstance_diskResourcePolicies(t *testing.T) {
372372
})
373373
}
374374

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+
375432
func TestAccComputeInstance_machineTypeUrl(t *testing.T) {
376433
t.Parallel()
377434

@@ -5327,6 +5384,61 @@ resource "google_compute_instance" "foobar" {
53275384
`, context)
53285385
}
53295386

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+
53305442
func testAccComputeInstance_basic_deletionProtectionFalse(instance string) string {
53315443
return fmt.Sprintf(`
53325444
data "google_compute_image" "my_image" {

0 commit comments

Comments
 (0)