diff --git a/builtin/providers/test/resource_nested_set.go b/builtin/providers/test/resource_nested_set.go index 318e020e1..c1e6520fb 100644 --- a/builtin/providers/test/resource_nested_set.go +++ b/builtin/providers/test/resource_nested_set.go @@ -23,6 +23,11 @@ func testResourceNestedSet() *schema.Resource { Type: schema.TypeBool, Optional: true, }, + "force_new": { + Type: schema.TypeString, + Optional: true, + ForceNew: true, + }, "single": { Type: schema.TypeSet, Optional: true, diff --git a/builtin/providers/test/resource_nested_set_test.go b/builtin/providers/test/resource_nested_set_test.go index fb5694fa7..fe2818701 100644 --- a/builtin/providers/test/resource_nested_set_test.go +++ b/builtin/providers/test/resource_nested_set_test.go @@ -127,7 +127,7 @@ resource "test_resource_nested_set" "foo" { }, }) } -func TestResourceNestedSet_multi(t *testing.T) { +func TestResourceNestedSet_multiAddRemove(t *testing.T) { checkFunc := func(s *terraform.State) error { return nil } @@ -214,6 +214,25 @@ resource "test_resource_nested_set" "foo" { optional_int = 3 } } +} + `), + Check: checkFunc, + }, + + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_nested_set" "foo" { + optional = true + single { + value = "bar" + optional = "baz" + } + multi { + set { + required = "new" + optional_int = 3 + } + } } `), Check: checkFunc, @@ -221,3 +240,68 @@ resource "test_resource_nested_set" "foo" { }, }) } + +func TestResourceNestedSet_forceNewEmptyString(t *testing.T) { + var id string + step := 0 + checkFunc := func(s *terraform.State) error { + root := s.ModuleByPath(addrs.RootModuleInstance) + res := root.Resources["test_resource_nested_set.foo"] + defer func() { + step++ + id = res.Primary.ID + }() + + if step == 2 && res.Primary.ID == id { + // setting an empty string currently does not trigger ForceNew, but + // it should in the future. + return nil + } + + if res.Primary.ID == id { + return errors.New("expected new resource") + } + + return nil + } + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_nested_set" "foo" { + multi { + set { + required = "val" + } + } +} + `), + Check: checkFunc, + }, + + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_nested_set" "foo" { + multi { + set { + required = "" + } + } +} + `), + Check: checkFunc, + }, + + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_nested_set" "foo" { + force_new = "" +} + `), + Check: checkFunc, + }, + }, + }) +}