-
Notifications
You must be signed in to change notification settings - Fork 9.3k
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
Feature/add support resource tags for aws cloudwatch event rule resource #8076
Feature/add support resource tags for aws cloudwatch event rule resource #8076
Conversation
@@ -163,6 +168,7 @@ func resourceAwsCloudWatchEventRuleRead(d *schema.ResourceData, meta interface{} | |||
} | |||
log.Printf("[DEBUG] Setting boolean state: %t", boolState) | |||
d.Set("is_enabled", boolState) | |||
d.Set("tags", saveTagsCloudWatchEvents(conn, d, aws.StringValue(out.Arn))) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This implementation seems off, which likely can be verified with error checking when using d.Set()
. With aggregate types (TypeList, TypeSet, TypeMap), we should perform error checking to prevent issues where the code is not properly able to set the Terraform state. e.g.
if err := d.Set("tags", ...); err != nil {
return fmt.Errorf("error setting tags: %s", err)
}
However saveTagsCloudWatchEvents
is returning an error
type itself. The value in the second argument for d.Set()
with a TypeMap
should be a map[string]interface{}
. In general, its preferred to keep tag API calls in the Read function (so you can return errors with context) then just set the tags
attribute like the others.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the updates, @kterada0509! 🚀
--- PASS: TestAccAWSCloudWatchEventRule_prefix (12.66s)
--- PASS: TestAccAWSCloudWatchEventRule_full (13.87s)
--- PASS: TestAccAWSCloudWatchEventRule_importBasic (13.98s)
--- PASS: TestAccAWSCloudWatchEventRule_basic (21.56s)
--- PASS: TestAccAWSCloudWatchEventRule_enable (30.87s)
--- PASS: TestAccAWSCloudWatchEventRule_tags (33.59s)
@@ -121,6 +122,10 @@ func resourceAwsCloudWatchEventRuleCreate(d *schema.ResourceData, meta interface | |||
|
|||
log.Printf("[INFO] CloudWatch Event Rule %q created", *out.RuleArn) | |||
|
|||
if err := setTagsCloudWatchEvents(conn, d, aws.StringValue(out.RuleArn)); err != nil { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
For future enhancement, it appears PutRule
supports a Tags
parameter directly: https://docs.aws.amazon.com/sdk-for-go/api/service/cloudwatchevents/#PutRuleInput
Instead of setting the Tags via TagResource
we may be able to simplify with something like:
Tags: tagsFromMapCloudWatchEvents(d.Get("tags").(map[string]interface{})),
Which (at least on creation) may be a requirement in some environments with IAM-based restrictions based on tags.
The current implementation is passing acceptance testing though, so for now we can get this in as-is.
This has been released in version 2.4.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading. |
Just updated to provider version 2.4.0 and am getting error output that appears to be what was introduced in this PR:
and then after the failed apply it's not possible to refresh state from the same error:
Downgrading to 2.3.0 resolves the issue. The resource definition is fairly simple:
Release notes for 2.4.0 don't show this as a breaking change. Am I missing something about how this has been implemented, or should this be made into an issue? |
2.4.0 introduced the issue above for me as well. |
Hi @sernst and @jgelens 👋 Version 2.4.0 of the Terraform AWS Provider began fetching (and configuring if desired) the new support for CloudWatch Event Rule resource tags, but was omitting the actual error message as you found. Apologies about that and its been rectified in #8190 which will release in version 2.5.0 likely later today. If you are limiting IAM permissions, it is likely that you'll need to add In general though, the maintainers here will always recommend creating a new top level GitHub issue over commenting on a closed issue or pull request as these can be lost/forgotten in a project of this size. |
@bflad Good to know and thanks for the fast turnaround on it. Will do in the future. |
I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you feel this issue should be reopened, we encourage creating a new issue linking back to this one for added context. Thanks! |
Community Note
Fixes #8047
Changes proposed in this pull request:
aws_cloudwatch_event_rule
resourceOutput from acceptance testing: