diff --git a/internal/legacy/builtin/bins/provider-test/main.go b/internal/legacy/builtin/bins/provider-test/main.go deleted file mode 100644 index eb6d3f796..000000000 --- a/internal/legacy/builtin/bins/provider-test/main.go +++ /dev/null @@ -1,15 +0,0 @@ -package main - -import ( - "github.com/hashicorp/terraform/internal/legacy/builtin/providers/test" - "github.com/hashicorp/terraform/internal/legacy/terraform" - "github.com/hashicorp/terraform/plugin" -) - -func main() { - plugin.Serve(&plugin.ServeOpts{ - ProviderFunc: func() terraform.ResourceProvider { - return test.Provider() - }, - }) -} diff --git a/internal/legacy/builtin/providers/test/data_source.go b/internal/legacy/builtin/providers/test/data_source.go deleted file mode 100644 index 11ff28a2f..000000000 --- a/internal/legacy/builtin/providers/test/data_source.go +++ /dev/null @@ -1,63 +0,0 @@ -package test - -import ( - "time" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testDataSource() *schema.Resource { - return &schema.Resource{ - Read: testDataSourceRead, - - Schema: map[string]*schema.Schema{ - "list": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - - "input": { - Type: schema.TypeString, - Optional: true, - }, - - "output": { - Type: schema.TypeString, - Computed: true, - }, - // this attribute is computed, but never set by the provider - "nil": { - Type: schema.TypeString, - Computed: true, - }, - - "input_map": { - Type: schema.TypeMap, - Elem: &schema.Schema{Type: schema.TypeString}, - Optional: true, - }, - "output_map": { - Type: schema.TypeMap, - Elem: &schema.Schema{Type: schema.TypeString}, - Computed: true, - }, - }, - } -} - -func testDataSourceRead(d *schema.ResourceData, meta interface{}) error { - d.SetId(time.Now().UTC().String()) - d.Set("list", []interface{}{"one", "two", "three"}) - - if input, hasInput := d.GetOk("input"); hasInput { - d.Set("output", input) - } else { - d.Set("output", "some output") - } - - if inputMap, hasInput := d.GetOk("input_map"); hasInput { - d.Set("output_map", inputMap) - } - return nil -} diff --git a/internal/legacy/builtin/providers/test/data_source_label.go b/internal/legacy/builtin/providers/test/data_source_label.go deleted file mode 100644 index 8e97d2fed..000000000 --- a/internal/legacy/builtin/providers/test/data_source_label.go +++ /dev/null @@ -1,25 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func providerLabelDataSource() *schema.Resource { - return &schema.Resource{ - Read: providerLabelDataSourceRead, - - Schema: map[string]*schema.Schema{ - "label": { - Type: schema.TypeString, - Computed: true, - }, - }, - } -} - -func providerLabelDataSourceRead(d *schema.ResourceData, meta interface{}) error { - label := meta.(string) - d.SetId(label) - d.Set("label", label) - return nil -} diff --git a/internal/legacy/builtin/providers/test/provider.go b/internal/legacy/builtin/providers/test/provider.go deleted file mode 100644 index 4ca826898..000000000 --- a/internal/legacy/builtin/providers/test/provider.go +++ /dev/null @@ -1,59 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" - "github.com/hashicorp/terraform/internal/legacy/terraform" -) - -func Provider() terraform.ResourceProvider { - return &schema.Provider{ - Schema: map[string]*schema.Schema{ - // Optional attribute to label a particular instance for a test - // that has multiple instances of this provider, so that they - // can be distinguished using the test_provider_label data source. - "label": { - Type: schema.TypeString, - Optional: true, - }, - }, - ProviderMetaSchema: map[string]*schema.Schema{ - // Optionally allow specifying information at a module-level - "foo": { - Type: schema.TypeString, - Optional: true, - }, - }, - ResourcesMap: map[string]*schema.Resource{ - "test_resource": testResource(), - "test_resource_gh12183": testResourceGH12183(), - "test_resource_with_custom_diff": testResourceCustomDiff(), - "test_resource_timeout": testResourceTimeout(), - "test_resource_diff_suppress": testResourceDiffSuppress(), - "test_resource_force_new": testResourceForceNew(), - "test_resource_nested": testResourceNested(), - "test_resource_nested_set": testResourceNestedSet(), - "test_resource_state_func": testResourceStateFunc(), - "test_resource_deprecated": testResourceDeprecated(), - "test_resource_defaults": testResourceDefaults(), - "test_resource_list": testResourceList(), - "test_resource_list_set": testResourceListSet(), - "test_resource_map": testResourceMap(), - "test_resource_computed_set": testResourceComputedSet(), - "test_resource_config_mode": testResourceConfigMode(), - "test_resource_nested_id": testResourceNestedId(), - "test_resource_provider_meta": testResourceProviderMeta(), - "test_resource_signal": testResourceSignal(), - "test_undeleteable": testResourceUndeleteable(), - "test_resource_required_min": testResourceRequiredMin(), - }, - DataSourcesMap: map[string]*schema.Resource{ - "test_data_source": testDataSource(), - "test_provider_label": providerLabelDataSource(), - }, - ConfigureFunc: providerConfigure, - } -} - -func providerConfigure(d *schema.ResourceData) (interface{}, error) { - return d.Get("label"), nil -} diff --git a/internal/legacy/builtin/providers/test/resource.go b/internal/legacy/builtin/providers/test/resource.go deleted file mode 100644 index 46b3a1cb5..000000000 --- a/internal/legacy/builtin/providers/test/resource.go +++ /dev/null @@ -1,233 +0,0 @@ -package test - -import ( - "errors" - "fmt" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResource() *schema.Resource { - return &schema.Resource{ - Create: testResourceCreate, - Read: testResourceRead, - Update: testResourceUpdate, - Delete: testResourceDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - CustomizeDiff: func(d *schema.ResourceDiff, _ interface{}) error { - if d.HasChange("optional") { - d.SetNewComputed("planned_computed") - } - return nil - }, - - Schema: map[string]*schema.Schema{ - "required": { - Type: schema.TypeString, - Required: true, - }, - "optional": { - Type: schema.TypeString, - Optional: true, - }, - "optional_bool": { - Type: schema.TypeBool, - Optional: true, - }, - "optional_force_new": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "optional_computed_map": { - Type: schema.TypeMap, - Optional: true, - Computed: true, - }, - "optional_computed_force_new": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - "optional_computed": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - "computed_read_only": { - Type: schema.TypeString, - Computed: true, - }, - "computed_from_required": { - Type: schema.TypeString, - Computed: true, - ForceNew: true, - }, - "computed_read_only_force_new": { - Type: schema.TypeString, - Computed: true, - ForceNew: true, - }, - "computed_list": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "set": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Set: schema.HashString, - }, - "computed_set": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Set: schema.HashString, - }, - "map": { - Type: schema.TypeMap, - Optional: true, - }, - "optional_map": { - Type: schema.TypeMap, - Optional: true, - }, - "required_map": { - Type: schema.TypeMap, - Required: true, - }, - "map_that_look_like_set": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "computed_map": { - Type: schema.TypeMap, - Computed: true, - }, - "list": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "list_of_map": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeMap, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - }, - "apply_error": { - Type: schema.TypeString, - Optional: true, - Description: "return and error during apply", - }, - "planned_computed": { - Type: schema.TypeString, - Computed: true, - Description: "copied the required field during apply, and plans computed when changed", - }, - // this should return unset from GetOkExists - "get_ok_exists_false": { - Type: schema.TypeBool, - Computed: true, - Optional: true, - Description: "do not set in config", - }, - "int": { - Type: schema.TypeInt, - Optional: true, - }, - }, - } -} - -func testResourceCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - - errMsg, _ := d.Get("apply_error").(string) - if errMsg != "" { - return errors.New(errMsg) - } - - // Required must make it through to Create - if _, ok := d.GetOk("required"); !ok { - return fmt.Errorf("Missing attribute 'required', but it's required!") - } - if _, ok := d.GetOk("required_map"); !ok { - return fmt.Errorf("Missing attribute 'required_map', but it's required!") - } - - d.Set("computed_from_required", d.Get("required")) - - return testResourceRead(d, meta) -} - -func testResourceRead(d *schema.ResourceData, meta interface{}) error { - d.Set("computed_read_only", "value_from_api") - d.Set("computed_read_only_force_new", "value_from_api") - if _, ok := d.GetOk("optional_computed_map"); !ok { - d.Set("optional_computed_map", map[string]string{}) - } - d.Set("computed_map", map[string]string{"key1": "value1"}) - d.Set("computed_list", []string{"listval1", "listval2"}) - d.Set("computed_set", []string{"setval1", "setval2"}) - - d.Set("planned_computed", d.Get("optional")) - - // if there is no "set" value, erroneously set it to an empty set. This - // might change a null value to an empty set, but we should be able to - // ignore that. - s := d.Get("set") - if s == nil || s.(*schema.Set).Len() == 0 { - d.Set("set", []interface{}{}) - } - - // This mimics many providers always setting a *string value. - // The existing behavior is that this will appear in the state as an empty - // string, which we have to maintain. - o := d.Get("optional") - if o == "" { - d.Set("optional", nil) - } - - // This should not show as set unless it's set in the config - _, ok := d.GetOkExists("get_ok_exists_false") - if ok { - return errors.New("get_ok_exists_false should not be set") - } - - return nil -} - -func testResourceUpdate(d *schema.ResourceData, meta interface{}) error { - errMsg, _ := d.Get("apply_error").(string) - if errMsg != "" { - return errors.New(errMsg) - } - return testResourceRead(d, meta) -} - -func testResourceDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_computed_set.go b/internal/legacy/builtin/providers/test/resource_computed_set.go deleted file mode 100644 index fa2035c8d..000000000 --- a/internal/legacy/builtin/providers/test/resource_computed_set.go +++ /dev/null @@ -1,123 +0,0 @@ -package test - -import ( - "bytes" - "fmt" - "math/rand" - "strings" - - "github.com/hashicorp/terraform/helper/hashcode" - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceComputedSet() *schema.Resource { - return &schema.Resource{ - Create: testResourceComputedSetCreate, - Read: testResourceComputedSetRead, - Delete: testResourceComputedSetDelete, - Update: testResourceComputedSetUpdate, - - CustomizeDiff: func(d *schema.ResourceDiff, _ interface{}) error { - o, n := d.GetChange("set_count") - if o != n { - d.SetNewComputed("string_set") - } - return nil - }, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "set_count": { - Type: schema.TypeInt, - Optional: true, - }, - "string_set": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - Set: schema.HashString, - }, - - "rule": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Computed: true, - }, - - "ip_protocol": { - Type: schema.TypeString, - Required: true, - ForceNew: false, - }, - - "cidr": { - Type: schema.TypeString, - Optional: true, - ForceNew: false, - StateFunc: func(v interface{}) string { - return strings.ToLower(v.(string)) - }, - }, - }, - }, - }, - "optional_set": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - }, - } -} - -func computeSecGroupV2RuleHash(v interface{}) int { - var buf bytes.Buffer - m := v.(map[string]interface{}) - buf.WriteString(fmt.Sprintf("%s-", m["ip_protocol"].(string))) - buf.WriteString(fmt.Sprintf("%s-", strings.ToLower(m["cidr"].(string)))) - - return hashcode.String(buf.String()) -} - -func testResourceComputedSetCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId(fmt.Sprintf("%x", rand.Int63())) - return testResourceComputedSetRead(d, meta) -} - -func testResourceComputedSetRead(d *schema.ResourceData, meta interface{}) error { - count := 3 - v, ok := d.GetOk("set_count") - if ok { - count = v.(int) - } - - var set []interface{} - for i := 0; i < count; i++ { - set = append(set, fmt.Sprintf("%d", i)) - } - - d.Set("string_set", schema.NewSet(schema.HashString, set)) - - // This isn't computed, but we should be able to ignore without issues. - d.Set("optional_set", []interface{}{}) - return nil -} - -func testResourceComputedSetUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceComputedSetRead(d, meta) -} - -func testResourceComputedSetDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_config_mode.go b/internal/legacy/builtin/providers/test/resource_config_mode.go deleted file mode 100644 index bb1da1550..000000000 --- a/internal/legacy/builtin/providers/test/resource_config_mode.go +++ /dev/null @@ -1,78 +0,0 @@ -package test - -import ( - "fmt" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceConfigMode() *schema.Resource { - return &schema.Resource{ - Create: testResourceConfigModeCreate, - Read: testResourceConfigModeRead, - Delete: testResourceConfigModeDelete, - Update: testResourceConfigModeUpdate, - - Schema: map[string]*schema.Schema{ - "resource_as_attr": { - Type: schema.TypeList, - ConfigMode: schema.SchemaConfigModeAttr, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "foo": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - "nested_set": { - Type: schema.TypeSet, - Optional: true, - ConfigMode: schema.SchemaConfigModeAttr, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - Optional: true, - }, - "set": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - }, - } -} - -func testResourceConfigModeCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("placeholder") - return testResourceConfigModeRead(d, meta) -} - -func testResourceConfigModeRead(d *schema.ResourceData, meta interface{}) error { - if l, ok := d.Get("resource_as_attr").([]interface{}); !ok { - return fmt.Errorf("resource_as_attr should appear as []interface{}, not %T", l) - } else { - for i, item := range l { - if _, ok := item.(map[string]interface{}); !ok { - return fmt.Errorf("resource_as_attr[%d] should appear as map[string]interface{}, not %T", i, item) - } - } - } - return nil -} - -func testResourceConfigModeUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceConfigModeRead(d, meta) -} - -func testResourceConfigModeDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_defaults.go b/internal/legacy/builtin/providers/test/resource_defaults.go deleted file mode 100644 index f46a4bb02..000000000 --- a/internal/legacy/builtin/providers/test/resource_defaults.go +++ /dev/null @@ -1,70 +0,0 @@ -package test - -import ( - "fmt" - "math/rand" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceDefaults() *schema.Resource { - return &schema.Resource{ - Create: testResourceDefaultsCreate, - Read: testResourceDefaultsRead, - Delete: testResourceDefaultsDelete, - Update: testResourceDefaultsUpdate, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "default_string": { - Type: schema.TypeString, - Optional: true, - Default: "default string", - }, - "default_bool": { - Type: schema.TypeString, - Optional: true, - Default: true, - }, - "nested": { - Type: schema.TypeSet, - Optional: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "string": { - Type: schema.TypeString, - Optional: true, - Default: "default nested", - }, - "optional": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - }, - } -} - -func testResourceDefaultsCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId(fmt.Sprintf("%x", rand.Int63())) - return testResourceDefaultsRead(d, meta) -} - -func testResourceDefaultsUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceDefaultsRead(d, meta) -} - -func testResourceDefaultsRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceDefaultsDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_deprecated.go b/internal/legacy/builtin/providers/test/resource_deprecated.go deleted file mode 100644 index d78722208..000000000 --- a/internal/legacy/builtin/providers/test/resource_deprecated.go +++ /dev/null @@ -1,119 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceDeprecated() *schema.Resource { - return &schema.Resource{ - Create: testResourceDeprecatedCreate, - Read: testResourceDeprecatedRead, - Update: testResourceDeprecatedUpdate, - Delete: testResourceDeprecatedDelete, - - Schema: map[string]*schema.Schema{ - "map_deprecated": { - Type: schema.TypeMap, - Optional: true, - Deprecated: "deprecated", - }, - "map_removed": { - Type: schema.TypeMap, - Optional: true, - Removed: "removed", - }, - "set_block_deprecated": { - Type: schema.TypeSet, - Optional: true, - MaxItems: 1, - Deprecated: "deprecated", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - Required: true, - Deprecated: "deprecated", - }, - "optional": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Deprecated: "deprecated", - }, - }, - }, - }, - "set_block_removed": { - Type: schema.TypeSet, - Optional: true, - MaxItems: 1, - Removed: "Removed", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Computed: true, - Removed: "removed", - }, - }, - }, - }, - "list_block_deprecated": { - Type: schema.TypeList, - Optional: true, - Deprecated: "deprecated", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - Required: true, - Deprecated: "deprecated", - }, - "optional": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Deprecated: "deprecated", - }, - }, - }, - }, - "list_block_removed": { - Type: schema.TypeList, - Optional: true, - Removed: "removed", - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Removed: "removed", - }, - }, - }, - }, - }, - } -} - -func testResourceDeprecatedCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - return nil -} - -func testResourceDeprecatedRead(d *schema.ResourceData, meta interface{}) error { - - return nil -} - -func testResourceDeprecatedUpdate(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceDeprecatedDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_diff_suppress.go b/internal/legacy/builtin/providers/test/resource_diff_suppress.go deleted file mode 100644 index 309cc4488..000000000 --- a/internal/legacy/builtin/providers/test/resource_diff_suppress.go +++ /dev/null @@ -1,104 +0,0 @@ -package test - -import ( - "fmt" - "math/rand" - "strings" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceDiffSuppress() *schema.Resource { - diffSuppress := func(k, old, new string, d *schema.ResourceData) bool { - if old == "" || strings.Contains(new, "replace") { - return false - } - return true - } - - return &schema.Resource{ - Create: testResourceDiffSuppressCreate, - Read: testResourceDiffSuppressRead, - Delete: testResourceDiffSuppressDelete, - Update: testResourceDiffSuppressUpdate, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeString, - Optional: true, - }, - "val_to_upper": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - StateFunc: func(val interface{}) string { - return strings.ToUpper(val.(string)) - }, - DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { - return strings.ToUpper(old) == strings.ToUpper(new) - }, - }, - "network": { - Type: schema.TypeString, - Optional: true, - Default: "default", - ForceNew: true, - DiffSuppressFunc: diffSuppress, - }, - "subnetwork": { - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - DiffSuppressFunc: diffSuppress, - }, - - "node_pool": { - Type: schema.TypeList, - Optional: true, - Computed: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - Computed: true, - ForceNew: true, - }, - }, - }, - }, - }, - } -} - -func testResourceDiffSuppressCreate(d *schema.ResourceData, meta interface{}) error { - d.Set("network", "modified") - d.Set("subnetwork", "modified") - - if _, ok := d.GetOk("node_pool"); !ok { - d.Set("node_pool", []string{}) - } - - id := fmt.Sprintf("%x", rand.Int63()) - d.SetId(id) - return nil -} - -func testResourceDiffSuppressRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceDiffSuppressUpdate(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceDiffSuppressDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_force_new.go b/internal/legacy/builtin/providers/test/resource_force_new.go deleted file mode 100644 index 85721141e..000000000 --- a/internal/legacy/builtin/providers/test/resource_force_new.go +++ /dev/null @@ -1,39 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceForceNew() *schema.Resource { - return &schema.Resource{ - Create: testResourceForceNewCreate, - Read: testResourceForceNewRead, - Delete: testResourceForceNewDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "triggers": { - Type: schema.TypeMap, - Optional: true, - ForceNew: true, - }, - }, - } -} - -func testResourceForceNewCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - return testResourceForceNewRead(d, meta) -} - -func testResourceForceNewRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceForceNewDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_gh12183.go b/internal/legacy/builtin/providers/test/resource_gh12183.go deleted file mode 100644 index f75fbe2e9..000000000 --- a/internal/legacy/builtin/providers/test/resource_gh12183.go +++ /dev/null @@ -1,64 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -// This is a test resource to help reproduce GH-12183. This issue came up -// as a complex mixing of core + helper/schema and while we added core tests -// to cover some of the cases, this test helps top it off with an end-to-end -// test. -func testResourceGH12183() *schema.Resource { - return &schema.Resource{ - Create: testResourceCreate_gh12183, - Read: testResourceRead_gh12183, - Update: testResourceUpdate_gh12183, - Delete: testResourceDelete_gh12183, - Schema: map[string]*schema.Schema{ - "key": &schema.Schema{ - Type: schema.TypeString, - Optional: true, - }, - - "config": &schema.Schema{ - Type: schema.TypeList, - Optional: true, - ForceNew: true, - MinItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - - "rules": { - Type: schema.TypeSet, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - Set: schema.HashString, - }, - }, - }, - }, - }, - } -} - -func testResourceCreate_gh12183(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - return testResourceRead_gh12183(d, meta) -} - -func testResourceRead_gh12183(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceUpdate_gh12183(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceDelete_gh12183(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_list.go b/internal/legacy/builtin/providers/test/resource_list.go deleted file mode 100644 index 9c69f915c..000000000 --- a/internal/legacy/builtin/providers/test/resource_list.go +++ /dev/null @@ -1,192 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceList() *schema.Resource { - return &schema.Resource{ - Create: testResourceListCreate, - Read: testResourceListRead, - Update: testResourceListUpdate, - Delete: testResourceListDelete, - - CustomizeDiff: func(d *schema.ResourceDiff, _ interface{}) error { - if d.HasChange("dependent_list") { - d.SetNewComputed("computed_list") - } - return nil - }, - - Schema: map[string]*schema.Schema{ - "list_block": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "string": { - Type: schema.TypeString, - Optional: true, - }, - "int": { - Type: schema.TypeInt, - Optional: true, - }, - "force_new": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "sublist": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "sublist_block": { - Type: schema.TypeList, - Optional: true, - Computed: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "string": { - Type: schema.TypeString, - Required: true, - }, - "int": { - Type: schema.TypeInt, - Required: true, - }, - }, - }, - }, - "sublist_block_optional": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "list": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - }, - }, - }, - "dependent_list": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "val": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - "computed_list": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "min_items": { - Type: schema.TypeList, - Optional: true, - MinItems: 2, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "val": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - "never_set": { - Type: schema.TypeList, - MaxItems: 1, - Optional: true, - Computed: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "sublist": { - Type: schema.TypeList, - MaxItems: 1, - ForceNew: true, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "bool": { - Type: schema.TypeBool, - ForceNew: true, - Required: true, - }, - "string": { - Type: schema.TypeString, - Computed: true, - }, - }, - }, - }, - }, - }, - }, - "map_list": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeMap}, - }, - }, - } -} - -func testResourceListCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - return testResourceListRead(d, meta) -} - -func testResourceListRead(d *schema.ResourceData, meta interface{}) error { - fixedIps := d.Get("dependent_list") - - // all_fixed_ips should be set as computed with a CustomizeDiff func, but - // we're trying to emulate legacy provider behavior, and updating a - // computed field was a common case. - ips := []interface{}{} - if fixedIps != nil { - for _, v := range fixedIps.([]interface{}) { - m := v.(map[string]interface{}) - ips = append(ips, m["val"]) - } - } - if err := d.Set("computed_list", ips); err != nil { - return err - } - - // "computing" these values should insert empty containers into the - // never_set block. - values := make(map[string]interface{}) - values["sublist"] = []interface{}{} - d.Set("never_set", []interface{}{values}) - - return nil -} - -func testResourceListUpdate(d *schema.ResourceData, meta interface{}) error { - block := d.Get("never_set").([]interface{}) - if len(block) > 0 { - // if profiles contains any values, they should not be nil - _ = block[0].(map[string]interface{}) - } - return testResourceListRead(d, meta) -} - -func testResourceListDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_list_set.go b/internal/legacy/builtin/providers/test/resource_list_set.go deleted file mode 100644 index fe54d9235..000000000 --- a/internal/legacy/builtin/providers/test/resource_list_set.go +++ /dev/null @@ -1,192 +0,0 @@ -package test - -import ( - "fmt" - "math/rand" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceListSet() *schema.Resource { - return &schema.Resource{ - Create: testResourceListSetCreate, - Read: testResourceListSetRead, - Delete: testResourceListSetDelete, - Update: testResourceListSetUpdate, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "list": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "set": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "elem": { - Type: schema.TypeString, - Optional: true, - DiffSuppressFunc: func(_, o, n string, _ *schema.ResourceData) bool { - return o == n - }, - }, - }, - }, - Set: func(v interface{}) int { - raw := v.(map[string]interface{}) - if el, ok := raw["elem"]; ok { - return schema.HashString(el) - } - return 42 - }, - }, - }, - }, - }, - "replication_configuration": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "role": { - Type: schema.TypeString, - Required: true, - }, - "rules": { - Type: schema.TypeSet, - Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Optional: true, - }, - "destination": { - Type: schema.TypeSet, - MaxItems: 1, - MinItems: 1, - Required: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "account_id": { - Type: schema.TypeString, - Optional: true, - }, - "bucket": { - Type: schema.TypeString, - Required: true, - }, - "storage_class": { - Type: schema.TypeString, - Optional: true, - }, - "replica_kms_key_id": { - Type: schema.TypeString, - Optional: true, - }, - "access_control_translation": { - Type: schema.TypeList, - Optional: true, - MinItems: 1, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "owner": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - }, - }, - }, - "source_selection_criteria": { - Type: schema.TypeSet, - Optional: true, - MinItems: 1, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "sse_kms_encrypted_objects": { - Type: schema.TypeSet, - Optional: true, - MinItems: 1, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "enabled": { - Type: schema.TypeBool, - Required: true, - }, - }, - }, - }, - }, - }, - }, - "prefix": { - Type: schema.TypeString, - Optional: true, - }, - "status": { - Type: schema.TypeString, - Required: true, - }, - "priority": { - Type: schema.TypeInt, - Optional: true, - }, - "filter": { - Type: schema.TypeList, - Optional: true, - MinItems: 1, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "prefix": { - Type: schema.TypeString, - Optional: true, - }, - "tags": { - Type: schema.TypeMap, - Optional: true, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - }, - } -} - -func testResourceListSetCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId(fmt.Sprintf("%x", rand.Int63())) - return testResourceListSetRead(d, meta) -} - -func testResourceListSetUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceListSetRead(d, meta) -} - -func testResourceListSetRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceListSetDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_map.go b/internal/legacy/builtin/providers/test/resource_map.go deleted file mode 100644 index fe1ece1e9..000000000 --- a/internal/legacy/builtin/providers/test/resource_map.go +++ /dev/null @@ -1,77 +0,0 @@ -package test - -import ( - "fmt" - - "github.com/hashicorp/terraform/configs/hcl2shim" - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceMap() *schema.Resource { - return &schema.Resource{ - Create: testResourceMapCreate, - Read: testResourceMapRead, - Update: testResourceMapUpdate, - Delete: testResourceMapDelete, - - Schema: map[string]*schema.Schema{ - "name": { - Type: schema.TypeString, - Required: true, - }, - "map_of_three": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - ValidateFunc: func(v interface{}, _ string) ([]string, []error) { - errs := []error{} - for k, v := range v.(map[string]interface{}) { - if v == hcl2shim.UnknownVariableValue { - errs = append(errs, fmt.Errorf("unknown value in ValidateFunc: %q=%q", k, v)) - } - } - return nil, errs - }, - }, - "map_values": { - Type: schema.TypeMap, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - "computed_map": { - Type: schema.TypeMap, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - } -} - -func testResourceMapCreate(d *schema.ResourceData, meta interface{}) error { - // make sure all elements are passed to the map - m := d.Get("map_of_three").(map[string]interface{}) - if len(m) != 3 { - return fmt.Errorf("expected 3 map values, got %#v\n", m) - } - - d.SetId("testId") - return testResourceMapRead(d, meta) -} - -func testResourceMapRead(d *schema.ResourceData, meta interface{}) error { - var computedMap map[string]interface{} - if v, ok := d.GetOk("map_values"); ok { - computedMap = v.(map[string]interface{}) - } - d.Set("computed_map", computedMap) - return nil -} - -func testResourceMapUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceMapRead(d, meta) -} - -func testResourceMapDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_nested.go b/internal/legacy/builtin/providers/test/resource_nested.go deleted file mode 100644 index c78274d53..000000000 --- a/internal/legacy/builtin/providers/test/resource_nested.go +++ /dev/null @@ -1,114 +0,0 @@ -package test - -import ( - "fmt" - "math/rand" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceNested() *schema.Resource { - return &schema.Resource{ - Create: testResourceNestedCreate, - Read: testResourceNestedRead, - Delete: testResourceNestedDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - }, - "nested": { - Type: schema.TypeSet, - Optional: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "string": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "optional": { - Type: schema.TypeBool, - Optional: true, - ForceNew: true, - }, - "nested_again": { - Type: schema.TypeSet, - Optional: true, - ForceNew: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "string": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - }, - }, - }, - }, - }, - }, - "list_block": { - Type: schema.TypeList, - Optional: true, - Computed: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "sub_list_block": { - Type: schema.TypeList, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "bool": { - Type: schema.TypeBool, - Optional: true, - }, - "set": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - }, - }, - }, - }, - }, - }, - } -} - -func testResourceNestedCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId(fmt.Sprintf("%x", rand.Int63())) - return testResourceNestedRead(d, meta) -} - -func testResourceNestedUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceNestedRead(d, meta) -} - -func testResourceNestedRead(d *schema.ResourceData, meta interface{}) error { - set := []map[string]interface{}{map[string]interface{}{ - "sub_list_block": []map[string]interface{}{map[string]interface{}{ - "bool": false, - "set": schema.NewSet(schema.HashString, nil), - }}, - }} - d.Set("list_block", set) - return nil -} - -func testResourceNestedDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_nested_id.go b/internal/legacy/builtin/providers/test/resource_nested_id.go deleted file mode 100644 index f5a2d9bf9..000000000 --- a/internal/legacy/builtin/providers/test/resource_nested_id.go +++ /dev/null @@ -1,48 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceNestedId() *schema.Resource { - return &schema.Resource{ - Create: testResourceNestedIdCreate, - Read: testResourceNestedIdRead, - Update: testResourceNestedIdUpdate, - Delete: testResourceNestedIdDelete, - - Schema: map[string]*schema.Schema{ - "list_block": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "id": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - }, - }, - }, - }, - } -} - -func testResourceNestedIdCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - return nil -} - -func testResourceNestedIdRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceNestedIdUpdate(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceNestedIdDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_nested_set.go b/internal/legacy/builtin/providers/test/resource_nested_set.go deleted file mode 100644 index 4a1253400..000000000 --- a/internal/legacy/builtin/providers/test/resource_nested_set.go +++ /dev/null @@ -1,171 +0,0 @@ -package test - -import ( - "fmt" - "math/rand" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceNestedSet() *schema.Resource { - return &schema.Resource{ - Create: testResourceNestedSetCreate, - Read: testResourceNestedSetRead, - Delete: testResourceNestedSetDelete, - Update: testResourceNestedSetUpdate, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeBool, - Optional: true, - }, - "force_new": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - }, - "type_list": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - }, - }, - }, - }, - "single": { - Type: schema.TypeSet, - Optional: true, - MaxItems: 1, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "value": { - Type: schema.TypeString, - ForceNew: true, - Required: true, - }, - - "optional": { - Type: schema.TypeString, - ForceNew: true, - Optional: true, - Computed: true, - }, - }, - }, - }, - "multi": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "set": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "required": { - Type: schema.TypeString, - Required: true, - ForceNew: true, - }, - "optional_int": { - Type: schema.TypeInt, - Optional: true, - }, - "bool": { - Type: schema.TypeBool, - Optional: true, - }, - }, - }, - }, - - "optional": { - Type: schema.TypeString, - // commenting this causes it to get missed during apply - //ForceNew: true, - Optional: true, - }, - "bool": { - Type: schema.TypeBool, - Optional: true, - }, - }, - }, - }, - "with_list": { - Type: schema.TypeSet, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "required": { - Type: schema.TypeString, - Required: true, - }, - "list": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Schema{ - Type: schema.TypeString, - }, - }, - "list_block": { - Type: schema.TypeList, - Optional: true, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "unused": { - Type: schema.TypeString, - Optional: true, - }, - }, - }, - }, - }, - }, - }, - }, - } -} - -func testResourceNestedSetCreate(d *schema.ResourceData, meta interface{}) error { - id := fmt.Sprintf("%x", rand.Int63()) - d.SetId(id) - - // replicate some awkward handling of a computed value in a set - set := d.Get("single").(*schema.Set) - l := set.List() - if len(l) == 1 { - if s, ok := l[0].(map[string]interface{}); ok { - if v, _ := s["optional"].(string); v == "" { - s["optional"] = id - } - } - } - - d.Set("single", set) - - return testResourceNestedSetRead(d, meta) -} - -func testResourceNestedSetRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceNestedSetDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} - -func testResourceNestedSetUpdate(d *schema.ResourceData, meta interface{}) error { - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_provider_meta.go b/internal/legacy/builtin/providers/test/resource_provider_meta.go deleted file mode 100644 index c900c5159..000000000 --- a/internal/legacy/builtin/providers/test/resource_provider_meta.go +++ /dev/null @@ -1,95 +0,0 @@ -package test - -import ( - "fmt" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceProviderMeta() *schema.Resource { - return &schema.Resource{ - Create: testResourceProviderMetaCreate, - Read: testResourceProviderMetaRead, - Update: testResourceProviderMetaUpdate, - Delete: testResourceProviderMetaDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeString, - Optional: true, - }, - }, - } -} - -type providerMeta struct { - Foo string `cty:"foo"` -} - -func testResourceProviderMetaCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - var m providerMeta - - err := d.GetProviderMeta(&m) - if err != nil { - return err - } - - if m.Foo != "bar" { - return fmt.Errorf("expected provider_meta.foo to be %q, was %q", - "bar", m.Foo) - } - - return testResourceProviderMetaRead(d, meta) -} - -func testResourceProviderMetaRead(d *schema.ResourceData, meta interface{}) error { - var m providerMeta - - err := d.GetProviderMeta(&m) - if err != nil { - return err - } - - if m.Foo != "bar" { - return fmt.Errorf("expected provider_meta.foo to be %q, was %q", - "bar", m.Foo) - } - - return nil -} - -func testResourceProviderMetaUpdate(d *schema.ResourceData, meta interface{}) error { - var m providerMeta - - err := d.GetProviderMeta(&m) - if err != nil { - return err - } - - if m.Foo != "bar" { - return fmt.Errorf("expected provider_meta.foo to be %q, was %q", - "bar", m.Foo) - } - return testResourceProviderMetaRead(d, meta) -} - -func testResourceProviderMetaDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - var m providerMeta - - err := d.GetProviderMeta(&m) - if err != nil { - return err - } - - if m.Foo != "bar" { - return fmt.Errorf("expected provider_meta.foo to be %q, was %q", - "bar", m.Foo) - } - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_required_min.go b/internal/legacy/builtin/providers/test/resource_required_min.go deleted file mode 100644 index 23419ed02..000000000 --- a/internal/legacy/builtin/providers/test/resource_required_min.go +++ /dev/null @@ -1,68 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceRequiredMin() *schema.Resource { - return &schema.Resource{ - Create: testResourceRequiredMinCreate, - Read: testResourceRequiredMinRead, - Update: testResourceRequiredMinUpdate, - Delete: testResourceRequiredMinDelete, - - CustomizeDiff: func(d *schema.ResourceDiff, _ interface{}) error { - if d.HasChange("dependent_list") { - d.SetNewComputed("computed_list") - } - return nil - }, - - Schema: map[string]*schema.Schema{ - "min_items": { - Type: schema.TypeList, - Optional: true, - MinItems: 2, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "val": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - "required_min_items": { - Type: schema.TypeList, - Required: true, - MinItems: 2, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "val": { - Type: schema.TypeString, - Required: true, - }, - }, - }, - }, - }, - } -} - -func testResourceRequiredMinCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - return testResourceRequiredMinRead(d, meta) -} - -func testResourceRequiredMinRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceRequiredMinUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceRequiredMinRead(d, meta) -} - -func testResourceRequiredMinDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_signal.go b/internal/legacy/builtin/providers/test/resource_signal.go deleted file mode 100644 index 398a996cd..000000000 --- a/internal/legacy/builtin/providers/test/resource_signal.go +++ /dev/null @@ -1,43 +0,0 @@ -package test - -import ( - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceSignal() *schema.Resource { - return &schema.Resource{ - Create: testResourceSignalCreate, - Read: testResourceSignalRead, - Update: testResourceSignalUpdate, - Delete: testResourceSignalDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeString, - Optional: true, - }, - }, - } -} - -func testResourceSignalCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - - return testResourceSignalRead(d, meta) -} - -func testResourceSignalRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceSignalUpdate(d *schema.ResourceData, meta interface{}) error { - return testResourceSignalRead(d, meta) -} - -func testResourceSignalDelete(d *schema.ResourceData, meta interface{}) error { - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_state_func.go b/internal/legacy/builtin/providers/test/resource_state_func.go deleted file mode 100644 index 9589f102e..000000000 --- a/internal/legacy/builtin/providers/test/resource_state_func.go +++ /dev/null @@ -1,118 +0,0 @@ -package test - -import ( - "crypto/sha1" - "encoding/hex" - "fmt" - "math/rand" - - "github.com/hashicorp/terraform/helper/hashcode" - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceStateFunc() *schema.Resource { - return &schema.Resource{ - Create: testResourceStateFuncCreate, - Read: testResourceStateFuncRead, - Update: testResourceStateFuncUpdate, - Delete: testResourceStateFuncDelete, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "optional": { - Type: schema.TypeString, - Optional: true, - }, - "state_func": { - Type: schema.TypeString, - Optional: true, - ForceNew: true, - StateFunc: stateFuncHash, - }, - "state_func_value": { - Type: schema.TypeString, - Optional: true, - }, - - // set block with computed elements - "set_block": { - Type: schema.TypeSet, - Optional: true, - Set: setBlockHash, - Elem: &schema.Resource{ - Schema: map[string]*schema.Schema{ - "required": { - Type: schema.TypeString, - Required: true, - }, - "optional": { - Type: schema.TypeString, - Optional: true, - Computed: true, - }, - }, - }, - }, - }, - } -} - -func stateFuncHash(v interface{}) string { - hash := sha1.Sum([]byte(v.(string))) - return hex.EncodeToString(hash[:]) -} - -func setBlockHash(v interface{}) int { - m := v.(map[string]interface{}) - required, _ := m["required"].(string) - optional, _ := m["optional"].(string) - return hashcode.String(fmt.Sprintf("%s|%s", required, optional)) -} - -func testResourceStateFuncCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId(fmt.Sprintf("%x", rand.Int63())) - - // if we have a reference for the actual data in the state_func field, - // compare it - if data, ok := d.GetOk("state_func_value"); ok { - expected := data.(string) - got := d.Get("state_func").(string) - if expected != got { - return fmt.Errorf("expected state_func value:%q, got%q", expected, got) - } - } - - // Check that we can lookup set elements by our computed hash. - // This is not advised, but we can use this to make sure the final diff was - // prepared with the correct values. - setBlock, ok := d.GetOk("set_block") - if ok { - set := setBlock.(*schema.Set) - for _, obj := range set.List() { - idx := setBlockHash(obj) - requiredAddr := fmt.Sprintf("%s.%d.%s", "set_block", idx, "required") - _, ok := d.GetOkExists(requiredAddr) - if !ok { - return fmt.Errorf("failed to get attr %q from %#v", fmt.Sprintf(requiredAddr), d.State().Attributes) - } - } - } - - return testResourceStateFuncRead(d, meta) -} - -func testResourceStateFuncRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceStateFuncUpdate(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceStateFuncDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_timeout.go b/internal/legacy/builtin/providers/test/resource_timeout.go deleted file mode 100644 index 17a6da0eb..000000000 --- a/internal/legacy/builtin/providers/test/resource_timeout.go +++ /dev/null @@ -1,125 +0,0 @@ -package test - -import ( - "fmt" - "time" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceTimeout() *schema.Resource { - return &schema.Resource{ - Create: testResourceTimeoutCreate, - Read: testResourceTimeoutRead, - Update: testResourceTimeoutUpdate, - Delete: testResourceTimeoutDelete, - - // Due to the schema version also being stashed in the private/meta - // data, we need to ensure that it does not overwrite the map - // containing the timeouts. - SchemaVersion: 1, - - Timeouts: &schema.ResourceTimeout{ - Create: schema.DefaultTimeout(time.Second), - Update: schema.DefaultTimeout(time.Second), - Delete: schema.DefaultTimeout(time.Second), - }, - - Importer: &schema.ResourceImporter{ - State: schema.ImportStatePassthrough, - }, - - Schema: map[string]*schema.Schema{ - "create_delay": { - Type: schema.TypeString, - Optional: true, - }, - "read_delay": { - Type: schema.TypeString, - Optional: true, - }, - "update_delay": { - Type: schema.TypeString, - Optional: true, - }, - "delete_delay": { - Type: schema.TypeString, - Optional: true, - }, - }, - } -} - -func testResourceTimeoutCreate(d *schema.ResourceData, meta interface{}) error { - delayString := d.Get("create_delay").(string) - var delay time.Duration - var err error - if delayString != "" { - delay, err = time.ParseDuration(delayString) - if err != nil { - return err - } - } - - if delay > d.Timeout(schema.TimeoutCreate) { - return fmt.Errorf("timeout while creating resource") - } - - d.SetId("testId") - - return testResourceRead(d, meta) -} - -func testResourceTimeoutRead(d *schema.ResourceData, meta interface{}) error { - delayString := d.Get("read_delay").(string) - var delay time.Duration - var err error - if delayString != "" { - delay, err = time.ParseDuration(delayString) - if err != nil { - return err - } - } - - if delay > d.Timeout(schema.TimeoutRead) { - return fmt.Errorf("timeout while reading resource") - } - - return nil -} - -func testResourceTimeoutUpdate(d *schema.ResourceData, meta interface{}) error { - delayString := d.Get("update_delay").(string) - var delay time.Duration - var err error - if delayString != "" { - delay, err = time.ParseDuration(delayString) - if err != nil { - return err - } - } - - if delay > d.Timeout(schema.TimeoutUpdate) { - return fmt.Errorf("timeout while updating resource") - } - return nil -} - -func testResourceTimeoutDelete(d *schema.ResourceData, meta interface{}) error { - delayString := d.Get("delete_delay").(string) - var delay time.Duration - var err error - if delayString != "" { - delay, err = time.ParseDuration(delayString) - if err != nil { - return err - } - } - - if delay > d.Timeout(schema.TimeoutDelete) { - return fmt.Errorf("timeout while deleting resource") - } - - d.SetId("") - return nil -} diff --git a/internal/legacy/builtin/providers/test/resource_undeletable.go b/internal/legacy/builtin/providers/test/resource_undeletable.go deleted file mode 100644 index b4be0bff3..000000000 --- a/internal/legacy/builtin/providers/test/resource_undeletable.go +++ /dev/null @@ -1,30 +0,0 @@ -package test - -import ( - "fmt" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceUndeleteable() *schema.Resource { - return &schema.Resource{ - Create: testResourceUndeleteableCreate, - Read: testResourceUndeleteableRead, - Delete: testResourceUndeleteableDelete, - - Schema: map[string]*schema.Schema{}, - } -} - -func testResourceUndeleteableCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("placeholder") - return testResourceUndeleteableRead(d, meta) -} - -func testResourceUndeleteableRead(d *schema.ResourceData, meta interface{}) error { - return nil -} - -func testResourceUndeleteableDelete(d *schema.ResourceData, meta interface{}) error { - return fmt.Errorf("test_undeleteable always fails deletion (use terraform state rm if you really want to delete it)") -} diff --git a/internal/legacy/builtin/providers/test/resource_with_custom_diff.go b/internal/legacy/builtin/providers/test/resource_with_custom_diff.go deleted file mode 100644 index 397e0795e..000000000 --- a/internal/legacy/builtin/providers/test/resource_with_custom_diff.go +++ /dev/null @@ -1,154 +0,0 @@ -package test - -import ( - "fmt" - - "github.com/hashicorp/terraform/internal/legacy/helper/schema" -) - -func testResourceCustomDiff() *schema.Resource { - return &schema.Resource{ - Create: testResourceCustomDiffCreate, - Read: testResourceCustomDiffRead, - CustomizeDiff: testResourceCustomDiffCustomizeDiff, - Update: testResourceCustomDiffUpdate, - Delete: testResourceCustomDiffDelete, - Schema: map[string]*schema.Schema{ - "required": { - Type: schema.TypeString, - Required: true, - }, - "computed": { - Type: schema.TypeInt, - Computed: true, - }, - "index": { - Type: schema.TypeInt, - Computed: true, - }, - "veto": { - Type: schema.TypeBool, - Optional: true, - }, - "list": { - Type: schema.TypeList, - Computed: true, - Elem: &schema.Schema{Type: schema.TypeString}, - }, - }, - } -} - -type listDiffCases struct { - Type string - Value string -} - -func testListDiffCases(index int) []listDiffCases { - switch index { - case 0: - return []listDiffCases{ - { - Type: "add", - Value: "dc1", - }, - } - case 1: - return []listDiffCases{ - { - Type: "remove", - Value: "dc1", - }, - { - Type: "add", - Value: "dc2", - }, - { - Type: "add", - Value: "dc3", - }, - } - } - return nil -} - -func testListDiffCasesReadResult(index int) []interface{} { - switch index { - case 1: - return []interface{}{"dc1"} - default: - return []interface{}{"dc2", "dc3"} - } -} - -func testResourceCustomDiffCreate(d *schema.ResourceData, meta interface{}) error { - d.SetId("testId") - - // Required must make it through to Create - if _, ok := d.GetOk("required"); !ok { - return fmt.Errorf("missing attribute 'required', but it's required") - } - - _, new := d.GetChange("computed") - expected := new.(int) - 1 - actual := d.Get("index").(int) - if expected != actual { - return fmt.Errorf("expected computed to be 1 ahead of index, got computed: %d, index: %d", expected, actual) - } - d.Set("index", new) - - return testResourceCustomDiffRead(d, meta) -} - -func testResourceCustomDiffRead(d *schema.ResourceData, meta interface{}) error { - if err := d.Set("list", testListDiffCasesReadResult(d.Get("index").(int))); err != nil { - return err - } - return nil -} - -func testResourceCustomDiffCustomizeDiff(d *schema.ResourceDiff, meta interface{}) error { - if d.Get("veto").(bool) == true { - return fmt.Errorf("veto is true, diff vetoed") - } - // Note that this gets put into state after the update, regardless of whether - // or not anything is acted upon in the diff. - d.SetNew("computed", d.Get("computed").(int)+1) - - // This tests a diffed list, based off of the value of index - dcs := testListDiffCases(d.Get("index").(int)) - s := d.Get("list").([]interface{}) - for _, dc := range dcs { - switch dc.Type { - case "add": - s = append(s, dc.Value) - case "remove": - for i := range s { - if s[i].(string) == dc.Value { - copy(s[i:], s[i+1:]) - s = s[:len(s)-1] - break - } - } - } - } - d.SetNew("list", s) - - return nil -} - -func testResourceCustomDiffUpdate(d *schema.ResourceData, meta interface{}) error { - _, new := d.GetChange("computed") - expected := new.(int) - 1 - actual := d.Get("index").(int) - if expected != actual { - return fmt.Errorf("expected computed to be 1 ahead of index, got computed: %d, index: %d", expected, actual) - } - d.Set("index", new) - return testResourceCustomDiffRead(d, meta) -} - -func testResourceCustomDiffDelete(d *schema.ResourceData, meta interface{}) error { - d.SetId("") - return nil -}