From 29c83231ce746a188959554d7ee6343c6f251cd3 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 13 Apr 2015 18:56:48 -0500 Subject: [PATCH] core: avoid diff mismatch on NewRemoved fields during -/+ fixes #1508 In a DESTROY/CREATE scenario, the plan diff will be run against the state of the old instance, while the apply diff will be run against an empty state (because the state is cleared when the destroy node does its thing.) For complex attributes, this can result in keys that seem to disappear between the two diffs, when in reality everything is working just fine. Same() needs to take into account this scenario by analyzing NewRemoved and treating as "Same" a diff that does indeed have that key removed. --- resource_compute_instance_test.go | 52 +++++++++++++++++++++++++++++++ 1 file changed, 52 insertions(+) diff --git a/resource_compute_instance_test.go b/resource_compute_instance_test.go index 9c53fae0..612282b1 100644 --- a/resource_compute_instance_test.go +++ b/resource_compute_instance_test.go @@ -168,6 +168,34 @@ func TestAccComputeInstance_update_deprecated_network(t *testing.T) { }) } +func TestAccComputeInstance_forceNewAndChangeMetadata(t *testing.T) { + var instance compute.Instance + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testAccCheckComputeInstanceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccComputeInstance_basic, + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeInstanceExists( + "google_compute_instance.foobar", &instance), + ), + }, + resource.TestStep{ + Config: testAccComputeInstance_forceNewAndChangeMetadata, + Check: resource.ComposeTestCheckFunc( + testAccCheckComputeInstanceExists( + "google_compute_instance.foobar", &instance), + testAccCheckComputeInstanceMetadata( + &instance, "qux", "true"), + ), + }, + }, + }) +} + func TestAccComputeInstance_update(t *testing.T) { var instance compute.Instance @@ -432,6 +460,30 @@ resource "google_compute_instance" "foobar" { } }` +// Update zone to ForceNew, and change metadata k/v entirely +// Generates diff mismatch +const testAccComputeInstance_forceNewAndChangeMetadata = ` +resource "google_compute_instance" "foobar" { + name = "terraform-test" + machine_type = "n1-standard-1" + zone = "us-central1-a" + zone = "us-central1-b" + tags = ["baz"] + + disk { + image = "debian-7-wheezy-v20140814" + } + + network_interface { + network = "default" + access_config { } + } + + metadata { + qux = "true" + } +}` + // Update metadata, tags, and network_interface const testAccComputeInstance_update = ` resource "google_compute_instance" "foobar" {