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

Refresh phase fails if Shield Protection was manually removed #18046

Closed
mkielar opened this issue Mar 11, 2021 · 5 comments · Fixed by #19168
Closed

Refresh phase fails if Shield Protection was manually removed #18046

mkielar opened this issue Mar 11, 2021 · 5 comments · Fixed by #19168
Labels
bug Addresses a defect in current functionality. service/shield Issues and PRs that pertain to the shield service.
Milestone

Comments

@mkielar
Copy link
Contributor

mkielar commented Mar 11, 2021

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform CLI and Terraform AWS Provider Version

Affected Resource(s)

  • aws_shield_protection

Terraform Configuration Files

Please include all Terraform configurations required to reproduce the bug. Bug reports without a functional reproduction may be closed without investigation.

resource "aws_shield_protection" "nat_eip" {
  count = var.enabled && var.vpc_enable_nat_gateway && var.enable_shield_protection ? local.nat_gateway_count : 0

  name         = "${var.vpc_name}-nat-eip-${module.vpc.nat_ids[count.index]}"
  resource_arn = "arn:aws:ec2:${data.aws_region.current.name}:${data.aws_caller_identity.current.account_id}:eip-allocation/${module.vpc.nat_ids[count.index]}"
}

Debug Output

N/A

Panic Output

N/A

Expected Behavior

Terraform should see that both the protected resource and the protection were removed from AWS and recreate them.

Actual Behavior

Terraform fails with:

Error: error reading Shield Protection ([MASKED]): ResourceNotFoundException: The referenced protection does not exist.
{
  RespMetadata: {
    StatusCode: 400,
    RequestID: "[MASKED]"
  },
  Message_: "The referenced protection does not exist."
}

Steps to Reproduce

  1. terraform apply
  2. Manuall destroy the protection from AWS Shield Console
  3. terraform apply
@ghost ghost added the service/shield Issues and PRs that pertain to the shield service. label Mar 11, 2021
@github-actions github-actions bot added the needs-triage Waiting for first response or review from a maintainer. label Mar 11, 2021
@mkielar
Copy link
Contributor Author

mkielar commented Mar 11, 2021

As a workaround it's possible to try running terraform destroy with -refresh=false flag, which on one hand allows Terraform do remove aws_shield_protection resources from the statefile.

On the other hand running with -refresh=false causes a gazzilion of failures on other resources that suddenly did not expect nulls in different places, so it's not really an option for us in fully automated CICD.

@mkielar
Copy link
Contributor Author

mkielar commented Mar 11, 2021

I think the issue is with returning an error here:
https://github.com/hashicorp/terraform-provider-aws/blob/main/aws/resource_aws_shield_protection.go#L60-L62

without first examining it for "resource not found" situation, similar to what's done here:
https://github.com/hashicorp/terraform-provider-aws/blob/main/aws/resource_aws_iam_role.go#L240-L244

The describe_protection method raises ResourceNotFoundException according to docs, which should be checked in the resource *Read method, and processed correctly without failing.

@ewbankkit
Copy link
Contributor

A _disappears acceptance test would have caught this 😄.

@ewbankkit ewbankkit added bug Addresses a defect in current functionality. and removed needs-triage Waiting for first response or review from a maintainer. labels Mar 11, 2021
@github-actions github-actions bot added this to the v3.39.0 milestone May 3, 2021
@ghost
Copy link

ghost commented May 7, 2021

This has been released in version 3.39.0 of the Terraform AWS provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template for triage. Thanks!

@github-actions
Copy link

github-actions bot commented Jun 6, 2021

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.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Jun 6, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Addresses a defect in current functionality. service/shield Issues and PRs that pertain to the shield service.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants