Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

resource/aws_cloudwatch_event_rule: Prevent multiple names on creation #4579

Merged
merged 1 commit into from
May 23, 2018
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 12 additions & 12 deletions aws/resource_aws_cloudwatch_event_rule.go
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,16 @@ func resourceAwsCloudWatchEventRule() *schema.Resource {
func resourceAwsCloudWatchEventRuleCreate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).cloudwatcheventsconn

input, err := buildPutRuleInputStruct(d)
var name string
if v, ok := d.GetOk("name"); ok {
name = v.(string)
} else if v, ok := d.GetOk("name_prefix"); ok {
name = resource.PrefixedUniqueId(v.(string))
} else {
name = resource.UniqueId()
}

input, err := buildPutRuleInputStruct(d, name)
if err != nil {
return errwrap.Wrapf("Creating CloudWatch Event Rule failed: {{err}}", err)
}
Expand Down Expand Up @@ -172,7 +181,7 @@ func resourceAwsCloudWatchEventRuleUpdate(d *schema.ResourceData, meta interface
log.Printf("[DEBUG] CloudWatch Event Rule (%q) enabled", d.Id())
}

input, err := buildPutRuleInputStruct(d)
input, err := buildPutRuleInputStruct(d, d.Id())
if err != nil {
return errwrap.Wrapf("Updating CloudWatch Event Rule failed: {{err}}", err)
}
Expand Down Expand Up @@ -226,16 +235,7 @@ func resourceAwsCloudWatchEventRuleDelete(d *schema.ResourceData, meta interface
return nil
}

func buildPutRuleInputStruct(d *schema.ResourceData) (*events.PutRuleInput, error) {
var name string
if v, ok := d.GetOk("name"); ok {
name = v.(string)
} else if v, ok := d.GetOk("name_prefix"); ok {
name = resource.PrefixedUniqueId(v.(string))
} else {
name = resource.UniqueId()
}

func buildPutRuleInputStruct(d *schema.ResourceData, name string) (*events.PutRuleInput, error) {
input := events.PutRuleInput{
Name: aws.String(name),
}
Expand Down