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

[Bug]: sweeper/aws_cloudfront_distribution: Please the update policy before deleting #33575

Closed
YakDriver opened this issue Sep 21, 2023 · 3 comments · Fixed by #33578
Closed
Labels
bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service. sweeper Pertains to changes to or issues with the sweeper.
Milestone

Comments

@YakDriver
Copy link
Member

YakDriver commented Sep 21, 2023

Terraform Core Version

1.5.5

AWS Provider Version

5.17.0

Affected Resource(s)

  • aws_cloudfront_distribution
  • aws_cloudfront_continuous_deployment_policy

Expected Behavior

Delete (and sweep) should succeed

Actual Behavior

Delete fails

Relevant Error/Panic Output Snippet

Sweeper fails with:

disabling CloudFront Distribution (E3TP2IZ1XR0V8E): StagingDistributionInUse: The specified staging distribution is currently used by a continuous deployment policy. Please the update policy before deleting.

Tests fail with:

Error running post-test destroy, there may be dangling resources: exit status 1
        
        Error: deleting CloudFront Distribution (E2GF0G8J901FV6): PreconditionFailed: The request failed because it didn't meet the preconditions in one or more request-header fields.

NOTE: This is already listed as a eventual consistency retry error but even increasing the retry time does not allow the test infrastructure to be deleted.

Terraform Configuration Files

resource "aws_cloudfront_distribution" "staging" {
  enabled          = true
  retain_on_delete = false
  staging          = true

  default_cache_behavior {
    allowed_methods        = ["GET", "HEAD"]
    cached_methods         = ["GET", "HEAD"]
    target_origin_id       = "test"
    viewer_protocol_policy = "allow-all"

    forwarded_values {
      query_string = false

      cookies {
        forward = "all"
      }
    }
  }

  origin {
    domain_name = "www.example.com"
    origin_id   = "test"

    custom_origin_config {
      http_port              = 80
      https_port             = 443
      origin_protocol_policy = "https-only"
      origin_ssl_protocols   = ["TLSv1.2"]
    }
  }

  restrictions {
    geo_restriction {
      restriction_type = "none"
    }
  }

  viewer_certificate {
    cloudfront_default_certificate = true
  }
}

resource "aws_cloudfront_distribution" "test" {
  enabled          = true
  retain_on_delete = false

  continuous_deployment_policy_id = aws_cloudfront_continuous_deployment_policy.test.id

  default_cache_behavior {
    allowed_methods        = ["GET", "HEAD"]
    cached_methods         = ["GET", "HEAD"]
    target_origin_id       = "test"
    viewer_protocol_policy = "allow-all"

    forwarded_values {
      query_string = false

      cookies {
        forward = "all"
      }
    }
  }

  origin {
    domain_name = "www.example.com"
    origin_id   = "test"

    custom_origin_config {
      http_port              = 80
      https_port             = 443
      origin_protocol_policy = "https-only"
      origin_ssl_protocols   = ["TLSv1.2"]
    }
  }

  restrictions {
    geo_restriction {
      restriction_type = "none"
    }
  }

  viewer_certificate {
    cloudfront_default_certificate = true
  }
}

resource "aws_cloudfront_continuous_deployment_policy" "test" {
  enabled = false

  staging_distribution_dns_names {
    items    = [aws_cloudfront_distribution.staging.domain_name]
    quantity = 1
  }

  traffic_config {
    type = "SingleWeight"
    single_weight_config {
      weight = "0.01"
    }
  }
}

Steps to Reproduce

  1. Comment out the continuous_deployment_policy_id line
  2. terraform apply
  3. Uncomment out the continuous_deployment_policy_id line
  4. terraform apply
  5. Attempt sweep (you'll get the sweep error) and/or test with these steps (you'll get the test error)

Debug Output

No response

Panic Output

No response

Important Factoids

No response

References

Would you like to implement a fix?

None

@YakDriver YakDriver added the bug Addresses a defect in current functionality. label Sep 21, 2023
@github-actions
Copy link

Community Note

Voting for Prioritization

  • Please vote on this issue by adding a 👍 reaction to the original post to help the community and maintainers prioritize this request.
  • Please see our prioritization guide for information on how we prioritize.
  • 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.

Volunteering to Work on This Issue

  • If you are interested in working on this issue, please leave a comment.
  • If this would be your first contribution, please review the contribution guide.

@github-actions github-actions bot added service/cloudfront Issues and PRs that pertain to the cloudfront service. sweeper Pertains to changes to or issues with the sweeper. labels Sep 21, 2023
@github-actions github-actions bot added this to the v5.19.0 milestone Sep 27, 2023
@github-actions
Copy link

This functionality has been released in v5.19.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. Thank you!

@github-actions
Copy link

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 Oct 29, 2023
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/cloudfront Issues and PRs that pertain to the cloudfront service. sweeper Pertains to changes to or issues with the sweeper.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

1 participant