Merge pull request #9825 from hashicorp/b-conflictswith-computed
helper/schema: allow ConflictsWith and Computed Optional fields
This commit is contained in:
commit
85062d6c1f
|
@ -135,7 +135,10 @@ type Schema struct {
|
|||
// NOTE: This currently does not work.
|
||||
ComputedWhen []string
|
||||
|
||||
// ConflictsWith is a set of schema keys that conflict with this schema
|
||||
// ConflictsWith is a set of schema keys that conflict with this schema.
|
||||
// This will only check that they're set in the _config_. This will not
|
||||
// raise an error for a malfunctioning resource that sets a conflicting
|
||||
// key.
|
||||
ConflictsWith []string
|
||||
|
||||
// When Deprecated is set, this attribute is deprecated.
|
||||
|
@ -571,7 +574,7 @@ func (m schemaMap) InternalValidate(topSchemaMap schemaMap) error {
|
|||
return fmt.Errorf("%s: ConflictsWith cannot contain Required attribute (%s)", k, key)
|
||||
}
|
||||
|
||||
if target.Computed || len(target.ComputedWhen) > 0 {
|
||||
if len(target.ComputedWhen) > 0 {
|
||||
return fmt.Errorf("%s: ConflictsWith cannot contain Computed(When) attribute (%s)", k, key)
|
||||
}
|
||||
}
|
||||
|
|
|
@ -2885,21 +2885,6 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
true,
|
||||
},
|
||||
|
||||
"ConflictsWith cannot be used w/ Computed": {
|
||||
map[string]*Schema{
|
||||
"blacklist": &Schema{
|
||||
Type: TypeBool,
|
||||
Computed: true,
|
||||
},
|
||||
"whitelist": &Schema{
|
||||
Type: TypeBool,
|
||||
Optional: true,
|
||||
ConflictsWith: []string{"blacklist"},
|
||||
},
|
||||
},
|
||||
true,
|
||||
},
|
||||
|
||||
"ConflictsWith cannot be used w/ ComputedWhen": {
|
||||
map[string]*Schema{
|
||||
"blacklist": &Schema{
|
||||
|
@ -2963,7 +2948,7 @@ func TestSchemaMap_InternalValidate(t *testing.T) {
|
|||
}
|
||||
|
||||
for tn, tc := range cases {
|
||||
err := schemaMap(tc.In).InternalValidate(schemaMap{})
|
||||
err := schemaMap(tc.In).InternalValidate(nil)
|
||||
if err != nil != tc.Err {
|
||||
if tc.Err {
|
||||
t.Fatalf("%q: Expected error did not occur:\n\n%#v", tn, tc.In)
|
||||
|
@ -3758,6 +3743,78 @@ func TestSchemaMap_Validate(t *testing.T) {
|
|||
},
|
||||
},
|
||||
|
||||
"Computed + Optional fields conflicting with each other": {
|
||||
Schema: map[string]*Schema{
|
||||
"foo_att": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"bar_att"},
|
||||
},
|
||||
"bar_att": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"foo_att"},
|
||||
},
|
||||
},
|
||||
|
||||
Config: map[string]interface{}{
|
||||
"foo_att": "foo-val",
|
||||
"bar_att": "bar-val",
|
||||
},
|
||||
|
||||
Err: true,
|
||||
Errors: []error{
|
||||
fmt.Errorf(`"foo_att": conflicts with bar_att ("bar-val")`),
|
||||
fmt.Errorf(`"bar_att": conflicts with foo_att ("foo-val")`),
|
||||
},
|
||||
},
|
||||
|
||||
"Computed + Optional fields NOT conflicting with each other": {
|
||||
Schema: map[string]*Schema{
|
||||
"foo_att": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"bar_att"},
|
||||
},
|
||||
"bar_att": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"foo_att"},
|
||||
},
|
||||
},
|
||||
|
||||
Config: map[string]interface{}{
|
||||
"foo_att": "foo-val",
|
||||
},
|
||||
|
||||
Err: false,
|
||||
},
|
||||
|
||||
"Computed + Optional fields that conflict with none set": {
|
||||
Schema: map[string]*Schema{
|
||||
"foo_att": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"bar_att"},
|
||||
},
|
||||
"bar_att": &Schema{
|
||||
Type: TypeString,
|
||||
Optional: true,
|
||||
Computed: true,
|
||||
ConflictsWith: []string{"foo_att"},
|
||||
},
|
||||
},
|
||||
|
||||
Config: map[string]interface{}{},
|
||||
|
||||
Err: false,
|
||||
},
|
||||
|
||||
"Good with ValidateFunc": {
|
||||
Schema: map[string]*Schema{
|
||||
"validate_me": &Schema{
|
||||
|
|
Loading…
Reference in New Issue