diff --git a/builtin/providers/test/provider.go b/builtin/providers/test/provider.go index d69ae95f9..e8b6cf228 100644 --- a/builtin/providers/test/provider.go +++ b/builtin/providers/test/provider.go @@ -22,6 +22,7 @@ func Provider() terraform.ResourceProvider { "test_resource_with_custom_diff": testResourceCustomDiff(), "test_resource_timeout": testResourceTimeout(), "test_resource_diff_suppress": testResourceDiffSuppress(), + "test_resource_force_new": testResourceForceNew(), }, DataSourcesMap: map[string]*schema.Resource{ "test_data_source": testDataSource(), diff --git a/builtin/providers/test/resource_force_new.go b/builtin/providers/test/resource_force_new.go new file mode 100644 index 000000000..81a06736c --- /dev/null +++ b/builtin/providers/test/resource_force_new.go @@ -0,0 +1,39 @@ +package test + +import ( + "github.com/hashicorp/terraform/helper/schema" +) + +func testResourceForceNew() *schema.Resource { + return &schema.Resource{ + Create: testResourceForceNewCreate, + Read: testResourceForceNewRead, + Delete: testResourceForceNewDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Schema: map[string]*schema.Schema{ + "triggers": { + Type: schema.TypeMap, + Optional: true, + ForceNew: true, + }, + }, + } +} + +func testResourceForceNewCreate(d *schema.ResourceData, meta interface{}) error { + d.SetId("testId") + return testResourceForceNewRead(d, meta) +} + +func testResourceForceNewRead(d *schema.ResourceData, meta interface{}) error { + return nil +} + +func testResourceForceNewDelete(d *schema.ResourceData, meta interface{}) error { + d.SetId("") + return nil +} diff --git a/builtin/providers/test/resource_force_new_test.go b/builtin/providers/test/resource_force_new_test.go new file mode 100644 index 000000000..3e0bf19c3 --- /dev/null +++ b/builtin/providers/test/resource_force_new_test.go @@ -0,0 +1,79 @@ +package test + +import ( + "strings" + "testing" + + "github.com/hashicorp/terraform/helper/resource" +) + +func TestResourceForceNew_create(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_force_new" "foo" { + triggers = { + "a" = "foo" + } +}`), + }, + }, + }) +} +func TestResourceForceNew_update(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_force_new" "foo" { + triggers = { + "a" = "foo" + } +}`), + }, + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_force_new" "foo" { + triggers = { + "a" = "bar" + } +}`), + }, + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_force_new" "foo" { + triggers = { + "b" = "bar" + } +}`), + }, + }, + }) +} + +func TestResourceForceNew_remove(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_force_new" "foo" { + triggers = { + "a" = "bar" + } +}`), + }, + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource_force_new" "foo" { +} `), + }, + }, + }) +} diff --git a/builtin/providers/test/resource_test.go b/builtin/providers/test/resource_test.go index 2d0168fc7..dd33783ff 100644 --- a/builtin/providers/test/resource_test.go +++ b/builtin/providers/test/resource_test.go @@ -443,3 +443,33 @@ output "value_from_map_from_list" { func testAccCheckResourceDestroy(s *terraform.State) error { return nil } + +func TestResource_removeForceNew(t *testing.T) { + resource.UnitTest(t, resource.TestCase{ + Providers: testAccProviders, + CheckDestroy: testAccCheckResourceDestroy, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource" "foo" { + required = "yep" + required_map = { + key = "value" + } + optional_force_new = "here" +} + `), + }, + resource.TestStep{ + Config: strings.TrimSpace(` +resource "test_resource" "foo" { + required = "yep" + required_map = { + key = "value" + } +} + `), + }, + }, + }) +}