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

AWS aws_cloudwatch_event_target appears to always fail #5389

Closed
tj opened this issue Mar 1, 2016 · 3 comments · Fixed by #5395
Closed

AWS aws_cloudwatch_event_target appears to always fail #5389

tj opened this issue Mar 1, 2016 · 3 comments · Fixed by #5395

Comments

@tj
Copy link

tj commented Mar 1, 2016

Seems like maybe an AWS API bug, I've tried aws_cloudwatch_event_rule.check_queuer.arn and aws_cloudwatch_event_rule.check_queuer.name, as well as manually entering the name, all result in:

'arn:aws:events:us-west-2:XXXXX:rule/check_queuer' at 'rule' failed to satisfy constraint:
Member must satisfy regular expression pattern: [\.\-_A-Za-z0-9]+
resource "aws_cloudwatch_event_rule" "check_queuer" {
  name = "check_queuer"
  description = "Invoke checks queuer"
  schedule_expression = "rate(5 minutes)"
  is_enabled = true
}

resource "aws_cloudwatch_event_target" "check_queuer" {
  target_id = "check_queuer"
  rule = "${aws_cloudwatch_event_rule.check_queuer.arn}"
  arn = "${var.check_queuer_arn}"
}
@radeksimko
Copy link
Member

Hi @tj ,
thanks for reporting this bug. After trying to reproduce this, I can say it will result in three bugfixes that I will send very soon:

  1. Documentation needs to be fixed as rule expects name of the rule, not ARN
  2. At the moment we capture the resource ID in the state, even when the error is returned - this needs to be fixed, so that it doesn't get captured at all in such cases.
  3. If it was captured in the state already and doesn't exist, there's currently no easy way to recover from that (unless we expect the user to remove the resource from tfstate file manually). This needs to be fixed too.

Coincidentally I did hit the same issue when creating acceptance tests for this resource and I thought it would be nice if Terraform could detect these things before even attempting to create any resource.

That is why I submitted https://github.com/hashicorp/terraform/issues/5035

Quick fix

If you want to recover right now, the best solution I can think of is to change rule = "${aws_cloudwatch_event_rule.check_queuer.arn}" to rule = "${aws_cloudwatch_event_rule.check_queuer.name}" and remove the aws_cloudwatch_event_target.check_queuer from the terraform.tfstate.

Real fix

After applying/merging the bugfix, user should be able to just run apply and terraform will be able to recover from this state by removing non-existing CW target during the refresh stage.

@tj
Copy link
Author

tj commented Mar 1, 2016

Awesome thanks! Not a huge deal for now I can add it back next release

@ghost
Copy link

ghost commented Apr 27, 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 have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 27, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
2 participants