diff --git a/terraform/terraform.go b/terraform/terraform.go index 14dc9ef1a..1f7f469ff 100644 --- a/terraform/terraform.go +++ b/terraform/terraform.go @@ -154,7 +154,7 @@ func (t *Terraform) diffWalkFn( } // If there were no diff items, return right away - if len(diff.Attributes) == 0 { + if diff == nil || len(diff.Attributes) == 0 { return nil } diff --git a/terraform/terraform_test.go b/terraform/terraform_test.go index 3c90f5939..7f4ef8211 100644 --- a/terraform/terraform_test.go +++ b/terraform/terraform_test.go @@ -202,6 +202,18 @@ func TestTerraformDiff(t *testing.T) { } } +func TestTerraformDiff_nil(t *testing.T) { + tf := testTerraform(t, "diff-nil") + + diff, err := tf.Diff(nil) + if err != nil { + t.Fatalf("err: %s", err) + } + if len(diff.Resources) != 0 { + t.Fatalf("bad: %#v", diff.Resources) + } +} + func TestTerraformDiff_computed(t *testing.T) { tf := testTerraform(t, "diff-computed") @@ -269,6 +281,10 @@ func testProviderFunc(n string, rs []string) ResourceProviderFactory { continue } + if k == "nil" { + return nil, nil + } + if k == "compute" { diff.Attributes[v.(string)] = &ResourceAttrDiff{ Old: "", diff --git a/terraform/test-fixtures/diff-nil/main.tf b/terraform/test-fixtures/diff-nil/main.tf new file mode 100644 index 000000000..4adbc1aca --- /dev/null +++ b/terraform/test-fixtures/diff-nil/main.tf @@ -0,0 +1,3 @@ +resource "aws_instance" "foo" { + nil = "1" +}