Reverted ConflictsWith fix (moved to separate PR: GH-13019)

This commit is contained in:
Brandon Tosch 2017-03-23 12:42:05 -07:00
parent 808a9f04f6
commit a327648599
2 changed files with 3 additions and 48 deletions

View File

@ -1164,35 +1164,16 @@ func (m schemaMap) validateConflictingAttributes(
return nil return nil
} }
for _, conflictingKey := range schema.ConflictsWith { for _, conflicting_key := range schema.ConflictsWith {
resolvedConflictingKey := resolveConflictingKey(k, conflictingKey) if value, ok := c.Get(conflicting_key); ok {
if value, ok := c.Get(resolvedConflictingKey); ok {
return fmt.Errorf( return fmt.Errorf(
"%q: conflicts with %s (%#v)", k, resolvedConflictingKey, value) "%q: conflicts with %s (%#v)", k, conflicting_key, value)
} }
} }
return nil return nil
} }
//The key we are validating for (k) contains the index for the current list/set item
//Example: list.2.field
//The conflicting key does not contain the index so we must resolve it and add it to the conflicting key
//Example: list.conflictingField needs to become list.2.conflictingField
func resolveConflictingKey(k string, conflictingKey string) string {
if conflictingFieldIndex := strings.LastIndex(conflictingKey, "."); conflictingFieldIndex != -1 {
if parentName := conflictingKey[:conflictingFieldIndex+1]; parentName != "" {
if strings.HasPrefix(strings.ToLower(k), strings.ToLower(parentName)) {
conflictingFieldName := conflictingKey[conflictingFieldIndex+1:]
fieldIndex := strings.LastIndex(k, ".")
return k[:fieldIndex+1] + conflictingFieldName
}
}
}
return conflictingKey
}
func (m schemaMap) validateList( func (m schemaMap) validateList(
k string, k string,
raw interface{}, raw interface{},

View File

@ -14,7 +14,6 @@ import (
"github.com/hashicorp/terraform/config" "github.com/hashicorp/terraform/config"
"github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/hashcode"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
"strings"
) )
func TestEnvDefaultFunc(t *testing.T) { func TestEnvDefaultFunc(t *testing.T) {
@ -5019,31 +5018,6 @@ func TestSchemaSet_ValidateMinItems(t *testing.T) {
} }
} }
func TestSchema_ResolveConflictingKey(t *testing.T) {
cases := []struct {
Key string
ConflictingKey string
ExpectedResolvedKey string
}{
{"Field", "ConflictField", "ConflictField"},
{"Nested.Field", "Nested.ConflictField", "Nested.ConflictField"},
{"Double.Nested.Field", "Double.Nested.ConflictField", "Double.Nested.ConflictField"},
{"List.0.Field", "List.ConflictingField", "List.0.ConflictingField"},
{"Nested.List.0.Field", "Nested.List.ConflictingField", "Nested.List.0.ConflictingField"},
{"Field", ".G.I.G.O.", ".G.I.G.O."},
{"Field", ".", "."},
{"Field", "", ""},
}
for i, tc := range cases {
actualResolvedKey := resolveConflictingKey(tc.Key, tc.ConflictingKey)
if !strings.EqualFold(actualResolvedKey, tc.ExpectedResolvedKey) {
t.Errorf("%d: expected: %s actual: %s", i, tc.ExpectedResolvedKey, actualResolvedKey)
}
}
}
// errorSort implements sort.Interface to sort errors by their error message // errorSort implements sort.Interface to sort errors by their error message
type errorSort []error type errorSort []error