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

Feature/add support resource tags for aws cloudwatch event rule resource #8076

Conversation

teraken0509
Copy link
Contributor

Community Note

  • Please vote on this pull request by adding a 👍 reaction to the original pull request comment to help the community and maintainers prioritize this request
  • Please do not leave "+1" comments, they generate extra noise for pull request followers and do not help prioritize the request

Fixes #8047

Changes proposed in this pull request:

  • Add resource tags support
  • Add tags attribute for aws_cloudwatch_event_rule resource

Output from acceptance testing:

$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudWatchEventRule_tags'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSCloudWatchEventRule_tags -timeout 120m
=== RUN   TestAccAWSCloudWatchEventRule_tags
=== PAUSE TestAccAWSCloudWatchEventRule_tags
=== CONT  TestAccAWSCloudWatchEventRule_tags
--- PASS: TestAccAWSCloudWatchEventRule_tags (57.41s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	57.489s
$ make testacc TEST=./aws TESTARGS='-run=TestAccAWSCloudWatchEventRule_full'
==> Checking that code complies with gofmt requirements...
TF_ACC=1 go test ./aws -v -parallel 20 -run=TestAccAWSCloudWatchEventRule_full -timeout 120m
=== RUN   TestAccAWSCloudWatchEventRule_full
=== PAUSE TestAccAWSCloudWatchEventRule_full
=== CONT  TestAccAWSCloudWatchEventRule_full
--- PASS: TestAccAWSCloudWatchEventRule_full (51.71s)
PASS
ok  	github.com/terraform-providers/terraform-provider-aws/aws	51.780s

@ghost ghost added size/L Managed by automation to categorize the size of a PR. service/cloudwatchevents tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure. documentation Introduces or discusses updates to documentation. labels Mar 26, 2019
@bflad bflad added the enhancement Requests to existing resources that expand the functionality or scope. label Mar 29, 2019
@@ -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)))
Copy link
Contributor

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.

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Mar 29, 2019
@ghost ghost added size/XL Managed by automation to categorize the size of a PR. and removed size/L Managed by automation to categorize the size of a PR. labels Mar 29, 2019
@bflad bflad added this to the v2.4.0 milestone Mar 29, 2019
Copy link
Contributor

@bflad bflad left a 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 {
Copy link
Contributor

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.

@bflad bflad merged commit dea3fb3 into hashicorp:master Mar 29, 2019
bflad added a commit that referenced this pull request Mar 29, 2019
@bflad
Copy link
Contributor

bflad commented Mar 29, 2019

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.

@sernst
Copy link

sernst commented Apr 1, 2019

Just updated to provider version 2.4.0 and am getting error output that appears to be what was introduced in this PR:

Error: Error applying plan:
aws_cloudwatch_event_rule.rule: error setting tags: Error retreiving tags for ARN: arn:aws:events:us-east-1:######:rule/my-cloudwatch-rule

and then after the failed apply it's not possible to refresh state from the same error:

Error: Error refreshing state: 1 error(s) occurred:
aws_cloudwatch_event_rule.rule: error setting tags: Error retreiving tags for ARN: arn:aws:events:us-east-1:######:rule/my-cloudwatch-rule

Downgrading to 2.3.0 resolves the issue. The resource definition is fairly simple:

resource "aws_cloudwatch_event_rule" "rule" {
  name = "${var.name}-cloudwatch-rule"
  schedule_expression = "cron(2 * * * ? *)"

  depends_on = ["aws_lambda_function.lambda"]
}

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?

@ghost ghost removed the waiting-response Maintainers are waiting on response from community or contributor. label Apr 1, 2019
@jgelens
Copy link

jgelens commented Apr 4, 2019

2.4.0 introduced the issue above for me as well.

@bflad
Copy link
Contributor

bflad commented Apr 4, 2019

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 events:ListTagsForResource to any IAM policies so the Terraform resource can at least read the information from the API.

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.

@sernst
Copy link

sernst commented Apr 6, 2019

@bflad Good to know and thanks for the fast turnaround on it. Will do in the future.

@teraken0509 teraken0509 deleted the feature/add-support-resource-tags-for-aws_cloudwatch_event_rule-resource branch March 5, 2020 14:04
@ghost
Copy link

ghost commented Mar 5, 2020

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!

@ghost ghost locked and limited conversation to collaborators Mar 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
documentation Introduces or discusses updates to documentation. enhancement Requests to existing resources that expand the functionality or scope. size/XL Managed by automation to categorize the size of a PR. tests PRs: expanded test coverage. Issues: expanded coverage, enhancements to test infrastructure.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

r/aws_cloudwatch_event_rule: Add support for resource tags
4 participants