diff --git a/go.mod b/go.mod index 20d07bc3c..12096ab47 100644 --- a/go.mod +++ b/go.mod @@ -6,7 +6,7 @@ require ( github.com/hashicorp/go-getter v1.4.2-0.20200106182914-9813cbd4eb02 // indirect github.com/hashicorp/hcl/v2 v2.3.0 // indirect github.com/hashicorp/terraform-config-inspect v0.0.0-20191212124732-c6ae6269b9d7 // indirect - github.com/hashicorp/terraform-plugin-sdk v1.9.1 + github.com/hashicorp/terraform-plugin-sdk v1.11.0 github.com/linode/linodego v0.15.0 golang.org/x/crypto v0.0.0-20200220183623-bac4c82f6975 golang.org/x/oauth2 v0.0.0-20200107190931-bf48bf16ab8d diff --git a/go.sum b/go.sum index 192634e6a..3a4114a5e 100644 --- a/go.sum +++ b/go.sum @@ -268,10 +268,12 @@ github.com/hashicorp/terraform-json v0.4.0 h1:KNh29iNxozP5adfUFBJ4/fWd0Cu3taGgjH github.com/hashicorp/terraform-json v0.4.0/go.mod h1:eAbqb4w0pSlRmdvl8fOyHAi/+8jnkVYN28gJkSJrLhU= github.com/hashicorp/terraform-plugin-sdk v1.7.0 h1:B//oq0ZORG+EkVrIJy0uPGSonvmXqxSzXe8+GhknoW0= github.com/hashicorp/terraform-plugin-sdk v1.7.0/go.mod h1:OjgQmey5VxnPej/buEhe+YqKm0KNvV3QqU4hkqHqPCY= -github.com/hashicorp/terraform-plugin-sdk v1.9.1 h1:AgHnd6yPCg7o57XWrv4L7tIMdF0KQpcZro1pDHF1Xbw= -github.com/hashicorp/terraform-plugin-sdk v1.9.1/go.mod h1:C/AXwmDHqbc3h6URiHpIsVKrwV4PS0Sh0+VTaeEkShw= +github.com/hashicorp/terraform-plugin-sdk v1.11.0 h1:qAI27eiSdIm0D+GCdlyGwtcWAYkjdVWC7OdS/3XcJq4= +github.com/hashicorp/terraform-plugin-sdk v1.11.0/go.mod h1:HiWIPD/T9HixIhQUwaSoDQxo4BLFdmiBi/Qz5gjB8Q0= github.com/hashicorp/terraform-plugin-test v1.2.0 h1:AWFdqyfnOj04sxTdaAF57QqvW7XXrT8PseUHkbKsE8I= github.com/hashicorp/terraform-plugin-test v1.2.0/go.mod h1:QIJHYz8j+xJtdtLrFTlzQVC0ocr3rf/OjIpgZLK56Hs= +github.com/hashicorp/terraform-plugin-test v1.3.0 h1:hU5LoxrOn9qvOo+LTKN6mSav2J+dAMprbdxJPEQvp4U= +github.com/hashicorp/terraform-plugin-test v1.3.0/go.mod h1:QIJHYz8j+xJtdtLrFTlzQVC0ocr3rf/OjIpgZLK56Hs= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 h1:hjyO2JsNZUKT1ym+FAdlBEkGPevazYsmVgIMw7dVELg= github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596/go.mod h1:kNDNcF7sN4DocDLBkQYz73HGKwN1ANB1blq4lIYLYvg= github.com/hashicorp/yamux v0.0.0-20180604194846-3520598351bb/go.mod h1:+NfK9FKeTrX5uv1uIXGdwYDTeHna2qgaIlx54MXqjAM= diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/acctest/doc.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/acctest/doc.go new file mode 100644 index 000000000..08bff3c88 --- /dev/null +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/acctest/doc.go @@ -0,0 +1,31 @@ +// Package acctest provides the ability to opt in to the new binary test driver. The binary +// test driver allows you to run your acceptance tests with a binary of Terraform instead of +// an emulated version packaged inside the SDK. This allows for a number of important +// enhancements, but most notably a more realistic testing experience and matrix testing +// against multiple versions of Terraform CLI. This also allows the SDK to be completely +// separated, at a dependency level, from the Terraform CLI, as long as it is >= 0.12.0 +// +// The new test driver must be enabled by initialising the test helper in your TestMain +// function in all provider packages that run acceptance tests. Most providers have only +// one package. +// +// In v2 of the SDK, the binary test driver will be mandatory. +// +// After importing this package, you can add code similar to the following: +// +// func TestMain(m *testing.M) { +// acctest.UseBinaryDriver("provider_name", Provider) +// resource.TestMain(m) +// } +// +// Where `Provider` is the function that returns the instance of a configured `terraform.ResourceProvider` +// Some providers already have a TestMain defined, usually for the purpose of enabling test +// sweepers. These additional occurrences should be removed. +// +// Initialising the binary test helper using UseBinaryDriver causes all tests to be run using +// the new binary driver. Until SDK v2, the DisableBinaryDriver boolean property can be used +// to use the legacy test driver for an individual TestCase. +// +// It is no longer necessary to import other Terraform providers as Go modules: these +// imports should be removed. +package acctest diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing.go index ecea64c61..13ac7078e 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing.go @@ -12,6 +12,7 @@ import ( "path/filepath" "reflect" "regexp" + "strconv" "strings" "syscall" "testing" @@ -558,7 +559,6 @@ func Test(t TestT, c TestCase) { // We require verbose mode so that the user knows what is going on. if !testTesting && !testing.Verbose() && !c.IsUnitTest { t.Fatal("Acceptance tests must be run with the -v flag on tests") - return } // get instances of all providers, so we can use the individual @@ -1021,28 +1021,28 @@ func ComposeAggregateTestCheckFunc(fs ...TestCheckFunc) TestCheckFunc { // testing that computed values were set, when it is not possible to // know ahead of time what the values will be. func TestCheckResourceAttrSet(name, key string) TestCheckFunc { - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := primaryInstanceState(s, name) if err != nil { return err } return testCheckResourceAttrSet(is, name, key) - } + }) } // TestCheckModuleResourceAttrSet - as per TestCheckResourceAttrSet but with // support for non-root modules func TestCheckModuleResourceAttrSet(mp []string, name string, key string) TestCheckFunc { mpt := addrs.Module(mp).UnkeyedInstanceShim() - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := modulePathPrimaryInstanceState(s, mpt, name) if err != nil { return err } return testCheckResourceAttrSet(is, name, key) - } + }) } func testCheckResourceAttrSet(is *terraform.InstanceState, name string, key string) error { @@ -1056,28 +1056,28 @@ func testCheckResourceAttrSet(is *terraform.InstanceState, name string, key stri // TestCheckResourceAttr is a TestCheckFunc which validates // the value in state for the given name/key combination. func TestCheckResourceAttr(name, key, value string) TestCheckFunc { - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := primaryInstanceState(s, name) if err != nil { return err } return testCheckResourceAttr(is, name, key, value) - } + }) } // TestCheckModuleResourceAttr - as per TestCheckResourceAttr but with // support for non-root modules func TestCheckModuleResourceAttr(mp []string, name string, key string, value string) TestCheckFunc { mpt := addrs.Module(mp).UnkeyedInstanceShim() - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := modulePathPrimaryInstanceState(s, mpt, name) if err != nil { return err } return testCheckResourceAttr(is, name, key, value) - } + }) } func testCheckResourceAttr(is *terraform.InstanceState, name string, key string, value string) error { @@ -1111,28 +1111,28 @@ func testCheckResourceAttr(is *terraform.InstanceState, name string, key string, // TestCheckNoResourceAttr is a TestCheckFunc which ensures that // NO value exists in state for the given name/key combination. func TestCheckNoResourceAttr(name, key string) TestCheckFunc { - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := primaryInstanceState(s, name) if err != nil { return err } return testCheckNoResourceAttr(is, name, key) - } + }) } // TestCheckModuleNoResourceAttr - as per TestCheckNoResourceAttr but with // support for non-root modules func TestCheckModuleNoResourceAttr(mp []string, name string, key string) TestCheckFunc { mpt := addrs.Module(mp).UnkeyedInstanceShim() - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := modulePathPrimaryInstanceState(s, mpt, name) if err != nil { return err } return testCheckNoResourceAttr(is, name, key) - } + }) } func testCheckNoResourceAttr(is *terraform.InstanceState, name string, key string) error { @@ -1159,28 +1159,28 @@ func testCheckNoResourceAttr(is *terraform.InstanceState, name string, key strin // TestMatchResourceAttr is a TestCheckFunc which checks that the value // in state for the given name/key combination matches the given regex. func TestMatchResourceAttr(name, key string, r *regexp.Regexp) TestCheckFunc { - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := primaryInstanceState(s, name) if err != nil { return err } return testMatchResourceAttr(is, name, key, r) - } + }) } // TestModuleMatchResourceAttr - as per TestMatchResourceAttr but with // support for non-root modules func TestModuleMatchResourceAttr(mp []string, name string, key string, r *regexp.Regexp) TestCheckFunc { mpt := addrs.Module(mp).UnkeyedInstanceShim() - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSet(key, func(s *terraform.State) error { is, err := modulePathPrimaryInstanceState(s, mpt, name) if err != nil { return err } return testMatchResourceAttr(is, name, key, r) - } + }) } func testMatchResourceAttr(is *terraform.InstanceState, name string, key string, r *regexp.Regexp) error { @@ -1216,7 +1216,7 @@ func TestCheckModuleResourceAttrPtr(mp []string, name string, key string, value // TestCheckResourceAttrPair is a TestCheckFunc which validates that the values // in state for a pair of name/key combinations are equal. func TestCheckResourceAttrPair(nameFirst, keyFirst, nameSecond, keySecond string) TestCheckFunc { - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSetPair(keyFirst, keySecond, func(s *terraform.State) error { isFirst, err := primaryInstanceState(s, nameFirst) if err != nil { return err @@ -1228,7 +1228,7 @@ func TestCheckResourceAttrPair(nameFirst, keyFirst, nameSecond, keySecond string } return testCheckResourceAttrPair(isFirst, nameFirst, keyFirst, isSecond, nameSecond, keySecond) - } + }) } // TestCheckModuleResourceAttrPair - as per TestCheckResourceAttrPair but with @@ -1236,7 +1236,7 @@ func TestCheckResourceAttrPair(nameFirst, keyFirst, nameSecond, keySecond string func TestCheckModuleResourceAttrPair(mpFirst []string, nameFirst string, keyFirst string, mpSecond []string, nameSecond string, keySecond string) TestCheckFunc { mptFirst := addrs.Module(mpFirst).UnkeyedInstanceShim() mptSecond := addrs.Module(mpSecond).UnkeyedInstanceShim() - return func(s *terraform.State) error { + return checkIfIndexesIntoTypeSetPair(keyFirst, keySecond, func(s *terraform.State) error { isFirst, err := modulePathPrimaryInstanceState(s, mptFirst, nameFirst) if err != nil { return err @@ -1248,7 +1248,7 @@ func TestCheckModuleResourceAttrPair(mpFirst []string, nameFirst string, keyFirs } return testCheckResourceAttrPair(isFirst, nameFirst, keyFirst, isSecond, nameSecond, keySecond) - } + }) } func testCheckResourceAttrPair(isFirst *terraform.InstanceState, nameFirst string, keyFirst string, isSecond *terraform.InstanceState, nameSecond string, keySecond string) error { @@ -1424,3 +1424,35 @@ func detailedErrorMessage(err error) string { return err.Error() } } + +// indexesIntoTypeSet is a heuristic to try and identify if a flatmap style +// string address uses a precalculated TypeSet hash, which are integers and +// typically are large and obviously not a list index +func indexesIntoTypeSet(key string) bool { + for _, part := range strings.Split(key, ".") { + if i, err := strconv.Atoi(part); err == nil && i > 100 { + return true + } + } + return false +} + +func checkIfIndexesIntoTypeSet(key string, f TestCheckFunc) TestCheckFunc { + return func(s *terraform.State) error { + err := f(s) + if err != nil && s.IsBinaryDrivenTest && indexesIntoTypeSet(key) { + return fmt.Errorf("Error in test check: %s\nTest check address %q likely indexes into TypeSet\nThis is not possible in V1 of the SDK while using the binary driver\nPlease disable the driver for this TestCase with DisableBinaryDriver: true", err, key) + } + return err + } +} + +func checkIfIndexesIntoTypeSetPair(keyFirst, keySecond string, f TestCheckFunc) TestCheckFunc { + return func(s *terraform.State) error { + err := f(s) + if err != nil && s.IsBinaryDrivenTest && (indexesIntoTypeSet(keyFirst) || indexesIntoTypeSet(keySecond)) { + return fmt.Errorf("Error in test check: %s\nTest check address %q or %q likely indexes into TypeSet\nThis is not possible in V1 of the SDK while using the binary driver\nPlease disable the driver for this TestCase with DisableBinaryDriver: true", err, keyFirst, keySecond) + } + return err + } +} diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new.go index 8ba9c85d3..34244e095 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new.go @@ -14,13 +14,18 @@ import ( tftest "github.com/hashicorp/terraform-plugin-test" ) -func getState(t *testing.T, wd *tftest.WorkingDir) *terraform.State { - jsonState := wd.RequireState(t) - state, err := shimStateFromJson(jsonState) - if err != nil { - t.Fatal(err) +func runPostTestDestroy(t *testing.T, c TestCase, wd *tftest.WorkingDir) error { + wd.RequireDestroy(t) + + if c.CheckDestroy != nil { + statePostDestroy := getState(t, wd) + + if err := c.CheckDestroy(statePostDestroy); err != nil { + return err + } } - return state + + return nil } func RunNewTest(t *testing.T, c TestCase, providers map[string]terraform.ResourceProvider) { @@ -29,15 +34,12 @@ func RunNewTest(t *testing.T, c TestCase, providers map[string]terraform.Resourc wd := acctest.TestHelper.RequireNewWorkingDir(t) defer func() { - wd.RequireDestroy(t) + statePreDestroy := getState(t, wd) - if c.CheckDestroy != nil { - statePostDestroy := getState(t, wd) - - if err := c.CheckDestroy(statePostDestroy); err != nil { - t.Fatal(err) - } + if !stateIsEmpty(statePreDestroy) { + runPostTestDestroy(t, c, wd) } + wd.Close() }() @@ -98,6 +100,19 @@ func RunNewTest(t *testing.T, c TestCase, providers map[string]terraform.Resourc } } +func getState(t *testing.T, wd *tftest.WorkingDir) *terraform.State { + jsonState := wd.RequireState(t) + state, err := shimStateFromJson(jsonState) + if err != nil { + t.Fatal(err) + } + return state +} + +func stateIsEmpty(state *terraform.State) bool { + return state.Empty() || !state.HasResources() +} + func planIsEmpty(plan *tfjson.Plan) bool { for _, rc := range plan.ResourceChanges { if rc.Mode == tfjson.DataResourceMode { @@ -114,6 +129,7 @@ func planIsEmpty(plan *tfjson.Plan) bool { } return true } + func testIDRefresh(c TestCase, t *testing.T, wd *tftest.WorkingDir, step TestStep, r *terraform.ResourceState) error { spewConf := spew.NewDefaultConfig() spewConf.SortKeys = true diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new_config.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new_config.go index d2fbf29d7..a59d685d8 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new_config.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/resource/testing_new_config.go @@ -32,6 +32,7 @@ func testStepNewConfig(t *testing.T, c TestCase, wd *tftest.WorkingDir, step Tes state := getState(t, wd) if step.Check != nil { + state.IsBinaryDrivenTest = true if err := step.Check(state); err != nil { t.Fatal(err) } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/field_reader.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/field_reader.go index 622e9b13e..b3c023d19 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/field_reader.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/field_reader.go @@ -44,6 +44,8 @@ func (r *FieldReadResult) ValueOrZero(s *Schema) interface{} { // SchemasForFlatmapPath tries its best to find a sequence of schemas that // the given dot-delimited attribute path traverses through. +// +// Deprecated: This function will be removed in version 2 without replacement. func SchemasForFlatmapPath(path string, schemaMap map[string]*Schema) []*Schema { parts := strings.Split(path, ".") return addrToSchema(parts, schemaMap) diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go index 75cfe8857..1bc308088 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/resource.go @@ -770,6 +770,8 @@ func (r *Resource) TestResourceData() *ResourceData { // SchemasForFlatmapPath tries its best to find a sequence of schemas that // the given dot-delimited attribute path traverses through in the schema // of the receiving Resource. +// +// Deprecated: This function will be removed in version 2 without replacement. func (r *Resource) SchemasForFlatmapPath(path string) []*Schema { return SchemasForFlatmapPath(path, r.Schema) } diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/schema.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/schema.go index 69ab09b7c..df0172fa1 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/schema.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/helper/schema/schema.go @@ -223,9 +223,12 @@ type Schema struct { // // AtLeastOneOf is a set of schema keys that, when set, at least one of // the keys in that list must be specified. + // + // RequiredWith is a set of schema keys that must be set simultaneously. ConflictsWith []string ExactlyOneOf []string AtLeastOneOf []string + RequiredWith []string // When Deprecated is set, this attribute is deprecated. // @@ -236,6 +239,9 @@ type Schema struct { // When Removed is set, this attribute has been removed from the schema // + // Deprecated: This field will be removed in version 2 without replacement + // as the functionality is not necessary. + // // Removed attributes can be left in the Schema to generate informative error // messages for the user when they show up in resource configurations. // This string is the message shown to the user with instructions on @@ -767,21 +773,28 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro } if len(v.ConflictsWith) > 0 { - err := checkKeysAgainstSchemaFlags(k, v.ConflictsWith, topSchemaMap) + err := checkKeysAgainstSchemaFlags(k, v.ConflictsWith, topSchemaMap, v, false) if err != nil { return fmt.Errorf("ConflictsWith: %+v", err) } } + if len(v.RequiredWith) > 0 { + err := checkKeysAgainstSchemaFlags(k, v.RequiredWith, topSchemaMap, v, true) + if err != nil { + return fmt.Errorf("RequiredWith: %+v", err) + } + } + if len(v.ExactlyOneOf) > 0 { - err := checkKeysAgainstSchemaFlags(k, v.ExactlyOneOf, topSchemaMap) + err := checkKeysAgainstSchemaFlags(k, v.ExactlyOneOf, topSchemaMap, v, true) if err != nil { return fmt.Errorf("ExactlyOneOf: %+v", err) } } if len(v.AtLeastOneOf) > 0 { - err := checkKeysAgainstSchemaFlags(k, v.AtLeastOneOf, topSchemaMap) + err := checkKeysAgainstSchemaFlags(k, v.AtLeastOneOf, topSchemaMap, v, true) if err != nil { return fmt.Errorf("AtLeastOneOf: %+v", err) } @@ -850,14 +863,20 @@ func (m schemaMap) internalValidate(topSchemaMap schemaMap, attrsOnly bool) erro return nil } -func checkKeysAgainstSchemaFlags(k string, keys []string, topSchemaMap schemaMap) error { +func checkKeysAgainstSchemaFlags(k string, keys []string, topSchemaMap schemaMap, self *Schema, allowSelfReference bool) error { for _, key := range keys { parts := strings.Split(key, ".") sm := topSchemaMap var target *Schema - for _, part := range parts { - // Skip index fields - if _, err := strconv.Atoi(part); err == nil { + for idx, part := range parts { + // Skip index fields if 0 + partInt, err := strconv.Atoi(part) + + if err == nil { + if partInt != 0 { + return fmt.Errorf("%s configuration block reference (%s) can only use the .0. index for TypeList and MaxItems: 1 configuration blocks", k, key) + } + continue } @@ -866,13 +885,28 @@ func checkKeysAgainstSchemaFlags(k string, keys []string, topSchemaMap schemaMap return fmt.Errorf("%s references unknown attribute (%s) at part (%s)", k, key, part) } - if subResource, ok := target.Elem.(*Resource); ok { - sm = schemaMap(subResource.Schema) + subResource, ok := target.Elem.(*Resource) + + if !ok { + continue + } + + // Skip Type/MaxItems check if not the last element + if (target.Type == TypeSet || target.MaxItems != 1) && idx+1 != len(parts) { + return fmt.Errorf("%s configuration block reference (%s) can only be used with TypeList and MaxItems: 1 configuration blocks", k, key) } + + sm = schemaMap(subResource.Schema) } + if target == nil { return fmt.Errorf("%s cannot find target attribute (%s), sm: %#v", k, key, sm) } + + if target == self && !allowSelfReference { + return fmt.Errorf("%s cannot reference self (%s)", k, key) + } + if target.Required { return fmt.Errorf("%s cannot contain Required attribute (%s)", k, key) } @@ -881,6 +915,7 @@ func checkKeysAgainstSchemaFlags(k string, keys []string, topSchemaMap schemaMap return fmt.Errorf("%s cannot contain Computed(When) attribute (%s)", k, key) } } + return nil } @@ -1414,6 +1449,11 @@ func (m schemaMap) validate( "%q: this field cannot be set", k)} } + err = validateRequiredWithAttribute(k, schema, c) + if err != nil { + return nil, []error{err} + } + // If the value is unknown then we can't validate it yet. // In particular, this avoids spurious type errors where downstream // validation code sees UnknownVariableValue as being just a string. @@ -1494,6 +1534,27 @@ func removeDuplicates(elements []string) []string { return result } +func validateRequiredWithAttribute( + k string, + schema *Schema, + c *terraform.ResourceConfig) error { + + if len(schema.RequiredWith) == 0 { + return nil + } + + allKeys := removeDuplicates(append(schema.RequiredWith, k)) + sort.Strings(allKeys) + + for _, key := range allKeys { + if _, ok := c.Get(key); !ok { + return fmt.Errorf("%q: all of `%s` must be specified", k, strings.Join(allKeys, ",")) + } + } + + return nil +} + func validateExactlyOneAttribute( k string, schema *Schema, diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go index 3f6657ab2..4474ba994 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/meta/meta.go @@ -11,7 +11,7 @@ import ( ) // The main version number that is being run at the moment. -var SDKVersion = "1.9.1" +var SDKVersion = "1.11.0" // A pre-release marker for the version. If this is "" (empty string) // then it means that it is a final release. Otherwise, this is a pre-release diff --git a/vendor/github.com/hashicorp/terraform-plugin-sdk/terraform/state.go b/vendor/github.com/hashicorp/terraform-plugin-sdk/terraform/state.go index b2b308e79..98b20be7c 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-sdk/terraform/state.go +++ b/vendor/github.com/hashicorp/terraform-plugin-sdk/terraform/state.go @@ -112,6 +112,10 @@ type State struct { Modules []*ModuleState `json:"modules"` mu sync.Mutex + + // IsBinaryDrivenTest is a special flag that assists with a binary driver + // heuristic, it should not be set externally + IsBinaryDrivenTest bool } func (s *State) Lock() { s.mu.Lock() } diff --git a/vendor/github.com/hashicorp/terraform-plugin-test/helper.go b/vendor/github.com/hashicorp/terraform-plugin-test/helper.go index d4de44680..8a519aaf0 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-test/helper.go +++ b/vendor/github.com/hashicorp/terraform-plugin-test/helper.go @@ -196,6 +196,11 @@ func symlinkAuxiliaryProviders(pluginDir string) error { return nil } +// GetPluginName returns the configured plugin name. +func (h *Helper) GetPluginName() string { + return h.pluginName +} + // Close cleans up temporary files and directories created to support this // helper, returning an error if any of the cleanup fails. // @@ -218,7 +223,7 @@ func (h *Helper) NewWorkingDir() (*WorkingDir, error) { } // symlink the provider source files into the base directory - err = symlinkDir(h.sourceDir, dir) + err = symlinkDirectoriesOnly(h.sourceDir, dir) if err != nil { return nil, err } diff --git a/vendor/github.com/hashicorp/terraform-plugin-test/util.go b/vendor/github.com/hashicorp/terraform-plugin-test/util.go index 0732c82d1..57bc84f2d 100644 --- a/vendor/github.com/hashicorp/terraform-plugin-test/util.go +++ b/vendor/github.com/hashicorp/terraform-plugin-test/util.go @@ -53,3 +53,43 @@ func symlinkDir(srcDir string, destDir string) (err error) { } return } + +// symlinkDirectoriesOnly finds only the first-level child directories in srcDir +// and symlinks them into destDir. +// Unlike symlinkDir, this is done non-recursively in order to limit the number +// of file descriptors used. +func symlinkDirectoriesOnly(srcDir string, destDir string) (err error) { + srcInfo, err := os.Stat(srcDir) + if err != nil { + return err + } + + err = os.MkdirAll(destDir, srcInfo.Mode()) + if err != nil { + return err + } + + directory, err := os.Open(srcDir) + if err != nil { + return err + } + defer directory.Close() + objects, err := directory.Readdir(-1) + if err != nil { + return err + } + + for _, obj := range objects { + srcPath := filepath.Join(srcDir, obj.Name()) + destPath := filepath.Join(destDir, obj.Name()) + + if obj.IsDir() { + err = symlinkFile(srcPath, destPath) + if err != nil { + return err + } + } + + } + return +} diff --git a/vendor/modules.txt b/vendor/modules.txt index 35e008538..88d695629 100644 --- a/vendor/modules.txt +++ b/vendor/modules.txt @@ -347,7 +347,7 @@ github.com/hashicorp/logutils github.com/hashicorp/terraform-config-inspect/tfconfig # github.com/hashicorp/terraform-json v0.4.0 github.com/hashicorp/terraform-json -# github.com/hashicorp/terraform-plugin-sdk v1.9.1 +# github.com/hashicorp/terraform-plugin-sdk v1.11.0 github.com/hashicorp/terraform-plugin-sdk/acctest github.com/hashicorp/terraform-plugin-sdk/helper/acctest github.com/hashicorp/terraform-plugin-sdk/helper/hashcode @@ -393,7 +393,7 @@ github.com/hashicorp/terraform-plugin-sdk/internal/version github.com/hashicorp/terraform-plugin-sdk/meta github.com/hashicorp/terraform-plugin-sdk/plugin github.com/hashicorp/terraform-plugin-sdk/terraform -# github.com/hashicorp/terraform-plugin-test v1.2.0 +# github.com/hashicorp/terraform-plugin-test v1.3.0 github.com/hashicorp/terraform-plugin-test # github.com/hashicorp/terraform-svchost v0.0.0-20191011084731-65d371908596 github.com/hashicorp/terraform-svchost