diff --git a/builtin/bins/provider-test/main.go b/builtin/bins/provider-test/main.go deleted file mode 100644 index 97d03f2583..0000000000 --- a/builtin/bins/provider-test/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "github.com/hashicorp/terraform/builtin/providers/test" - "github.com/hashicorp/terraform/plugin" - "github.com/hashicorp/terraform/terraform" -) - -func main() { - plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: func() terraform.ResourceProvider { - return test.Provider() - }, - }) -} diff --git a/builtin/providers/test/data_source_label_test.go b/builtin/providers/test/data_source_label_test.go deleted file mode 100644 index d98a27b060..0000000000 --- a/builtin/providers/test/data_source_label_test.go +++ /dev/null @@ -1,45 +0,0 @@ -package test - -import ( - "errors" - "fmt" - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestProviderLabelDataSource(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -provider "test" { - label = "foo" -} - -data "test_provider_label" "test" { -} - `), - Check: func(s *terraform.State) error { - res, hasRes := s.RootModule().Resources["data.test_provider_label.test"] - if !hasRes { - return errors.New("No test_provider_label in state") - } - if got, want := res.Primary.ID, "foo"; got != want { - return fmt.Errorf("wrong id %q; want %q", got, want) - } - if got, want := res.Primary.Attributes["label"], "foo"; got != want { - return fmt.Errorf("wrong id %q; want %q", got, want) - } - return nil - }, - }, - }, - }) -} diff --git a/builtin/providers/test/data_source_test.go b/builtin/providers/test/data_source_test.go deleted file mode 100644 index c0a1ae57c3..0000000000 --- a/builtin/providers/test/data_source_test.go +++ /dev/null @@ -1,291 +0,0 @@ -package test - -import ( - "errors" - "fmt" - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestDataSource_dataSourceCount(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -data "test_data_source" "test" { - count = 3 - input = "count-${count.index}" -} - -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - - list = "${data.test_data_source.test.*.output}" -} - `), - Check: func(s *terraform.State) error { - res, hasRes := s.RootModule().Resources["test_resource.foo"] - if !hasRes { - return errors.New("No test_resource.foo in state") - } - if res.Primary.Attributes["list.#"] != "3" { - return errors.New("Wrong list.#, expected 3") - } - if res.Primary.Attributes["list.0"] != "count-0" { - return errors.New("Wrong list.0, expected count-0") - } - if res.Primary.Attributes["list.1"] != "count-1" { - return errors.New("Wrong list.0, expected count-1") - } - if res.Primary.Attributes["list.2"] != "count-2" { - return errors.New("Wrong list.0, expected count-2") - } - return nil - }, - }, - }, - }) -} - -// Test that the output of a data source can be used as the value for -// a "count" in a real resource. This would fail with "count cannot be computed" -// at some point. -func TestDataSource_valueAsResourceCount(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -data "test_data_source" "test" { - input = "4" -} - -resource "test_resource" "foo" { - count = "${data.test_data_source.test.output}" - - required = "yep" - required_map = { - key = "value" - } -} - `), - Check: func(s *terraform.State) error { - count := 0 - for k, _ := range s.RootModule().Resources { - if strings.HasPrefix(k, "test_resource.foo.") { - count++ - } - } - - if count != 4 { - return fmt.Errorf("bad count: %d", count) - } - return nil - }, - }, - }, - }) -} - -// TestDataSource_dataSourceCountGrandChild tests that a grandchild data source -// that is based off of count works, ie: dependency chain foo -> bar -> baz. -// This was failing because CountBoundaryTransformer is being run during apply -// instead of plan, which meant that it wasn't firing after data sources were -// potentially changing state and causing diff/interpolation issues. -// -// This happens after the initial apply, after state is saved. -func TestDataSource_dataSourceCountGrandChild(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: dataSourceCountGrandChildConfig, - }, - { - Config: dataSourceCountGrandChildConfig, - Check: func(s *terraform.State) error { - for _, v := range []string{"foo", "bar", "baz"} { - count := 0 - for k := range s.RootModule().Resources { - if strings.HasPrefix(k, fmt.Sprintf("data.test_data_source.%s.", v)) { - count++ - } - } - - if count != 2 { - return fmt.Errorf("bad count for data.test_data_source.%s: %d", v, count) - } - } - return nil - }, - }, - }, - }) -} - -const dataSourceCountGrandChildConfig = ` -data "test_data_source" "foo" { - count = 2 - input = "one" -} - -data "test_data_source" "bar" { - count = "${length(data.test_data_source.foo.*.id)}" - input = "${data.test_data_source.foo.*.output[count.index]}" -} - -data "test_data_source" "baz" { - count = "${length(data.test_data_source.bar.*.id)}" - input = "${data.test_data_source.bar.*.output[count.index]}" -} -` - -func TestDataSource_nilComputedValues(t *testing.T) { - check := func(s *terraform.State) error { - return nil - } - - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Check: check, - Config: ` -variable "index" { - default = "d" -} - -locals { - name = { - a = "something" - b = "else" - } -} - -data "test_data_source" "x" { - input = "${lookup(local.name, var.index, local.name["a"])}" -} - -data "test_data_source" "y" { - input = data.test_data_source.x.nil == "something" ? "something" : "else" -}`, - }, - }, - }) -} - -// referencing test_data_source.one.output_map["a"] should produce an error when -// there's a count. -func TestDataSource_indexedCountOfOne(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -data "test_data_source" "one" { - count = 1 - input_map = { - "a" = "b" - } -} - -data "test_data_source" "two" { - input_map = { - "x" = data.test_data_source.one.output_map["a"] - } -} - `), - ExpectError: regexp.MustCompile("Because data.test_data_source.one has \"count\" set, its attributes must be accessed on specific instances"), - }, - }, - }) -} - -// Verify that we can destroy when a data source references something with a -// count of 1. -func TestDataSource_countRefDestroyError(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -data "test_data_source" "one" { - count = 1 - input = "a" -} - -data "test_data_source" "two" { - input = data.test_data_source.one[0].output -} - `), - }, - }, - }) -} - -func TestDataSource_planUpdate(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -resource "test_resource" "a" { - required = "first" - required_map = { - key = "1" - } - optional_force_new = "first" -} - -data "test_data_source" "a" { - input = "${test_resource.a.computed_from_required}" -} - -output "out" { - value = "${data.test_data_source.a.output}" -} - `), - }, - { - Config: strings.TrimSpace(` -resource "test_resource" "a" { - required = "second" - required_map = { - key = "1" - } - optional_force_new = "second" -} - -data "test_data_source" "a" { - input = "${test_resource.a.computed_from_required}" -} - -output "out" { - value = "${data.test_data_source.a.output}" -} - `), - Check: resource.ComposeAggregateTestCheckFunc( - resource.TestCheckResourceAttr("data.test_data_source.a", "output", "second"), - resource.TestCheckOutput("out", "second"), - ), - }, - }, - }) -} diff --git a/builtin/providers/test/diff_apply_test.go b/builtin/providers/test/diff_apply_test.go deleted file mode 100644 index b28e110e02..0000000000 --- a/builtin/providers/test/diff_apply_test.go +++ /dev/null @@ -1,144 +0,0 @@ -package test - -import ( - "reflect" - "testing" - - "github.com/davecgh/go-spew/spew" - "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/terraform" -) - -func TestDiffApply_set(t *testing.T) { - priorAttrs := map[string]string{ - "id": "testID", - "egress.#": "1", - "egress.2129912301.cidr_blocks.#": "1", - "egress.2129912301.cidr_blocks.0": "10.0.0.0/8", - "egress.2129912301.description": "Egress description", - "egress.2129912301.from_port": "80", - "egress.2129912301.ipv6_cidr_blocks.#": "0", - "egress.2129912301.prefix_list_ids.#": "0", - "egress.2129912301.protocol": "tcp", - "egress.2129912301.security_groups.#": "0", - "egress.2129912301.self": "false", - "egress.2129912301.to_port": "8000", - } - - diff := &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{ - "egress.2129912301.cidr_blocks.#": {Old: "1", New: "0", NewComputed: false, NewRemoved: false}, - "egress.2129912301.cidr_blocks.0": {Old: "10.0.0.0/8", New: "", NewComputed: false, NewRemoved: true}, - "egress.2129912301.description": {Old: "Egress description", New: "", NewComputed: false, NewRemoved: true}, - "egress.2129912301.from_port": {Old: "80", New: "0", NewComputed: false, NewRemoved: true}, - "egress.2129912301.ipv6_cidr_blocks.#": {Old: "0", New: "0", NewComputed: false, NewRemoved: false}, - "egress.2129912301.prefix_list_ids.#": {Old: "0", New: "0", NewComputed: false, NewRemoved: false}, - "egress.2129912301.protocol": {Old: "tcp", New: "", NewComputed: false, NewRemoved: true}, - "egress.2129912301.security_groups.#": {Old: "0", New: "0", NewComputed: false, NewRemoved: false}, - "egress.2129912301.self": {Old: "false", New: "false", NewComputed: false, NewRemoved: true}, - "egress.2129912301.to_port": {Old: "8000", New: "0", NewComputed: false, NewRemoved: true}, - "egress.746197026.cidr_blocks.#": {Old: "", New: "1", NewComputed: false, NewRemoved: false}, - "egress.746197026.cidr_blocks.0": {Old: "", New: "10.0.0.0/8", NewComputed: false, NewRemoved: false}, - "egress.746197026.description": {Old: "", New: "New egress description", NewComputed: false, NewRemoved: false}, - "egress.746197026.from_port": {Old: "", New: "80", NewComputed: false, NewRemoved: false}, - "egress.746197026.ipv6_cidr_blocks.#": {Old: "", New: "0", NewComputed: false, NewRemoved: false}, - "egress.746197026.prefix_list_ids.#": {Old: "", New: "0", NewComputed: false, NewRemoved: false}, - "egress.746197026.protocol": {Old: "", New: "tcp", NewComputed: false, NewRemoved: false, NewExtra: "tcp"}, - "egress.746197026.security_groups.#": {Old: "", New: "0", NewComputed: false, NewRemoved: false}, - "egress.746197026.self": {Old: "", New: "false", NewComputed: false, NewRemoved: false}, - "egress.746197026.to_port": {Old: "", New: "8000", NewComputed: false, NewRemoved: false}, - // an erroneous nil diff should do nothing - "egress.111111111.to_port": nil, - }, - } - - resSchema := map[string]*schema.Schema{ - "egress": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - ConfigMode: schema.SchemaConfigModeAttr, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "from_port": { - Type: schema.TypeInt, - Required: true, - }, - - "to_port": { - Type: schema.TypeInt, - Required: true, - }, - - "protocol": { - Type: schema.TypeString, - Required: true, - }, - - "cidr_blocks": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - "ipv6_cidr_blocks": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - "prefix_list_ids": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "security_groups": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - "self": { - Type: schema.TypeBool, - Optional: true, - Default: false, - }, - - "description": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - } - - expected := map[string]string{ - "egress.#": "1", - "egress.746197026.cidr_blocks.#": "1", - "egress.746197026.cidr_blocks.0": "10.0.0.0/8", - "egress.746197026.description": "New egress description", - "egress.746197026.from_port": "80", "egress.746197026.ipv6_cidr_blocks.#": "0", - "egress.746197026.prefix_list_ids.#": "0", - "egress.746197026.protocol": "tcp", - "egress.746197026.security_groups.#": "0", - "egress.746197026.self": "false", - "egress.746197026.to_port": "8000", - "id": "testID", - } - - attrs, err := diff.Apply(priorAttrs, (&schema.Resource{Schema: resSchema}).CoreConfigSchema()) - if err != nil { - t.Fatal(err) - } - - if !reflect.DeepEqual(attrs, expected) { - t.Fatalf("wrong result\ngot: %s\nwant: %s\n", spew.Sdump(attrs), spew.Sdump(expected)) - } -} diff --git a/builtin/providers/test/provider_test.go b/builtin/providers/test/provider_test.go deleted file mode 100644 index 40defefac0..0000000000 --- a/builtin/providers/test/provider_test.go +++ /dev/null @@ -1,24 +0,0 @@ -package test - -import ( - "testing" - - "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/terraform" -) - -var testAccProviders map[string]terraform.ResourceProvider -var testAccProvider *schema.Provider - -func TestProvider(t *testing.T) { - if err := Provider().(*schema.Provider).InternalValidate(); err != nil { - t.Fatalf("err: %s", err) - } -} - -func init() { - testAccProvider = Provider().(*schema.Provider) - testAccProviders = map[string]terraform.ResourceProvider{ - "test": testAccProvider, - } -} diff --git a/builtin/providers/test/resource_computed_set_test.go b/builtin/providers/test/resource_computed_set_test.go deleted file mode 100644 index 06e6082350..0000000000 --- a/builtin/providers/test/resource_computed_set_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceComputedSet_update(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_computed_set" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_computed_set.foo", "string_set.#", "3", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_computed_set" "foo" { - set_count = 5 -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_computed_set.foo", "string_set.#", "5", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_computed_set" "foo" { - set_count = 2 -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_computed_set.foo", "string_set.#", "2", - ), - ), - }, - }, - }) -} - -func TestResourceComputedSet_ruleTest(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_computed_set" "foo" { - rule { - ip_protocol = "udp" - cidr = "0.0.0.0/0" - } -} - `), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_config_mode_test.go b/builtin/providers/test/resource_config_mode_test.go deleted file mode 100644 index f73adc8fff..0000000000 --- a/builtin/providers/test/resource_config_mode_test.go +++ /dev/null @@ -1,120 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceConfigMode(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_config_mode" "foo" { - resource_as_attr = [ - { - foo = "resource_as_attr 0" - }, - { - foo = "resource_as_attr 1" - }, - ] -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.#", "2"), - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.0.foo", "resource_as_attr 0"), - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.1.foo", "resource_as_attr 1"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_config_mode" "foo" { - # Due to a preprocessing fixup we do in lang.EvalBlock, it's allowed - # to specify resource_as_attr members using one or more nested blocks - # instead of attribute syntax, if desired. This should be equivalent - # to the previous config. - # - # This allowance is made for backward-compatibility with existing providers - # before Terraform v0.12 that were expecting nested block types to also - # support attribute syntax; it should not be used for any new use-cases. - resource_as_attr { - foo = "resource_as_attr 0" - } - resource_as_attr { - foo = "resource_as_attr 1" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.#", "2"), - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.0.foo", "resource_as_attr 0"), - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.1.foo", "resource_as_attr 1"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_config_mode" "foo" { - resource_as_attr = [ - { - foo = "resource_as_attr 0 updated" - }, - ] -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.#", "1"), - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.0.foo", "resource_as_attr 0 updated"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_config_mode" "foo" { - resource_as_attr = [] -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_config_mode.foo", "resource_as_attr.#", "0"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_config_mode" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckNoResourceAttr("test_resource_config_mode.foo", "resource_as_attr.#"), - ), - }, - }, - }) -} - -func TestResourceConfigMode_nestedSet(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_config_mode" "foo" { - resource_as_attr = [] - - nested_set { - value = "a" - } - nested_set { - value = "b" - set = [] - } -} - `), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_data_dep_test.go b/builtin/providers/test/resource_data_dep_test.go deleted file mode 100644 index 0cd773d533..0000000000 --- a/builtin/providers/test/resource_data_dep_test.go +++ /dev/null @@ -1,224 +0,0 @@ -package test - -import ( - "fmt" - "testing" - - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -// TestResourceDataDep_alignedCountScaleOut tests to make sure interpolation -// works (namely without index errors) when a data source and a resource share -// the same count variable during scale-out with an existing state. -func TestResourceDataDep_alignedCountScaleOut(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: testResourceDataDepConfig(2), - }, - { - Config: testResourceDataDepConfig(4), - Check: resource.TestCheckOutput("out", "value_from_api,value_from_api,value_from_api,value_from_api"), - }, - }, - }) -} - -// TestResourceDataDep_alignedCountScaleIn tests to make sure interpolation -// works (namely without index errors) when a data source and a resource share -// the same count variable during scale-in with an existing state. -func TestResourceDataDep_alignedCountScaleIn(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: testResourceDataDepConfig(4), - }, - { - Config: testResourceDataDepConfig(2), - Check: resource.TestCheckOutput("out", "value_from_api,value_from_api"), - }, - }, - }) -} - -// TestDataResourceDep_alignedCountScaleOut functions like -// TestResourceDataDep_alignedCountScaleOut, but with the dependencies swapped -// (resource now depends on data source, a pretty regular use case, but -// included here to check for regressions). -func TestDataResourceDep_alignedCountScaleOut(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: testDataResourceDepConfig(2), - }, - { - Config: testDataResourceDepConfig(4), - Check: resource.TestCheckOutput("out", "test,test,test,test"), - }, - }, - }) -} - -// TestDataResourceDep_alignedCountScaleIn functions like -// TestResourceDataDep_alignedCountScaleIn, but with the dependencies swapped -// (resource now depends on data source, a pretty regular use case, but -// included here to check for regressions). -func TestDataResourceDep_alignedCountScaleIn(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: testDataResourceDepConfig(4), - }, - { - Config: testDataResourceDepConfig(2), - Check: resource.TestCheckOutput("out", "test,test"), - }, - }, - }) -} - -// TestResourceResourceDep_alignedCountScaleOut functions like -// TestResourceDataDep_alignedCountScaleOut, but with a resource-to-resource -// dependency instead, a pretty regular use case, but included here to check -// for regressions. -func TestResourceResourceDep_alignedCountScaleOut(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: testResourceResourceDepConfig(2), - }, - { - Config: testResourceResourceDepConfig(4), - Check: resource.TestCheckOutput("out", "test,test,test,test"), - }, - }, - }) -} - -// TestResourceResourceDep_alignedCountScaleIn functions like -// TestResourceDataDep_alignedCountScaleIn, but with a resource-to-resource -// dependency instead, a pretty regular use case, but included here to check -// for regressions. -func TestResourceResourceDep_alignedCountScaleIn(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: func(s *terraform.State) error { - return nil - }, - Steps: []resource.TestStep{ - { - Config: testResourceResourceDepConfig(4), - }, - { - Config: testResourceResourceDepConfig(2), - Check: resource.TestCheckOutput("out", "test,test"), - }, - }, - }) -} - -func testResourceDataDepConfig(count int) string { - return fmt.Sprintf(` -variable num { - default = "%d" -} - -resource "test_resource" "foo" { - count = "${var.num}" - required = "yes" - - required_map = { - "foo" = "bar" - } -} - -data "test_data_source" "bar" { - count = "${var.num}" - input = "${test_resource.foo.*.computed_read_only[count.index]}" -} - -output "out" { - value = "${join(",", data.test_data_source.bar.*.output)}" -} -`, count) -} - -func testDataResourceDepConfig(count int) string { - return fmt.Sprintf(` -variable num { - default = "%d" -} - -data "test_data_source" "foo" { - count = "${var.num}" - input = "test" -} - -resource "test_resource" "bar" { - count = "${var.num}" - required = "yes" - optional = "${data.test_data_source.foo.*.output[count.index]}" - - required_map = { - "foo" = "bar" - } -} - -output "out" { - value = "${join(",", test_resource.bar.*.optional)}" -} -`, count) -} - -func testResourceResourceDepConfig(count int) string { - return fmt.Sprintf(` -variable num { - default = "%d" -} - -resource "test_resource" "foo" { - count = "${var.num}" - required = "yes" - optional = "test" - - required_map = { - "foo" = "bar" - } -} - -resource "test_resource" "bar" { - count = "${var.num}" - required = "yes" - optional = "${test_resource.foo.*.optional[count.index]}" - - required_map = { - "foo" = "bar" - } -} - -output "out" { - value = "${join(",", test_resource.bar.*.optional)}" -} -`, count) -} diff --git a/builtin/providers/test/resource_dataproc_cluster_test.go b/builtin/providers/test/resource_dataproc_cluster_test.go deleted file mode 100644 index 3d5a2282f2..0000000000 --- a/builtin/providers/test/resource_dataproc_cluster_test.go +++ /dev/null @@ -1,491 +0,0 @@ -package test - -import ( - "reflect" - "testing" - - "github.com/google/go-cmp/cmp" - - "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/terraform" -) - -var dataprocClusterSchema = map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "project": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "region": { - Type: schema.TypeString, - Optional: true, - Default: "global", - ForceNew: true, - }, - - "labels": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - // GCP automatically adds two labels - // 'goog-dataproc-cluster-uuid' - // 'goog-dataproc-cluster-name' - Computed: true, - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - if old != "" { - return true - } - return false - }, - }, - - "tag_set": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - - "cluster_config": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - - "delete_autogen_bucket": { - Type: schema.TypeBool, - Optional: true, - Default: false, - Removed: "If you need a bucket that can be deleted, please create" + - "a new one and set the `staging_bucket` field", - }, - - "staging_bucket": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "bucket": { - Type: schema.TypeString, - Computed: true, - }, - - "gce_cluster_config": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - - "zone": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "network": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - ConflictsWith: []string{"cluster_config.0.gce_cluster_config.0.subnetwork"}, - }, - - "subnetwork": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - ConflictsWith: []string{"cluster_config.0.gce_cluster_config.0.network"}, - }, - - "tags": { - Type: schema.TypeSet, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "service_account": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - - "service_account_scopes": { - Type: schema.TypeSet, - Optional: true, - Computed: true, - ForceNew: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - - "internal_ip_only": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - Default: false, - }, - - "metadata": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - ForceNew: true, - }, - }, - }, - }, - - "master_config": &schema.Schema{ - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "num_instances": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - - "image_uri": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "machine_type": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "disk_config": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "num_local_ssds": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "boot_disk_size_gb": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "boot_disk_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: "pd-standard", - }, - }, - }, - }, - "accelerators": { - Type: schema.TypeSet, - Optional: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "accelerator_type": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "accelerator_count": { - Type: schema.TypeInt, - Required: true, - ForceNew: true, - }, - }, - }, - }, - "instance_names": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - "preemptible_worker_config": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "num_instances": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - }, - "disk_config": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "num_local_ssds": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "boot_disk_size_gb": { - Type: schema.TypeInt, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "boot_disk_type": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - Default: "pd-standard", - }, - }, - }, - }, - - "instance_names": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - - "software_config": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "image_version": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - - "override_properties": { - Type: schema.TypeMap, - Optional: true, - ForceNew: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "properties": { - Type: schema.TypeMap, - Computed: true, - }, - }, - }, - }, - - "initialization_action": { - Type: schema.TypeList, - Optional: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "script": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - - "timeout_sec": { - Type: schema.TypeInt, - Optional: true, - Default: 300, - ForceNew: true, - }, - }, - }, - }, - "encryption_config": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "kms_key_name": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - }, - }, - }, -} - -func TestDiffApply_dataprocCluster(t *testing.T) { - priorAttrs := map[string]string{ - "cluster_config.#": "1", - "cluster_config.0.bucket": "dataproc-1dc18cb2-116e-4e92-85ea-ff63a1bf2745-us-central1", - "cluster_config.0.delete_autogen_bucket": "false", - "cluster_config.0.encryption_config.#": "0", - "cluster_config.0.gce_cluster_config.#": "1", - "cluster_config.0.gce_cluster_config.0.internal_ip_only": "false", - "cluster_config.0.gce_cluster_config.0.metadata.%": "0", - "cluster_config.0.gce_cluster_config.0.network": "https://www.googleapis.com/compute/v1/projects/hc-terraform-testing/global/networks/default", - "cluster_config.0.gce_cluster_config.0.service_account": "", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.#": "7", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.1245378569": "https://www.googleapis.com/auth/bigtable.admin.table", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.1328717722": "https://www.googleapis.com/auth/devstorage.read_write", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.1693978638": "https://www.googleapis.com/auth/devstorage.full_control", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.172152165": "https://www.googleapis.com/auth/logging.write", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.2401844655": "https://www.googleapis.com/auth/bigquery", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.299921284": "https://www.googleapis.com/auth/bigtable.data", - "cluster_config.0.gce_cluster_config.0.service_account_scopes.3804780973": "https://www.googleapis.com/auth/cloud.useraccounts.readonly", - "cluster_config.0.gce_cluster_config.0.subnetwork": "", - "cluster_config.0.gce_cluster_config.0.tags.#": "0", - "cluster_config.0.gce_cluster_config.0.zone": "us-central1-f", - "cluster_config.0.initialization_action.#": "0", - "cluster_config.0.master_config.#": "1", - "cluster_config.0.master_config.0.accelerators.#": "0", - "cluster_config.0.master_config.0.disk_config.#": "1", - "cluster_config.0.master_config.0.disk_config.0.boot_disk_size_gb": "500", - "cluster_config.0.master_config.0.disk_config.0.boot_disk_type": "pd-standard", - "cluster_config.0.master_config.0.disk_config.0.num_local_ssds": "0", - "cluster_config.0.master_config.0.image_uri": "https://www.googleapis.com/compute/v1/projects/cloud-dataproc/global/images/dataproc-1-3-deb9-20190228-000000-rc01", - "cluster_config.0.master_config.0.instance_names.#": "1", - "cluster_config.0.master_config.0.instance_names.0": "dproc-cluster-test-2ww3c60iww-m", - "cluster_config.0.master_config.0.machine_type": "n1-standard-4", - "cluster_config.0.master_config.0.num_instances": "1", - "cluster_config.0.preemptible_worker_config.#": "1", - "cluster_config.0.preemptible_worker_config.0.disk_config.#": "1", - "cluster_config.0.preemptible_worker_config.0.instance_names.#": "0", - "cluster_config.0.preemptible_worker_config.0.num_instances": "0", - "cluster_config.0.software_config.#": "1", - "cluster_config.0.software_config.0.image_version": "1.3.28-deb9", - "cluster_config.0.software_config.0.override_properties.%": "0", - "cluster_config.0.software_config.0.properties.%": "14", - "cluster_config.0.software_config.0.properties.capacity-scheduler:yarn.scheduler.capacity.root.default.ordering-policy": "fair", - "cluster_config.0.software_config.0.properties.core:fs.gs.block.size": "134217728", - "cluster_config.0.software_config.0.properties.core:fs.gs.metadata.cache.enable": "false", - "cluster_config.0.software_config.0.properties.core:hadoop.ssl.enabled.protocols": "TLSv1,TLSv1.1,TLSv1.2", - "cluster_config.0.software_config.0.properties.distcp:mapreduce.map.java.opts": "-Xmx768m", - "cluster_config.0.software_config.0.properties.distcp:mapreduce.map.memory.mb": "1024", - "cluster_config.0.software_config.0.properties.distcp:mapreduce.reduce.java.opts": "-Xmx768m", - "cluster_config.0.software_config.0.properties.distcp:mapreduce.reduce.memory.mb": "1024", - "cluster_config.0.software_config.0.properties.hdfs:dfs.datanode.address": "0.0.0.0:9866", - "cluster_config.0.software_config.0.properties.hdfs:dfs.datanode.http.address": "0.0.0.0:9864", - "cluster_config.0.software_config.0.properties.hdfs:dfs.datanode.https.address": "0.0.0.0:9865", - "cluster_config.0.software_config.0.properties.hdfs:dfs.datanode.ipc.address": "0.0.0.0:9867", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.handler.count": "20", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.http-address": "0.0.0.0:9870", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.https-address": "0.0.0.0:9871", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.lifeline.rpc-address": "dproc-cluster-test-2ww3c60iww-m:8050", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.secondary.http-address": "0.0.0.0:9868", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.secondary.https-address": "0.0.0.0:9869", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.service.handler.count": "10", - "cluster_config.0.software_config.0.properties.hdfs:dfs.namenode.servicerpc-address": "dproc-cluster-test-2ww3c60iww-m:8051", - "cluster_config.0.software_config.0.properties.mapred-env:HADOOP_JOB_HISTORYSERVER_HEAPSIZE": "3840", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.job.maps": "21", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.job.reduce.slowstart.completedmaps": "0.95", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.job.reduces": "7", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.map.cpu.vcores": "1", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.map.java.opts": "-Xmx2457m", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.map.memory.mb": "3072", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.reduce.cpu.vcores": "1", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.reduce.java.opts": "-Xmx2457m", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.reduce.memory.mb": "3072", - "cluster_config.0.software_config.0.properties.mapred:mapreduce.task.io.sort.mb": "256", - "cluster_config.0.software_config.0.properties.mapred:yarn.app.mapreduce.am.command-opts": "-Xmx2457m", - "cluster_config.0.software_config.0.properties.mapred:yarn.app.mapreduce.am.resource.cpu-vcores": "1", - "cluster_config.0.software_config.0.properties.mapred:yarn.app.mapreduce.am.resource.mb": "3072", - "cluster_config.0.software_config.0.properties.presto-jvm:MaxHeapSize": "12288m", - "cluster_config.0.software_config.0.properties.presto:query.max-memory-per-node": "7372MB", - "cluster_config.0.software_config.0.properties.presto:query.max-total-memory-per-node": "7372MB", - "cluster_config.0.software_config.0.properties.spark-env:SPARK_DAEMON_MEMORY": "3840m", - "cluster_config.0.software_config.0.properties.spark:spark.driver.maxResultSize": "1920m", - "cluster_config.0.software_config.0.properties.spark:spark.driver.memory": "3840m", - "cluster_config.0.software_config.0.properties.spark:spark.executor.cores": "2", - "cluster_config.0.software_config.0.properties.spark:spark.executor.instances": "2", - "cluster_config.0.software_config.0.properties.spark:spark.executor.memory": "5586m", - "cluster_config.0.software_config.0.properties.spark:spark.executorEnv.OPENBLAS_NUM_THREADS": "1", - "cluster_config.0.software_config.0.properties.spark:spark.scheduler.mode": "FAIR", - "cluster_config.0.software_config.0.properties.spark:spark.sql.cbo.enabled": "true", - "cluster_config.0.software_config.0.properties.spark:spark.yarn.am.memory": "640m", - "cluster_config.0.software_config.0.properties.yarn-env:YARN_TIMELINESERVER_HEAPSIZE": "3840", - "cluster_config.0.software_config.0.properties.yarn:yarn.nodemanager.resource.memory-mb": "12288", - "cluster_config.0.software_config.0.properties.yarn:yarn.resourcemanager.nodemanager-graceful-decommission-timeout-secs": "86400", - "cluster_config.0.software_config.0.properties.yarn:yarn.scheduler.maximum-allocation-mb": "12288", - "cluster_config.0.software_config.0.properties.yarn:yarn.scheduler.minimum-allocation-mb": "1024", - "cluster_config.0.staging_bucket": "", - "id": "dproc-cluster-test-ktbyrniu4e", - "labels.%": "4", - "labels.goog-dataproc-cluster-name": "dproc-cluster-test-ktbyrniu4e", - "labels.goog-dataproc-cluster-uuid": "d576c4e0-8fda-4ad1-abf5-ec951ab25855", - "labels.goog-dataproc-location": "us-central1", - "labels.key1": "value1", - "tag_set.#": "0", - } - - diff := &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{ - "labels.%": &terraform.ResourceAttrDiff{Old: "4", New: "1", NewComputed: false, NewRemoved: false, NewExtra: interface{}(nil), RequiresNew: false, Sensitive: false, Type: 0x0}, - "labels.goog-dataproc-cluster-name": &terraform.ResourceAttrDiff{Old: "dproc-cluster-test-ktbyrniu4e", New: "", NewComputed: false, NewRemoved: true, NewExtra: interface{}(nil), RequiresNew: false, Sensitive: false, Type: 0x0}, - "labels.goog-dataproc-cluster-uuid": &terraform.ResourceAttrDiff{Old: "d576c4e0-8fda-4ad1-abf5-ec951ab25855", New: "", NewComputed: false, NewRemoved: true, NewExtra: interface{}(nil), RequiresNew: false, Sensitive: false, Type: 0x0}, - "labels.goog-dataproc-location": &terraform.ResourceAttrDiff{Old: "us-central1", New: "", NewComputed: false, NewRemoved: true, NewExtra: interface{}(nil), RequiresNew: false, Sensitive: false, Type: 0x0}, - }, - } - - newAttrs, err := diff.Apply(priorAttrs, (&schema.Resource{Schema: dataprocClusterSchema}).CoreConfigSchema()) - if err != nil { - t.Fatal(err) - } - - // the diff'ed labale elements should be removed - delete(priorAttrs, "labels.goog-dataproc-cluster-name") - delete(priorAttrs, "labels.goog-dataproc-cluster-uuid") - delete(priorAttrs, "labels.goog-dataproc-location") - priorAttrs["labels.%"] = "1" - - // the missing required "name" should be added - priorAttrs["name"] = "" - - if !reflect.DeepEqual(priorAttrs, newAttrs) { - t.Fatal(cmp.Diff(priorAttrs, newAttrs)) - } -} diff --git a/builtin/providers/test/resource_defaults_test.go b/builtin/providers/test/resource_defaults_test.go deleted file mode 100644 index 8aabd44825..0000000000 --- a/builtin/providers/test/resource_defaults_test.go +++ /dev/null @@ -1,168 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceDefaults_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_defaults" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_string", "default string", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_bool", "1", - ), - resource.TestCheckNoResourceAttr( - "test_resource_defaults.foo", "nested.#", - ), - ), - }, - }, - }) -} - -func TestResourceDefaults_change(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -resource "test_resource_defaults" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_string", "default string", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_bool", "1", - ), - resource.TestCheckNoResourceAttr( - "test_resource_defaults.foo", "nested.#", - ), - ), - }, - { - Config: strings.TrimSpace(` -resource "test_resource_defaults" "foo" { - default_string = "new" - default_bool = false - nested { - optional = "nested" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_string", "new", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_bool", "false", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.2950978312.optional", "nested", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.2950978312.string", "default nested", - ), - ), - }, - { - Config: strings.TrimSpace(` -resource "test_resource_defaults" "foo" { - default_string = "new" - default_bool = false - nested { - optional = "nested" - string = "new" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_string", "new", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_bool", "false", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.782850362.optional", "nested", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.782850362.string", "new", - ), - ), - }, - }, - }) -} - -func TestResourceDefaults_inSet(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_defaults" "foo" { - nested { - optional = "val" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_string", "default string", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "default_bool", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.2826070548.optional", "val", - ), - resource.TestCheckResourceAttr( - "test_resource_defaults.foo", "nested.2826070548.string", "default nested", - ), - ), - }, - }, - }) -} - -func TestDefaults_emptyString(t *testing.T) { - config := ` -resource "test_resource_defaults" "test" { - default_string = "" -} -` - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: config, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_defaults.test", "default_string", ""), - ), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_deprecated_test.go b/builtin/providers/test/resource_deprecated_test.go deleted file mode 100644 index 8817567d98..0000000000 --- a/builtin/providers/test/resource_deprecated_test.go +++ /dev/null @@ -1,71 +0,0 @@ -package test - -import ( - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -// an empty config should be ok, because no deprecated/removed fields are set. -func TestResourceDeprecated_empty(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_deprecated" "foo" { -} - `), - }, - }, - }) -} - -// Deprecated fields should still work -func TestResourceDeprecated_deprecatedOK(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_deprecated" "foo" { - map_deprecated = { - "a" = "b", - } - set_block_deprecated { - value = "1" - } - list_block_deprecated { - value = "2" - } -} - `), - }, - }, - }) -} - -// Declaring an empty block should trigger the error -func TestResourceDeprecated_removedBlocks(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_deprecated" "foo" { - set_block_removed { - } - list_block_removed { - } -} - `), - ExpectError: regexp.MustCompile("REMOVED"), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_diff_suppress_test.go b/builtin/providers/test/resource_diff_suppress_test.go deleted file mode 100644 index 89416f32a1..0000000000 --- a/builtin/providers/test/resource_diff_suppress_test.go +++ /dev/null @@ -1,126 +0,0 @@ -package test - -import ( - "errors" - "strings" - "testing" - - "github.com/hashicorp/terraform/addrs" - - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestResourceDiffSuppress_create(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_diff_suppress" "foo" { - val_to_upper = "foo" -} - `), - }, - }, - }) -} -func TestResourceDiffSuppress_update(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_diff_suppress" "foo" { - val_to_upper = "foo" -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_diff_suppress" "foo" { - val_to_upper = "bar" - optional = "more" -} - `), - }, - }, - }) -} - -func TestResourceDiffSuppress_updateIgnoreChanges(t *testing.T) { - // None of these steps should replace the instance - id := "" - checkFunc := func(s *terraform.State) error { - root := s.ModuleByPath(addrs.RootModuleInstance) - res := root.Resources["test_resource_diff_suppress.foo"] - if id != "" && res.Primary.ID != id { - return errors.New("expected no resource replacement") - } - id = res.Primary.ID - return nil - } - - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_diff_suppress" "foo" { - val_to_upper = "foo" - - network = "foo" - subnetwork = "foo" - - node_pool { - name = "default-pool" - } - lifecycle { - ignore_changes = ["node_pool"] - } -} - `), - Check: checkFunc, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_diff_suppress" "foo" { - val_to_upper = "foo" - - network = "ignored" - subnetwork = "ignored" - - node_pool { - name = "default-pool" - } - lifecycle { - ignore_changes = ["node_pool"] - } -} - `), - Check: checkFunc, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_diff_suppress" "foo" { - val_to_upper = "foo" - - network = "ignored" - subnetwork = "ignored" - - node_pool { - name = "ignored" - } - lifecycle { - ignore_changes = ["node_pool"] - } -} - `), - Check: checkFunc, - }, - }, - }) -} diff --git a/builtin/providers/test/resource_force_new_test.go b/builtin/providers/test/resource_force_new_test.go deleted file mode 100644 index 3e0bf19c34..0000000000 --- a/builtin/providers/test/resource_force_new_test.go +++ /dev/null @@ -1,79 +0,0 @@ -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_gh12183_test.go b/builtin/providers/test/resource_gh12183_test.go deleted file mode 100644 index 9cf100587c..0000000000 --- a/builtin/providers/test/resource_gh12183_test.go +++ /dev/null @@ -1,40 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -// Tests GH-12183. This would previously cause a crash. More granular -// unit tests are scattered through helper/schema and terraform core for -// this. -func TestResourceGH12183_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_gh12183" "a" { - config { - name = "hello" - } -} - -resource "test_resource_gh12183" "b" { - key = "${lookup(test_resource_gh12183.a.config[0], "name")}" - config { - name = "required" - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} diff --git a/builtin/providers/test/resource_list_set_test.go b/builtin/providers/test/resource_list_set_test.go deleted file mode 100644 index f1e8353fb1..0000000000 --- a/builtin/providers/test/resource_list_set_test.go +++ /dev/null @@ -1,118 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceListSet_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list_set" "foo" { - list { - set { - elem = "A" - } - set { - elem = "B" - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list_set.foo", "list.0.set.1255198513.elem", "B"), - resource.TestCheckResourceAttr("test_resource_list_set.foo", "list.0.set.3554254475.elem", "A"), - resource.TestCheckResourceAttr("test_resource_list_set.foo", "list.0.set.#", "2"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list_set" "foo" { - list { - set { - elem = "B" - } - set { - elem = "C" - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list_set.foo", "list.0.set.1255198513.elem", "B"), - resource.TestCheckResourceAttr("test_resource_list_set.foo", "list.0.set.1037565863.elem", "C"), - resource.TestCheckResourceAttr("test_resource_list_set.foo", "list.0.set.#", "2"), - ), - }, - }, - }) -} - -func TestResourceListSet_updateNested(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list_set" "foo" { - replication_configuration { - role = "role_id" - rules { - id = "foobar" - status = "Enabled" - priority = 42 - filter { - tags = { - ReplicateMe = "Yes" - } - } - destination { - bucket = "bucket_id" - storage_class = "STANDARD" - } - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list_set.foo", "replication_configuration.0.rules.#", "1"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list_set" "foo" { - replication_configuration { - role = "role_id" - rules { - id = "foobar" - status = "Enabled" - priority = 42 - filter { - prefix = "foo" - tags = { - ReplicateMe = "Yes" - AnotherTag = "OK" - } - } - destination { - bucket = "bucket_id" - storage_class = "STANDARD" - } - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list_set.foo", "replication_configuration.0.rules.#", "1"), - ), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_list_test.go b/builtin/providers/test/resource_list_test.go deleted file mode 100644 index 876a81fd53..0000000000 --- a/builtin/providers/test/resource_list_test.go +++ /dev/null @@ -1,566 +0,0 @@ -package test - -import ( - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -// an empty config should be ok, because no deprecated/removed fields are set. -func TestResourceList_changed(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - string = "a" - int = 1 - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.string", "a", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.int", "1", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - string = "a" - int = 1 - } - - list_block { - string = "b" - int = 2 - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.#", "2", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.string", "a", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.int", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.1.string", "b", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.1.int", "2", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - string = "a" - int = 1 - } - - list_block { - string = "c" - int = 2 - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.#", "2", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.string", "a", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.int", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.1.string", "c", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.1.int", "2", - ), - ), - }, - }, - }) -} - -func TestResourceList_mapList(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -variable "map" { - type = map(string) - default = {} -} - -resource "test_resource_list" "foo" { - map_list = [ - { - a = "1" - }, - var.map - ] -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.foo", "map_list.1", "", - ), - ), - }, - }, - }) -} - -func TestResourceList_sublist(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - sublist_block { - string = "a" - int = 1 - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.sublist_block.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.sublist_block.0.string", "a", - ), - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.sublist_block.0.int", "1", - ), - ), - }, - }, - }) -} - -func TestResourceList_interpolationChanges(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - string = "x" - } -} -resource "test_resource_list" "bar" { - list_block { - string = test_resource_list.foo.id - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.string", "x", - ), - resource.TestCheckResourceAttr( - "test_resource_list.bar", "list_block.0.string", "testId", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "baz" { - list_block { - string = "x" - int = 1 - } -} -resource "test_resource_list" "bar" { - list_block { - string = test_resource_list.baz.id - int = 3 - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.baz", "list_block.0.string", "x", - ), - resource.TestCheckResourceAttr( - "test_resource_list.bar", "list_block.0.string", "testId", - ), - ), - }, - }, - }) -} - -func TestResourceList_removedForcesNew(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - force_new = "ok" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.foo", "list_block.0.force_new", "ok", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} - -func TestResourceList_emptyStrings(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - sublist = ["a", ""] - } - - list_block { - sublist = [""] - } - - list_block { - sublist = ["", "c", ""] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.0.sublist.0", "a"), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.0.sublist.1", ""), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.1.sublist.0", ""), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.2.sublist.0", ""), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.2.sublist.1", "c"), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.2.sublist.2", ""), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - sublist = [""] - } - - list_block { - sublist = [] - } - - list_block { - sublist = ["", "c"] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.0.sublist.#", "1"), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.0.sublist.0", ""), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.1.sublist.#", "0"), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.2.sublist.1", "c"), - resource.TestCheckResourceAttr("test_resource_list.foo", "list_block.2.sublist.#", "2"), - ), - }, - }, - }) -} - -func TestResourceList_addRemove(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list.foo", "computed_list.#", "0"), - resource.TestCheckResourceAttr("test_resource_list.foo", "dependent_list.#", "0"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - dependent_list { - val = "a" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list.foo", "computed_list.#", "1"), - resource.TestCheckResourceAttr("test_resource_list.foo", "dependent_list.#", "1"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_list.foo", "computed_list.#", "0"), - resource.TestCheckResourceAttr("test_resource_list.foo", "dependent_list.#", "0"), - ), - }, - }, - }) -} - -func TestResourceList_planUnknownInterpolation(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - string = "x" - } -} -resource "test_resource_list" "bar" { - list_block { - sublist = [ - test_resource_list.foo.list_block[0].string, - ] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.bar", "list_block.0.sublist.0", "x", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - string = "x" - } - dependent_list { - val = "y" - } -} -resource "test_resource_list" "bar" { - list_block { - sublist = [ - test_resource_list.foo.computed_list[0], - ] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.bar", "list_block.0.sublist.0", "y", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - list_block { - string = "x" - } - dependent_list { - val = "z" - } -} -resource "test_resource_list" "bar" { - list_block { - sublist = [ - test_resource_list.foo.computed_list[0], - ] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.bar", "list_block.0.sublist.0", "z", - ), - ), - }, - }, - }) -} - -func TestResourceList_planUnknownInterpolationList(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - dependent_list { - val = "y" - } -} -resource "test_resource_list" "bar" { - list_block { - sublist_block_optional { - list = test_resource_list.foo.computed_list - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.bar", "list_block.0.sublist_block_optional.0.list.0", "y", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "foo" { - dependent_list { - val = "z" - } -} -resource "test_resource_list" "bar" { - list_block { - sublist_block_optional { - list = test_resource_list.foo.computed_list - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_list.bar", "list_block.0.sublist_block_optional.0.list.0", "z", - ), - ), - }, - }, - }) -} - -func TestResourceList_dynamicList(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "a" { - dependent_list { - val = "a" - } - - dependent_list { - val = "b" - } -} -resource "test_resource_list" "b" { - list_block { - string = "constant" - } - dynamic "list_block" { - for_each = test_resource_list.a.computed_list - content { - string = list_block.value - } - } -} - `), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} - -func TestResourceList_dynamicMinItems(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -variable "a" { - type = list(number) - default = [1] -} - -resource "test_resource_list" "b" { - dynamic "min_items" { - for_each = var.a - content { - val = "foo" - } - } -} - `), - ExpectError: regexp.MustCompile(`attribute supports 2`), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "a" { - dependent_list { - val = "a" - } - - dependent_list { - val = "b" - } -} -resource "test_resource_list" "b" { - list_block { - string = "constant" - } - dynamic "min_items" { - for_each = test_resource_list.a.computed_list - content { - val = min_items.value - } - } -} - `), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_map_test.go b/builtin/providers/test/resource_map_test.go deleted file mode 100644 index 0d82d5f4f2..0000000000 --- a/builtin/providers/test/resource_map_test.go +++ /dev/null @@ -1,138 +0,0 @@ -package test - -import ( - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceMap_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - { - Config: ` -resource "test_resource_map" "foobar" { - name = "test" - map_of_three = { - one = "one" - two = "two" - empty = "" - } -}`, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_map.foobar", "map_of_three.empty", "", - ), - ), - }, - }, - }) -} - -func TestResourceMap_basicWithVars(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - { - Config: ` -variable "a" { - default = "a" -} - -variable "b" { - default = "b" -} - -resource "test_resource_map" "foobar" { - name = "test" - map_of_three = { - one = var.a - two = var.b - empty = "" - } -}`, - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} - -func TestResourceMap_computedMap(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - { - Config: ` -resource "test_resource_map" "foobar" { - name = "test" - map_of_three = { - one = "one" - two = "two" - empty = "" - } - map_values = { - a = "1" - b = "2" - } -}`, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_map.foobar", "computed_map.a", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_map.foobar", "computed_map.b", "2", - ), - ), - }, - { - Config: ` -resource "test_resource_map" "foobar" { - name = "test" - map_of_three = { - one = "one" - two = "two" - empty = "" - } - map_values = { - a = "3" - b = "4" - } -}`, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_map.foobar", "computed_map.a", "3", - ), - resource.TestCheckResourceAttr( - "test_resource_map.foobar", "computed_map.b", "4", - ), - ), - }, - { - Config: ` -resource "test_resource_map" "foobar" { - name = "test" - map_of_three = { - one = "one" - two = "two" - empty = "" - } - map_values = { - a = "3" - } -}`, - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_map.foobar", "computed_map.a", "3", - ), - resource.TestCheckNoResourceAttr( - "test_resource_map.foobar", "computed_map.b", - ), - ), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_nested_id_test.go b/builtin/providers/test/resource_nested_id_test.go deleted file mode 100644 index 9ca7a24684..0000000000 --- a/builtin/providers/test/resource_nested_id_test.go +++ /dev/null @@ -1,31 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceNestedId_unknownId(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_id" "foo" { -} -resource "test_resource_nested_id" "bar" { - list_block { - id = test_resource_nested_id.foo.id - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_nested_id.bar", "list_block.0.id", "testId"), - ), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_nested_set_test.go b/builtin/providers/test/resource_nested_set_test.go deleted file mode 100644 index dddce0e810..0000000000 --- a/builtin/providers/test/resource_nested_set_test.go +++ /dev/null @@ -1,653 +0,0 @@ -package test - -import ( - "errors" - "fmt" - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform/addrs" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestResourceNestedSet_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "bar" - } -} - `), - }, - }, - }) -} - -func TestResourceNestedSet_basicImport(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "bar" - } -} - `), - }, - resource.TestStep{ - ImportState: true, - ResourceName: "test_resource_nested_set.foo", - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "bar" - } -} - `), - ImportStateCheck: func(ss []*terraform.InstanceState) error { - for _, s := range ss { - if s.Attributes["multi.#"] != "0" || - s.Attributes["single.#"] != "0" || - s.Attributes["type_list.#"] != "0" || - s.Attributes["with_list.#"] != "0" { - return fmt.Errorf("missing blocks in imported state:\n%s", s) - } - } - return nil - }, - }, - }, - }) -} - -// The set should not be generated because of it's computed value -func TestResourceNestedSet_noSet(t *testing.T) { - checkFunc := func(s *terraform.State) error { - root := s.ModuleByPath(addrs.RootModuleInstance) - res := root.Resources["test_resource_nested_set.foo"] - for k, v := range res.Primary.Attributes { - if strings.HasPrefix(k, "single") && k != "single.#" { - return fmt.Errorf("unexpected set value: %s:%s", k, v) - } - } - 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" { -} - `), - Check: checkFunc, - }, - }, - }) -} - -// the empty type_list must be passed to the provider with 1 nil element -func TestResourceNestedSet_emptyBlock(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - type_list { - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_nested_set.foo", "type_list.#", "1"), - ), - }, - }, - }) -} - -func TestResourceNestedSet_emptyNestedListBlock(t *testing.T) { - checkFunc := func(s *terraform.State) error { - root := s.ModuleByPath(addrs.RootModuleInstance) - res := root.Resources["test_resource_nested_set.foo"] - found := false - for k := range res.Primary.Attributes { - if !regexp.MustCompile(`^with_list\.\d+\.list_block\.`).MatchString(k) { - continue - } - found = true - } - if !found { - return fmt.Errorf("with_list.X.list_block not found") - } - 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" { - with_list { - required = "ok" - list_block { - } - } -} - `), - Check: checkFunc, - }, - }, - }) -} -func TestResourceNestedSet_emptyNestedList(t *testing.T) { - checkFunc := func(s *terraform.State) error { - root := s.ModuleByPath(addrs.RootModuleInstance) - res := root.Resources["test_resource_nested_set.foo"] - found := false - for k, v := range res.Primary.Attributes { - if regexp.MustCompile(`^with_list\.\d+\.list\.#$`).MatchString(k) { - found = true - if v != "0" { - return fmt.Errorf("expected empty list: %s, got %s", k, v) - } - break - } - } - if !found { - return fmt.Errorf("with_list.X.nested_list not found") - } - 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" { - with_list { - required = "ok" - list = [] - } -} - `), - Check: checkFunc, - }, - }, - }) -} - -func TestResourceNestedSet_addRemove(t *testing.T) { - var id string - checkFunc := func(s *terraform.State) error { - root := s.ModuleByPath(addrs.RootModuleInstance) - res := root.Resources["test_resource_nested_set.foo"] - if res.Primary.ID == id { - return errors.New("expected new resource") - } - id = res.Primary.ID - 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" { -} - `), - Check: checkFunc, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "bar" - } -} - `), - Check: resource.ComposeTestCheckFunc( - checkFunc, - resource.TestCheckResourceAttr( - "test_resource_nested_set.foo", "single.#", "1", - ), - // the hash of single seems to change here, so we're not - // going to test for "value" directly - // FIXME: figure out why the set hash changes - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_nested_set.foo", "single.#", "0", - ), - checkFunc, - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "bar" - } -} - `), - Check: checkFunc, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "bar" - optional = "baz" - } -} - `), - Check: checkFunc, - }, - - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { -} - `), - Check: checkFunc, - }, - }, - }) -} -func TestResourceNestedSet_multiAddRemove(t *testing.T) { - checkFunc := func(s *terraform.State) error { - 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" { -} - `), - Check: checkFunc, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - multi { - optional = "bar" - } -} - `), - Check: checkFunc, - }, - - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { -} - `), - Check: checkFunc, - }, - - 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 = "new" - } - } -} - `), - Check: checkFunc, - }, - - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - multi { - set { - required = "new" - optional_int = 3 - } - } -} - `), - Check: checkFunc, - }, - - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "bar" - optional = "baz" - } - multi { - set { - required = "new" - 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, - }, - }, - }) -} - -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, - }, - }, - }) -} - -func TestResourceNestedSet_setWithList(t *testing.T) { - checkFunc := func(s *terraform.State) error { - 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" { - with_list { - required = "bar" - list = ["initial value"] - } -} - `), - Check: checkFunc, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - with_list { - required = "bar" - list = ["second value"] - } -} - `), - Check: checkFunc, - }, - }, - }) -} - -// This is the same as forceNewEmptyString, but we start with the empty value, -// instead of changing it. -func TestResourceNestedSet_nestedSetEmptyString(t *testing.T) { - 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 = "" - } - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_nested_set.foo", "multi.529860700.set.4196279896.required", "", - ), - ), - }, - }, - }) -} - -func TestResourceNestedSet_emptySet(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - multi { - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_nested_set.foo", "multi.#", "1", - ), - ), - }, - }, - }) -} - -func TestResourceNestedSet_multipleUnknownSetElements(t *testing.T) { - checkFunc := func(s *terraform.State) error { - return nil - } - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "a" { -} - -resource "test_resource_nested_set" "b" { -} - -resource "test_resource_nested_set" "c" { - multi { - optional = test_resource_nested_set.a.id - } - multi { - optional = test_resource_nested_set.b.id - } -} - `), - Check: checkFunc, - }, - }, - }) -} - -func TestResourceNestedSet_interpolationChanges(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "foo" { - single { - value = "x" - } -} -resource "test_resource_nested_set" "bar" { - single { - value = test_resource_nested_set.foo.id - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_nested_set.foo", "single.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_nested_set.bar", "single.#", "1", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested_set" "baz" { - single { - value = "x" - } -} -resource "test_resource_nested_set" "bar" { - single { - value = test_resource_nested_set.baz.id - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_nested_set.baz", "single.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_nested_set.bar", "single.#", "1", - ), - ), - }, - }, - }) -} - -func TestResourceNestedSet_dynamicSetBlock(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "a" { - required = "ok" - required_map = { - a = "b" - } -} - -resource "test_resource_nested_set" "foo" { - dynamic "with_list" { - iterator = thing - for_each = test_resource.a.computed_list - content { - required = thing.value - list = [thing.key] - } - } -} - `), - Check: resource.ComposeTestCheckFunc(), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_nested_test.go b/builtin/providers/test/resource_nested_test.go deleted file mode 100644 index c525f625c3..0000000000 --- a/builtin/providers/test/resource_nested_test.go +++ /dev/null @@ -1,217 +0,0 @@ -package test - -import ( - "errors" - "strings" - "testing" - - "github.com/google/go-cmp/cmp" - "github.com/hashicorp/terraform/addrs" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/terraform" -) - -func TestResourceNested_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { - nested { - string = "val" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.1877647874.string", "val", - ), - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "list_block.0.sub_list_block.0.bool", "false", - ), - ), - }, - }, - }) -} - -func TestResourceNested_addRemove(t *testing.T) { - var id string - idCheck := func(s *terraform.State) error { - root := s.ModuleByPath(addrs.RootModuleInstance) - res := root.Resources["test_resource_nested.foo"] - if res.Primary.ID == id { - return errors.New("expected new resource") - } - id = res.Primary.ID - return nil - } - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - idCheck, - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.#", "0", - ), - // Checking for a count of 0 and a nonexistent count should - // now be the same operation. - resource.TestCheckNoResourceAttr( - "test_resource_nested.foo", "nested.#", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { - nested { - string = "val" - } -} - `), - Check: resource.ComposeTestCheckFunc( - idCheck, - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.1877647874.string", "val", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { - optional = true - nested { - string = "val" - } -} - `), - Check: resource.ComposeTestCheckFunc( - idCheck, - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.1877647874.string", "val", - ), - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "optional", "true", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { - nested { - string = "val" - } -} - `), - Check: resource.ComposeTestCheckFunc( - idCheck, - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.1877647874.string", "val", - ), - resource.TestCheckNoResourceAttr( - "test_resource_nested.foo", "optional", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { - nested { - string = "val" - optional = true - } -} - `), - Check: resource.ComposeTestCheckFunc( - idCheck, - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.2994502535.string", "val", - ), - resource.TestCheckResourceAttr( - "test_resource_nested.foo", "nested.2994502535.optional", "true", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { -} - `), - Check: resource.ComposeTestCheckFunc( - idCheck, - resource.TestCheckNoResourceAttr( - "test_resource_nested.foo", "nested.#", - ), - ), - }, - }, - }) -} - -func TestResourceNested_dynamic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "foo" { - dynamic "nested" { - for_each = [["a"], []] - content { - string = join(",", nested.value) - optional = false - dynamic "nested_again" { - for_each = nested.value - content { - string = nested_again.value - } - } - } - } -} - `), - Check: func(s *terraform.State) error { - rs, ok := s.RootModule().Resources["test_resource_nested.foo"] - if !ok { - return errors.New("missing resource in state") - } - - got := rs.Primary.Attributes - want := map[string]string{ - "nested.#": "2", - "nested.33842314.string": "a", - "nested.33842314.optional": "false", - "nested.33842314.nested_again.#": "1", - "nested.33842314.nested_again.936590934.string": "a", - "nested.140280279.string": "", - "nested.140280279.optional": "false", - "nested.140280279.nested_again.#": "0", - "list_block.#": "1", - "list_block.0.sub_list_block.#": "1", - "list_block.0.sub_list_block.0.bool": "false", - "list_block.0.sub_list_block.0.set.#": "0", - } - delete(got, "id") // it's random, so not useful for testing - - if !cmp.Equal(got, want) { - return errors.New("wrong result\n" + cmp.Diff(want, got)) - } - - return nil - }, - }, - }, - }) -} diff --git a/builtin/providers/test/resource_provider_meta_test.go b/builtin/providers/test/resource_provider_meta_test.go deleted file mode 100644 index 3b92d0a409..0000000000 --- a/builtin/providers/test/resource_provider_meta_test.go +++ /dev/null @@ -1,29 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceProviderMeta_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -terraform { - provider_meta "test" { - foo = "bar" - } -} - -resource "test_resource_provider_meta" "foo" { -} - `), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_required_min_test.go b/builtin/providers/test/resource_required_min_test.go deleted file mode 100644 index 180c28ccfc..0000000000 --- a/builtin/providers/test/resource_required_min_test.go +++ /dev/null @@ -1,66 +0,0 @@ -package test - -import ( - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResource_dynamicRequiredMinItems(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: ` -resource "test_resource_required_min" "a" { -} -`, - ExpectError: regexp.MustCompile(`"required_min_items" blocks are required`), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "a" { - dependent_list { - val = "a" - } -} - -resource "test_resource_required_min" "b" { - dynamic "required_min_items" { - for_each = test_resource_list.a.computed_list - content { - val = required_min_items.value - } - } -} - `), - ExpectError: regexp.MustCompile(`required_min_items: attribute supports 2 item as a minimum`), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_list" "c" { - dependent_list { - val = "a" - } - - dependent_list { - val = "b" - } -} - -resource "test_resource_required_min" "b" { - dynamic "required_min_items" { - for_each = test_resource_list.c.computed_list - content { - val = required_min_items.value - } - } -} - `), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_state_func_test.go b/builtin/providers/test/resource_state_func_test.go deleted file mode 100644 index cf5726eead..0000000000 --- a/builtin/providers/test/resource_state_func_test.go +++ /dev/null @@ -1,85 +0,0 @@ -package test - -import ( - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceStateFunc_basic(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_state_func" "foo" { -} - `), - Check: resource.TestCheckNoResourceAttr("test_resource_state_func.foo", "state_func"), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_state_func" "foo" { - state_func = "data" - state_func_value = "data" -} - `), - Check: resource.TestCheckResourceAttr("test_resource_state_func.foo", "state_func", stateFuncHash("data")), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_state_func" "foo" { -} - `), - Check: resource.TestCheckNoResourceAttr("test_resource_state_func.foo", "state_func"), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_state_func" "foo" { - optional = "added" - state_func = "data" - state_func_value = "data" -} - `), - Check: resource.TestCheckResourceAttr("test_resource_state_func.foo", "state_func", stateFuncHash("data")), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_state_func" "foo" { - optional = "added" - state_func = "changed" - state_func_value = "changed" -} - `), - Check: resource.TestCheckResourceAttr("test_resource_state_func.foo", "state_func", stateFuncHash("changed")), - }, - }, - }) -} - -func TestResourceStateFunc_getOkSetElem(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_state_func" "foo" { -} - -resource "test_resource_state_func" "bar" { - set_block { - required = "foo" - optional = test_resource_state_func.foo.id - } - set_block { - required = test_resource_state_func.foo.id - } -} - `), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_test.go b/builtin/providers/test/resource_test.go deleted file mode 100644 index 510b7816c5..0000000000 --- a/builtin/providers/test/resource_test.go +++ /dev/null @@ -1,1220 +0,0 @@ -package test - -import ( - "reflect" - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform/addrs" - "github.com/hashicorp/terraform/helper/resource" - "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/terraform" -) - -func TestResource_basic(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" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckNoResourceAttr( - "test_resource.foo", "list.#", - ), - ), - }, - }, - }) -} - -func TestResource_changedList(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckNoResourceAttr( - "test_resource.foo", "list.#", - ), - ), - }, - { - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - list = ["a"] -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "list.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource.foo", "list.0", "a", - ), - ), - }, - { - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - list = ["a", "b"] -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "list.#", "2", - ), - resource.TestCheckResourceAttr( - "test_resource.foo", "list.0", "a", - ), - resource.TestCheckResourceAttr( - "test_resource.foo", "list.1", "b", - ), - ), - }, - { - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - list = ["b"] -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "list.#", "1", - ), - resource.TestCheckResourceAttr( - "test_resource.foo", "list.0", "b", - ), - ), - }, - }, - }) -} - -// Targeted test in TestContext2Apply_ignoreChangesCreate -func TestResource_ignoreChangesRequired(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" - } - lifecycle { - ignore_changes = ["required"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -func TestResource_ignoreChangesEmpty(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 = "one" - lifecycle { - ignore_changes = [] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_force_new = "two" - lifecycle { - ignore_changes = [] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -func TestResource_ignoreChangesForceNew(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 = "one" - lifecycle { - ignore_changes = ["optional_force_new"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_force_new = "two" - lifecycle { - ignore_changes = ["optional_force_new"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -// Covers specific scenario in #6005, handled by normalizing boolean strings in -// helper/schema -func TestResource_ignoreChangesForceNewBoolean(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 = "one" - optional_bool = true - lifecycle { - ignore_changes = ["optional_force_new"] - } -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_force_new = "two" - optional_bool = true - lifecycle { - ignore_changes = ["optional_force_new"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -func TestResource_ignoreChangesMap(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_computed_map = { - foo = "bar" - } - lifecycle { - ignore_changes = ["optional_computed_map"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_computed_map = { - foo = "bar" - no = "update" - } - lifecycle { - ignore_changes = ["optional_computed_map"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -func TestResource_ignoreChangesDependent(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - count = 2 - required = "yep" - required_map = { - key = "value" - } - - optional_force_new = "one" - lifecycle { - ignore_changes = ["optional_force_new"] - } -} -resource "test_resource" "bar" { - count = 2 - required = "yep" - required_map = { - key = "value" - } - optional = "${element(test_resource.foo.*.id, count.index)}" -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - count = 2 - required = "yep" - required_map = { - key = "value" - } - - optional_force_new = "two" - lifecycle { - ignore_changes = ["optional_force_new"] - } -} -resource "test_resource" "bar" { - count = 2 - required = "yep" - required_map = { - key = "value" - } - optional = "${element(test_resource.foo.*.id, count.index)}" -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -func TestResource_ignoreChangesStillReplaced(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 = "one" - optional_bool = true - lifecycle { - ignore_changes = ["optional_bool"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_force_new = "two" - optional_bool = false - lifecycle { - ignore_changes = ["optional_bool"] - } -} - `), - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -func TestResource_ignoreChangesCustomizeDiff(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 = "a" - lifecycle { - ignore_changes = [optional] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "planned_computed", "a", - ), - ), - }, - // On this step, `optional` changes, but `planned_computed` - // should remain as "a" because we have set `ignore_changes` - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional = "b" - lifecycle { - ignore_changes = [optional] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "planned_computed", "a", - ), - ), - }, - }, - }) -} - -// Reproduces plan-time panic when the wrong type is interpolated in a list of -// maps. -// TODO: this should return a type error, rather than silently setting an empty -// list -func TestResource_dataSourceListMapPanic(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 = "val" - required_map = {x = "y"} - list_of_map = "${var.maplist}" -} - -variable "maplist" { - type = "list" - - default = [ - {a = "b"} - ] -} - `), - ExpectError: nil, - Check: func(s *terraform.State) error { - return nil - }, - }, - }, - }) -} - -func TestResource_dataSourceIndexMapList(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 = "val" - - required_map = { - x = "y" - } - - list_of_map = [ - { - a = "1" - b = "2" - }, - { - c = "3" - d = "4" - }, - ] -} - -output "map_from_list" { - value = "${test_resource.foo.list_of_map[0]}" -} - -output "value_from_map_from_list" { - value = "${lookup(test_resource.foo.list_of_map[1], "d")}" -} - `), - ExpectError: nil, - Check: func(s *terraform.State) error { - root := s.ModuleByPath(addrs.RootModuleInstance) - mapOut := root.Outputs["map_from_list"].Value - expectedMapOut := map[string]interface{}{ - "a": "1", - "b": "2", - } - - valueOut := root.Outputs["value_from_map_from_list"].Value - expectedValueOut := "4" - - if !reflect.DeepEqual(mapOut, expectedMapOut) { - t.Fatalf("Expected: %#v\nGot: %#v", expectedMapOut, mapOut) - } - if !reflect.DeepEqual(valueOut, expectedValueOut) { - t.Fatalf("Expected: %#v\nGot: %#v", valueOut, expectedValueOut) - } - return nil - }, - }, - }, - }) -} - -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" - } -} - `), - }, - }, - }) -} - -func TestResource_unknownFuncInMap(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 = "ok" - required_map = { - key = "${uuid()}" - } -} - `), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -// Verify that we can destroy when a managed resource references something with -// a count of 1. -func TestResource_countRefDestroyError(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: strings.TrimSpace(` -resource "test_resource" "one" { - count = 1 - required = "ok" - required_map = { - key = "val" - } -} - -resource "test_resource" "two" { - required = test_resource.one[0].id - required_map = { - key = "val" - } -} - `), - }, - }, - }) -} - -func TestResource_emptyMapValue(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 = "ok" - required_map = { - a = "a" - b = "" - } -} - `), - }, - }, - }) -} - -func TestResource_updateError(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 = "first" - required_map = { - a = "a" - } -} -`), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "second" - required_map = { - a = "a" - } - apply_error = "update_error" -} -`), - ExpectError: regexp.MustCompile("update_error"), - }, - }, - }) -} - -func TestResource_applyError(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 = "second" - required_map = { - a = "a" - } - apply_error = "apply_error" -} -`), - ExpectError: regexp.MustCompile("apply_error"), - }, - }, - }) -} - -func TestResource_emptyStrings(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 = "second" - required_map = { - a = "a" - } - - list = [""] -} -`), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource.foo", "list.0", ""), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "second" - required_map = { - a = "a" - } - - list = ["", "b"] -} -`), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource.foo", "list.0", ""), - resource.TestCheckResourceAttr("test_resource.foo", "list.1", "b"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "second" - required_map = { - a = "a" - } - - list = [""] -} -`), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource.foo", "list.0", ""), - ), - }, - }, - }) -} - -func TestResource_setDrift(t *testing.T) { - testProvider := testAccProviders["test"] - res := testProvider.(*schema.Provider).ResourcesMap["test_resource"] - - // reset the Read function after the test - defer func() { - res.Read = testResourceRead - }() - - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "first" - required_map = { - a = "a" - } - set = ["a", "b"] -} -`), - Check: func(s *terraform.State) error { - return nil - }, - }, - resource.TestStep{ - PreConfig: func() { - // update the Read function to return the wrong "set" attribute values. - res.Read = func(d *schema.ResourceData, meta interface{}) error { - // update as expected first - if err := testResourceRead(d, meta); err != nil { - return err - } - d.Set("set", []interface{}{"a", "x"}) - return nil - } - }, - // Leave the config, so we can detect the mismatched set values. - // Updating the config would force the test to pass even if the Read - // function values were ignored. - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "second" - required_map = { - a = "a" - } - set = ["a", "b"] -} -`), - ExpectNonEmptyPlan: true, - }, - }, - }) -} - -func TestResource_optionalComputedMap(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_computed_map = { - foo = "bar" - baz = "" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "optional_computed_map.foo", "bar", - ), - resource.TestCheckResourceAttr( - "test_resource.foo", "optional_computed_map.baz", "", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_computed_map = {} -} - `), - // removing the map from the config should still leave an empty computed map - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "optional_computed_map.%", "0", - ), - ), - }, - }, - }) -} - -func TestResource_plannedComputed(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 = "ok" - required_map = { - key = "value" - } - optional = "hi" -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "planned_computed", "hi", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "ok" - required_map = { - key = "value" - } - optional = "changed" -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "planned_computed", "changed", - ), - ), - }, - }, - }) -} - -func TestDiffApply_map(t *testing.T) { - resSchema := map[string]*schema.Schema{ - "map": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - } - - priorAttrs := map[string]string{ - "id": "ok", - "map.%": "2", - "map.foo": "bar", - "map.bar": "", - } - - diff := &terraform.InstanceDiff{ - Attributes: map[string]*terraform.ResourceAttrDiff{ - "map.foo": &terraform.ResourceAttrDiff{Old: "bar", New: "", NewRemoved: true}, - "map.bar": &terraform.ResourceAttrDiff{Old: "", New: "", NewRemoved: true}, - }, - } - - newAttrs, err := diff.Apply(priorAttrs, (&schema.Resource{Schema: resSchema}).CoreConfigSchema()) - if err != nil { - t.Fatal(err) - } - - expect := map[string]string{ - "id": "ok", - "map.%": "0", - } - - if !reflect.DeepEqual(newAttrs, expect) { - t.Fatalf("expected:%#v got:%#v", expect, newAttrs) - } -} - -func TestResource_dependsComputed(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -variable "change" { - default = false -} - -resource "test_resource" "foo" { - required = "ok" - required_map = { - key = "value" - } - optional = var.change ? "after" : "" -} - -resource "test_resource" "bar" { - count = var.change ? 1 : 0 - required = test_resource.foo.planned_computed - required_map = { - key = "value" - } -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -variable "change" { - default = true -} - -resource "test_resource" "foo" { - required = "ok" - required_map = { - key = "value" - } - optional = var.change ? "after" : "" -} - -resource "test_resource" "bar" { - count = var.change ? 1 : 0 - required = test_resource.foo.planned_computed - required_map = { - key = "value" - } -} - `), - }, - }, - }) -} - -func TestResource_optionalComputedBool(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" - } -} - `), - }, - }, - }) -} - -func TestResource_replacedOptionalComputed(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "a" { -} - -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_computed = test_resource_nested.a.id -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_nested" "b" { -} - -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - optional_computed = test_resource_nested.b.id -} - `), - }, - }, - }) -} - -func TestResource_floatInIntAttr(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" - } - int = 40.2 -} - `), - ExpectError: regexp.MustCompile(`must be a whole number, got 40.2`), - }, - }, - }) -} - -func TestResource_unsetNil(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 = "a" -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource.foo", "optional", "a"), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource.foo", "optional", ""), - ), - }, - }, - }) -} - -// Verify we can use use numeric indices in `ignore_changes` paths. -func TestResource_ignoreChangesIndex(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" - } - list_of_map = [ - { - a = "b" - } - ] - - lifecycle { - ignore_changes = [list_of_map[0]["a"]] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "list_of_map.0.a", "b", - ), - ), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - list_of_map = [ - { - a = "c" - } - ] - - lifecycle { - ignore_changes = [list_of_map[0]["a"]] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "list_of_map.0.a", "b", - ), - ), - }, - // set ignore_changes to a prefix of the changed value - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource" "foo" { - required = "yep" - required_map = { - key = "value" - } - list_of_map = [ - { - a = "d" - } - ] - - lifecycle { - ignore_changes = [list_of_map[0]] - } -} - `), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr( - "test_resource.foo", "list_of_map.0.a", "b", - ), - ), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_timeout_test.go b/builtin/providers/test/resource_timeout_test.go deleted file mode 100644 index 312a37a781..0000000000 --- a/builtin/providers/test/resource_timeout_test.go +++ /dev/null @@ -1,158 +0,0 @@ -package test - -import ( - "regexp" - "strings" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -func TestResourceTimeout_create(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - create_delay = "2s" - timeouts { - create = "1s" - } -} - `), - ExpectError: regexp.MustCompile("timeout while creating resource"), - }, - }, - }) -} - -// start with the default, then modify it -func TestResourceTimeout_defaults(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - update_delay = "1ms" -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - update_delay = "2ms" - timeouts { - update = "3s" - } -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - update_delay = "2s" - delete_delay = "2s" - timeouts { - delete = "3s" - update = "3s" - } -} - `), - }, - // delete "foo" - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "bar" { -} - `), - }, - }, - }) -} - -func TestResourceTimeout_delete(t *testing.T) { - // If the delete timeout isn't saved until destroy, the cleanup here will - // fail because the default is only 20m. - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - delete_delay = "25m" - timeouts { - delete = "30m" - } -} - `), - }, - }, - }) -} -func TestResourceTimeout_update(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - update_delay = "1s" - timeouts { - update = "1s" - } -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - update_delay = "2s" - timeouts { - update = "1s" - } -} - `), - ExpectError: regexp.MustCompile("timeout while updating resource"), - }, - }, - }) -} - -func TestResourceTimeout_read(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - CheckDestroy: testAccCheckResourceDestroy, - Steps: []resource.TestStep{ - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { -} - `), - }, - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { - read_delay = "30m" -} - `), - ExpectError: regexp.MustCompile("timeout while reading resource"), - }, - // we need to remove the read_delay so that the resource can be - // destroyed in the final step, but expect an error here from the - // pre-existing delay. - resource.TestStep{ - Config: strings.TrimSpace(` -resource "test_resource_timeout" "foo" { -} - `), - ExpectError: regexp.MustCompile("timeout while reading resource"), - }, - }, - }) -} diff --git a/builtin/providers/test/resource_with_custom_diff_test.go b/builtin/providers/test/resource_with_custom_diff_test.go deleted file mode 100644 index 05982bec9a..0000000000 --- a/builtin/providers/test/resource_with_custom_diff_test.go +++ /dev/null @@ -1,53 +0,0 @@ -package test - -import ( - "fmt" - "regexp" - "testing" - - "github.com/hashicorp/terraform/helper/resource" -) - -// TestResourceWithCustomDiff test custom diff behaviour. -func TestResourceWithCustomDiff(t *testing.T) { - resource.UnitTest(t, resource.TestCase{ - Providers: testAccProviders, - Steps: []resource.TestStep{ - { - Config: resourceWithCustomDiffConfig(false), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "computed", "1"), - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "index", "1"), - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.#", "1"), - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.0", "dc1"), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: resourceWithCustomDiffConfig(false), - Check: resource.ComposeTestCheckFunc( - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "computed", "2"), - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "index", "2"), - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.#", "2"), - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.0", "dc2"), - resource.TestCheckResourceAttr("test_resource_with_custom_diff.foo", "list.1", "dc3"), - resource.TestCheckNoResourceAttr("test_resource_with_custom_diff.foo", "list.2"), - ), - ExpectNonEmptyPlan: true, - }, - { - Config: resourceWithCustomDiffConfig(true), - ExpectError: regexp.MustCompile("veto is true, diff vetoed"), - }, - }, - }) -} - -func resourceWithCustomDiffConfig(veto bool) string { - return fmt.Sprintf(` -resource "test_resource_with_custom_diff" "foo" { - required = "yep" - veto = %t -} -`, veto) -} diff --git a/builtin/providers/test/data_source.go b/internal/legacy/builtin/providers/test/data_source.go similarity index 95% rename from builtin/providers/test/data_source.go rename to internal/legacy/builtin/providers/test/data_source.go index 2a735703fb..11ff28a2f9 100644 --- a/builtin/providers/test/data_source.go +++ b/internal/legacy/builtin/providers/test/data_source.go @@ -3,7 +3,7 @@ package test import ( "time" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testDataSource() *schema.Resource { diff --git a/builtin/providers/test/data_source_label.go b/internal/legacy/builtin/providers/test/data_source_label.go similarity index 86% rename from builtin/providers/test/data_source_label.go rename to internal/legacy/builtin/providers/test/data_source_label.go index 40f3bad581..8e97d2fed8 100644 --- a/builtin/providers/test/data_source_label.go +++ b/internal/legacy/builtin/providers/test/data_source_label.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func providerLabelDataSource() *schema.Resource { diff --git a/builtin/providers/test/provider.go b/internal/legacy/builtin/providers/test/provider.go similarity index 94% rename from builtin/providers/test/provider.go rename to internal/legacy/builtin/providers/test/provider.go index 1066f37c21..4ca8268987 100644 --- a/builtin/providers/test/provider.go +++ b/internal/legacy/builtin/providers/test/provider.go @@ -1,8 +1,8 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" - "github.com/hashicorp/terraform/terraform" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/terraform" ) func Provider() terraform.ResourceProvider { diff --git a/builtin/providers/test/resource.go b/internal/legacy/builtin/providers/test/resource.go similarity index 98% rename from builtin/providers/test/resource.go rename to internal/legacy/builtin/providers/test/resource.go index b05fcc681e..46b3a1cb5e 100644 --- a/builtin/providers/test/resource.go +++ b/internal/legacy/builtin/providers/test/resource.go @@ -4,7 +4,7 @@ import ( "errors" "fmt" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResource() *schema.Resource { diff --git a/builtin/providers/test/resource_computed_set.go b/internal/legacy/builtin/providers/test/resource_computed_set.go similarity index 97% rename from builtin/providers/test/resource_computed_set.go rename to internal/legacy/builtin/providers/test/resource_computed_set.go index 092cd22760..fa2035c8d5 100644 --- a/builtin/providers/test/resource_computed_set.go +++ b/internal/legacy/builtin/providers/test/resource_computed_set.go @@ -7,7 +7,7 @@ import ( "strings" "github.com/hashicorp/terraform/helper/hashcode" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceComputedSet() *schema.Resource { diff --git a/builtin/providers/test/resource_config_mode.go b/internal/legacy/builtin/providers/test/resource_config_mode.go similarity index 96% rename from builtin/providers/test/resource_config_mode.go rename to internal/legacy/builtin/providers/test/resource_config_mode.go index 82b476039e..bb1da15507 100644 --- a/builtin/providers/test/resource_config_mode.go +++ b/internal/legacy/builtin/providers/test/resource_config_mode.go @@ -3,7 +3,7 @@ package test import ( "fmt" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceConfigMode() *schema.Resource { diff --git a/builtin/providers/test/resource_defaults.go b/internal/legacy/builtin/providers/test/resource_defaults.go similarity index 95% rename from builtin/providers/test/resource_defaults.go rename to internal/legacy/builtin/providers/test/resource_defaults.go index 41038de683..f46a4bb027 100644 --- a/builtin/providers/test/resource_defaults.go +++ b/internal/legacy/builtin/providers/test/resource_defaults.go @@ -4,7 +4,7 @@ import ( "fmt" "math/rand" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceDefaults() *schema.Resource { diff --git a/builtin/providers/test/resource_deprecated.go b/internal/legacy/builtin/providers/test/resource_deprecated.go similarity index 97% rename from builtin/providers/test/resource_deprecated.go rename to internal/legacy/builtin/providers/test/resource_deprecated.go index a176977b9b..d787222089 100644 --- a/builtin/providers/test/resource_deprecated.go +++ b/internal/legacy/builtin/providers/test/resource_deprecated.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceDeprecated() *schema.Resource { diff --git a/builtin/providers/test/resource_diff_suppress.go b/internal/legacy/builtin/providers/test/resource_diff_suppress.go similarity index 97% rename from builtin/providers/test/resource_diff_suppress.go rename to internal/legacy/builtin/providers/test/resource_diff_suppress.go index f5cfc9331d..309cc4488f 100644 --- a/builtin/providers/test/resource_diff_suppress.go +++ b/internal/legacy/builtin/providers/test/resource_diff_suppress.go @@ -5,7 +5,7 @@ import ( "math/rand" "strings" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceDiffSuppress() *schema.Resource { diff --git a/builtin/providers/test/resource_force_new.go b/internal/legacy/builtin/providers/test/resource_force_new.go similarity index 92% rename from builtin/providers/test/resource_force_new.go rename to internal/legacy/builtin/providers/test/resource_force_new.go index 81a06736c4..85721141ed 100644 --- a/builtin/providers/test/resource_force_new.go +++ b/internal/legacy/builtin/providers/test/resource_force_new.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceForceNew() *schema.Resource { diff --git a/builtin/providers/test/resource_gh12183.go b/internal/legacy/builtin/providers/test/resource_gh12183.go similarity index 95% rename from builtin/providers/test/resource_gh12183.go rename to internal/legacy/builtin/providers/test/resource_gh12183.go index d67bcf755f..f75fbe2e94 100644 --- a/builtin/providers/test/resource_gh12183.go +++ b/internal/legacy/builtin/providers/test/resource_gh12183.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) // This is a test resource to help reproduce GH-12183. This issue came up diff --git a/builtin/providers/test/resource_list.go b/internal/legacy/builtin/providers/test/resource_list.go similarity index 98% rename from builtin/providers/test/resource_list.go rename to internal/legacy/builtin/providers/test/resource_list.go index 895298ebb0..9c69f915c1 100644 --- a/builtin/providers/test/resource_list.go +++ b/internal/legacy/builtin/providers/test/resource_list.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceList() *schema.Resource { diff --git a/builtin/providers/test/resource_list_set.go b/internal/legacy/builtin/providers/test/resource_list_set.go similarity index 98% rename from builtin/providers/test/resource_list_set.go rename to internal/legacy/builtin/providers/test/resource_list_set.go index 0ce5abc8d5..fe54d92356 100644 --- a/builtin/providers/test/resource_list_set.go +++ b/internal/legacy/builtin/providers/test/resource_list_set.go @@ -4,7 +4,7 @@ import ( "fmt" "math/rand" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceListSet() *schema.Resource { diff --git a/builtin/providers/test/resource_map.go b/internal/legacy/builtin/providers/test/resource_map.go similarity index 96% rename from builtin/providers/test/resource_map.go rename to internal/legacy/builtin/providers/test/resource_map.go index c6bf62bd62..fe1ece1e9e 100644 --- a/builtin/providers/test/resource_map.go +++ b/internal/legacy/builtin/providers/test/resource_map.go @@ -4,7 +4,7 @@ import ( "fmt" "github.com/hashicorp/terraform/configs/hcl2shim" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceMap() *schema.Resource { diff --git a/builtin/providers/test/resource_nested.go b/internal/legacy/builtin/providers/test/resource_nested.go similarity index 97% rename from builtin/providers/test/resource_nested.go rename to internal/legacy/builtin/providers/test/resource_nested.go index bff7432594..c78274d53e 100644 --- a/builtin/providers/test/resource_nested.go +++ b/internal/legacy/builtin/providers/test/resource_nested.go @@ -4,7 +4,7 @@ import ( "fmt" "math/rand" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceNested() *schema.Resource { diff --git a/builtin/providers/test/resource_nested_id.go b/internal/legacy/builtin/providers/test/resource_nested_id.go similarity index 93% rename from builtin/providers/test/resource_nested_id.go rename to internal/legacy/builtin/providers/test/resource_nested_id.go index c3bd419745..f5a2d9bf93 100644 --- a/builtin/providers/test/resource_nested_id.go +++ b/internal/legacy/builtin/providers/test/resource_nested_id.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceNestedId() *schema.Resource { diff --git a/builtin/providers/test/resource_nested_set.go b/internal/legacy/builtin/providers/test/resource_nested_set.go similarity index 98% rename from builtin/providers/test/resource_nested_set.go rename to internal/legacy/builtin/providers/test/resource_nested_set.go index 81d7ab0f53..4a12534008 100644 --- a/builtin/providers/test/resource_nested_set.go +++ b/internal/legacy/builtin/providers/test/resource_nested_set.go @@ -4,7 +4,7 @@ import ( "fmt" "math/rand" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceNestedSet() *schema.Resource { diff --git a/builtin/providers/test/resource_provider_meta.go b/internal/legacy/builtin/providers/test/resource_provider_meta.go similarity index 96% rename from builtin/providers/test/resource_provider_meta.go rename to internal/legacy/builtin/providers/test/resource_provider_meta.go index c05adb1702..c900c5159f 100644 --- a/builtin/providers/test/resource_provider_meta.go +++ b/internal/legacy/builtin/providers/test/resource_provider_meta.go @@ -3,7 +3,7 @@ package test import ( "fmt" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceProviderMeta() *schema.Resource { diff --git a/builtin/providers/test/resource_required_min.go b/internal/legacy/builtin/providers/test/resource_required_min.go similarity index 95% rename from builtin/providers/test/resource_required_min.go rename to internal/legacy/builtin/providers/test/resource_required_min.go index 413d4c51d6..23419ed025 100644 --- a/builtin/providers/test/resource_required_min.go +++ b/internal/legacy/builtin/providers/test/resource_required_min.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceRequiredMin() *schema.Resource { diff --git a/builtin/providers/test/resource_signal.go b/internal/legacy/builtin/providers/test/resource_signal.go similarity index 93% rename from builtin/providers/test/resource_signal.go rename to internal/legacy/builtin/providers/test/resource_signal.go index 57e4bf0ebd..398a996cd6 100644 --- a/builtin/providers/test/resource_signal.go +++ b/internal/legacy/builtin/providers/test/resource_signal.go @@ -1,7 +1,7 @@ package test import ( - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceSignal() *schema.Resource { diff --git a/builtin/providers/test/resource_state_func.go b/internal/legacy/builtin/providers/test/resource_state_func.go similarity index 97% rename from builtin/providers/test/resource_state_func.go rename to internal/legacy/builtin/providers/test/resource_state_func.go index 609e5ea537..9589f102e7 100644 --- a/builtin/providers/test/resource_state_func.go +++ b/internal/legacy/builtin/providers/test/resource_state_func.go @@ -7,7 +7,7 @@ import ( "math/rand" "github.com/hashicorp/terraform/helper/hashcode" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceStateFunc() *schema.Resource { diff --git a/builtin/providers/test/resource_timeout.go b/internal/legacy/builtin/providers/test/resource_timeout.go similarity index 97% rename from builtin/providers/test/resource_timeout.go rename to internal/legacy/builtin/providers/test/resource_timeout.go index a10717550d..17a6da0ebd 100644 --- a/builtin/providers/test/resource_timeout.go +++ b/internal/legacy/builtin/providers/test/resource_timeout.go @@ -4,7 +4,7 @@ import ( "fmt" "time" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceTimeout() *schema.Resource { diff --git a/builtin/providers/test/resource_undeletable.go b/internal/legacy/builtin/providers/test/resource_undeletable.go similarity index 92% rename from builtin/providers/test/resource_undeletable.go rename to internal/legacy/builtin/providers/test/resource_undeletable.go index e5c9bb3b05..b4be0bff31 100644 --- a/builtin/providers/test/resource_undeletable.go +++ b/internal/legacy/builtin/providers/test/resource_undeletable.go @@ -3,7 +3,7 @@ package test import ( "fmt" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceUndeleteable() *schema.Resource { diff --git a/builtin/providers/test/resource_with_custom_diff.go b/internal/legacy/builtin/providers/test/resource_with_custom_diff.go similarity index 98% rename from builtin/providers/test/resource_with_custom_diff.go rename to internal/legacy/builtin/providers/test/resource_with_custom_diff.go index 10756548c1..397e0795e1 100644 --- a/builtin/providers/test/resource_with_custom_diff.go +++ b/internal/legacy/builtin/providers/test/resource_with_custom_diff.go @@ -3,7 +3,7 @@ package test import ( "fmt" - "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/internal/legacy/helper/schema" ) func testResourceCustomDiff() *schema.Resource {