Skip to content

Commit

Permalink
Merge branch 'ignore_overwrite_change' into coveo-master
Browse files Browse the repository at this point in the history
  • Loading branch information
Julien Duchesne committed Oct 1, 2018
2 parents 15413b8 + d3e88d5 commit 42a2ab1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 47 deletions.
22 changes: 8 additions & 14 deletions aws/resource_aws_ssm_parameter.go
Original file line number Diff line number Diff line change
Expand Up @@ -58,8 +58,10 @@ func resourceAwsSsmParameter() *schema.Resource {
Computed: true,
},
"overwrite": {
Type: schema.TypeBool,
Optional: true,
Type: schema.TypeBool,
Optional: true,
DiffSuppressFunc: func(k, old, new string, d *schema.ResourceData) bool { return true },
Deprecated: "The `overwrite` attribute is no longer used. Existing resources are now always overwritten.",
},
"allowed_pattern": {
Type: schema.TypeString,
Expand Down Expand Up @@ -174,7 +176,7 @@ func resourceAwsSsmParameterPut(d *schema.ResourceData, meta interface{}) error
Name: aws.String(d.Get("name").(string)),
Type: aws.String(d.Get("type").(string)),
Value: aws.String(d.Get("value").(string)),
Overwrite: aws.Bool(shouldUpdateSsmParameter(d)),
Overwrite: aws.Bool(!d.IsNewResource()),
AllowedPattern: aws.String(d.Get("allowed_pattern").(string)),
}

Expand All @@ -190,6 +192,9 @@ func resourceAwsSsmParameterPut(d *schema.ResourceData, meta interface{}) error

log.Printf("[DEBUG] Waiting for SSM Parameter %v to be updated", d.Get("name"))
if _, err := ssmconn.PutParameter(paramInput); err != nil {
if isAWSErr(err, ssm.ErrCodeParameterAlreadyExists, "") {
return fmt.Errorf("The parameter already exists")
}
return fmt.Errorf("error creating SSM parameter: %s", err)
}

Expand All @@ -201,14 +206,3 @@ func resourceAwsSsmParameterPut(d *schema.ResourceData, meta interface{}) error

return resourceAwsSsmParameterRead(d, meta)
}

func shouldUpdateSsmParameter(d *schema.ResourceData) bool {
// If the user has specified a preference, return their preference
if value, ok := d.GetOkExists("overwrite"); ok {
return value.(bool)
}

// Since the user has not specified a preference, obey lifecycle rules
// if it is not a new resource, otherwise overwrite should be set to false.
return !d.IsNewResource()
}
32 changes: 0 additions & 32 deletions aws/resource_aws_ssm_parameter_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -408,35 +408,3 @@ resource "aws_kms_alias" "test_alias" {
}
`, rName, value, keyAlias)
}

func TestAWSSSMParameterShouldUpdate(t *testing.T) {
data := resourceAwsSsmParameter().TestResourceData()
failure := false

if !shouldUpdateSsmParameter(data) {
t.Logf("Existing resources should be overwritten if the values don't match!")
failure = true
}

data.MarkNewResource()
if shouldUpdateSsmParameter(data) {
t.Logf("New resources must never be overwritten, this will overwrite parameters created outside of the system")
failure = true
}

data = resourceAwsSsmParameter().TestResourceData()
data.Set("overwrite", true)
if !shouldUpdateSsmParameter(data) {
t.Logf("Resources should always be overwritten if the user requests it")
failure = true
}

data.Set("overwrite", false)
if shouldUpdateSsmParameter(data) {
t.Logf("Resources should never be overwritten if the user requests it")
failure = true
}
if failure {
t.Fail()
}
}
1 change: 0 additions & 1 deletion website/docs/r/ssm_parameter.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,6 @@ The following arguments are supported:
* `value` - (Required) The value of the parameter.
* `description` - (Optional) The description of the parameter.
* `key_id` - (Optional) The KMS key id or arn for encrypting a SecureString.
* `overwrite` - (Optional) Overwrite an existing parameter. If not specified, will default to `false` if the resource has not been created by terraform to avoid overwrite of existing resource and will default to `true` otherwise (terraform lifecycle rules should then be used to manage the update behavior).
* `allowed_pattern` - (Optional) A regular expression used to validate the parameter value.
* `tags` - (Optional) A mapping of tags to assign to the object.

Expand Down

0 comments on commit 42a2ab1

Please sign in to comment.