Merge pull request #1379 from hashicorp/f-validate-forcenew-on-resources-without-update
helper/schema: ensure ForceNew set when Update is not
This commit is contained in:
commit
b0abb4ea49
|
@ -84,6 +84,7 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
|
||||||
"associate_public_ip_address": &schema.Schema{
|
"associate_public_ip_address": &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
Default: false,
|
Default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
@ -96,6 +97,7 @@ func resourceAwsLaunchConfiguration() *schema.Resource {
|
||||||
"ebs_optimized": &schema.Schema{
|
"ebs_optimized": &schema.Schema{
|
||||||
Type: schema.TypeBool,
|
Type: schema.TypeBool,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
Default: false,
|
Default: false,
|
||||||
},
|
},
|
||||||
|
|
||||||
|
|
|
@ -75,6 +75,7 @@ func resourceComputeRoute() *schema.Resource {
|
||||||
"tags": &schema.Schema{
|
"tags": &schema.Schema{
|
||||||
Type: schema.TypeSet,
|
Type: schema.TypeSet,
|
||||||
Optional: true,
|
Optional: true,
|
||||||
|
ForceNew: true,
|
||||||
Elem: &schema.Schema{Type: schema.TypeString},
|
Elem: &schema.Schema{Type: schema.TypeString},
|
||||||
Set: func(v interface{}) int {
|
Set: func(v interface{}) int {
|
||||||
return hashcode.String(v.(string))
|
return hashcode.String(v.(string))
|
||||||
|
|
|
@ -225,9 +225,31 @@ func (r *Resource) InternalValidate() error {
|
||||||
return errors.New("resource is nil")
|
return errors.New("resource is nil")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if r.isTopLevel() {
|
||||||
|
// All non-Computed attributes must be ForceNew if Update is not defined
|
||||||
|
if r.Update == nil {
|
||||||
|
nonForceNewAttrs := make([]string, 0)
|
||||||
|
for k, v := range r.Schema {
|
||||||
|
if !v.ForceNew && !v.Computed {
|
||||||
|
nonForceNewAttrs = append(nonForceNewAttrs, k)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
if len(nonForceNewAttrs) > 0 {
|
||||||
|
return fmt.Errorf(
|
||||||
|
"No Update defined, must set ForceNew on: %#v", nonForceNewAttrs)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return schemaMap(r.Schema).InternalValidate()
|
return schemaMap(r.Schema).InternalValidate()
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Returns true if the resource is "top level" i.e. not a sub-resource.
|
||||||
|
func (r *Resource) isTopLevel() bool {
|
||||||
|
// TODO: This is a heuristic; replace with a definitive attribute?
|
||||||
|
return r.Create != nil
|
||||||
|
}
|
||||||
|
|
||||||
// Determines if a given InstanceState needs to be migrated by checking the
|
// Determines if a given InstanceState needs to be migrated by checking the
|
||||||
// stored version number with the current SchemaVersion
|
// stored version number with the current SchemaVersion
|
||||||
func (r *Resource) checkSchemaVersion(is *terraform.InstanceState) (bool, int) {
|
func (r *Resource) checkSchemaVersion(is *terraform.InstanceState) (bool, int) {
|
||||||
|
|
Loading…
Reference in New Issue