Skip to content

Commit f5de157

Browse files
committed
fix diff on boot_disk.initialize_params.resource_policies
1 parent 8420234 commit f5de157

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.erb

+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.erb

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

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

@@ -5161,6 +5218,61 @@ resource "google_compute_instance" "foobar" {
51615218
`, context)
51625219
}
51635220

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

0 commit comments

Comments
 (0)