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

cloudfront destroy failure #1074

Closed
xenoterracide opened this issue Jul 6, 2017 · 15 comments · Fixed by #7794
Closed

cloudfront destroy failure #1074

xenoterracide opened this issue Jul 6, 2017 · 15 comments · Fixed by #7794
Labels
bug Addresses a defect in current functionality. service/cloudfront Issues and PRs that pertain to the cloudfront service.
Milestone

Comments

@xenoterracide
Copy link

xenoterracide commented Jul 6, 2017

cloudfront destroy fails, this seems to be because cloudfront needs to deactivate first, and then delete. It seems that even if it has been disabled for a while (ran apply, it disabled, and failed, ran again, it failed again?)

aws_cloudfront_distribution.Nexus: Still destroying... (ID: E1WQKB51SRD57X, 20m31s elapsed)
Error applying plan:

1 error(s) occurred:

* aws_cloudfront_distribution.Nexus (destroy): 1 error(s) occurred:

* aws_cloudfront_distribution.Nexus: PreconditionFailed: The request failed because it didn't meet the preconditions in one or more request-header fields.
	status code: 412, request id: 8c8c265d-6275-11e7-b7ad-47970b40e146

so after

aws_cloudfront_distribution.Nexus: Still destroying... (ID: E1WQKB51SRD57X, 10m0s elapsed)

I just went in an clicked delete. If more info is needed I will try to supply.

Terraform v0.9.11
@stack72 stack72 added the bug Addresses a defect in current functionality. label Jul 7, 2017
@cannontrodder
Copy link

I'm also getting this in 0.10.6 and deleting manually fixed it instantly. I think I might have interrupted a previous 'apply' - self-inflicted!

@Ninir
Copy link
Contributor

Ninir commented Sep 27, 2017

Hi folks,

@cannontrodder thank you for your feedback!

@xenoterracide could you also try on your side?

Thank you!

@Ninir Ninir added the waiting-response Maintainers are waiting on response from community or contributor. label Sep 27, 2017
@xenoterracide
Copy link
Author

xenoterracide commented Sep 27, 2017

deleting manually would cause the apply to go through, but a subsequent create/destroy was causing the problem to resurface (because of cloudfront's deactive -> delete workflow). It may work in 10, we haven't upgraded yet, I'll leave a note to update this in our upgrade ticket.

@spanktar
Copy link

spanktar commented Oct 4, 2017

Same here. 0.10.6, will try in 0.10.7 but not sure how to recreate.

Also of note, if trying to do a refresh/apply/destroy on more than just the CF resources, TF just hangs with no output. I had a hunch it was CF so I targeted them specifically and this surfaced.

@xenoterracide
Copy link
Author

xenoterracide commented Oct 31, 2017

0.10.8/aws 1.2

aws_cloudfront_distribution.Nexus: Still destroying... (ID: E3LLHNS4QUMVRA, 20m50s elapsed)

Error: Error applying plan:

1 error(s) occurred:

* aws_cloudfront_distribution.Nexus (destroy): 1 error(s) occurred:

* aws_cloudfront_distribution.Nexus: PreconditionFailed: The request failed because it didn't meet the preconditions in one or more request-header fields.
	status code: 412, request id: 3caf8c9e-be78-11e7-9a92-a11565751fd7

my guess is this was caused by my creating the distribution, and then trying to destroy it almost immediately as I troubleshoot another problem

@cannontrodder
Copy link

@Ninir I got this error again, googled it and found this thread where I had already commented! So at least others who get this issue can see this thread!

Anyway, there are some issues I get from time to time with terraform which I now feel are extreme edge-cases caused by my behaviour as I develop a complex terraform stack. I'm iterating over and over -
destroying/applying and so on. I'm doing this with a frequency that I could not see being matched in normal production use.

It's no surprise to me now that the issues I see are around destroying cloudfront distributions, rds instances and other resources that typically take a while to get up and running and a while to destroy. e.g., I've had cf distributions take 40 minutes to destroy.

So, for those who follow, don't sweat this issue too much, just apply/destroy again. The only sane thing to do when an something in AWS fails to do as terraform asks is to shrug your shoulders and just say "that's the cloud for you".

@xenoterracide
Copy link
Author

yeah, I've seen it take some 30-40 minutes on the long end, but that usually seems to happen when correcting some error or another, like if I stop a create in order to change something, but it's already started, it then takes longer to destroy it again. I think that perhaps the best strategy though, is to ensure your cloudfront resources are separate, so you don't have to destroy them when you destroy the things backing them.

@paddycarver paddycarver removed the waiting-response Maintainers are waiting on response from community or contributor. label Nov 21, 2017
@bflad bflad added the service/cloudfront Issues and PRs that pertain to the cloudfront service. label Jan 17, 2018
@jareware
Copy link

Just ran into this as well.

Applying the same config again managed to destroy the same CF distribution that had failed (after 11 minutes), and completed successfully in the end. 👍

Terraform v0.11.7
+ provider.aws v1.18.0
+ provider.grafana v1.0.2
+ provider.influxdb v1.0.1
+ provider.null v1.0.0

@bflad
Copy link
Contributor

bflad commented Jul 26, 2018

@jareware do you happen to have the debug logs from the failed apply? Unfortunately its really hard to troubleshoot or fix this issue without knowing exactly what is causing it. Any context helps! 😄

@bflad bflad added the waiting-response Maintainers are waiting on response from community or contributor. label Jul 26, 2018
@jareware
Copy link

Sadly I don't.

I'll try to keep this in mind for the future, though!

@arsdehnel
Copy link
Contributor

I just hit this same error and I do have the debug logs. Given the fact that it's 32000 lines long and littered with possible "secret" data, how would you want to receive them?

@denniskribl
Copy link

denniskribl commented Sep 27, 2018

just hit the same error when using Terratest to test my code.

my guess is this was caused by my creating the distribution, and then trying to destroy it almost immediately as I troubleshoot another problem

It seems like that's the problem. With the testing framework I am spawning a CF distribution, making some http calls until a 200 response occurs and then immediately destroy everything.

My dirty fix was to sleep for 5minutes after CF answers with a 200... 😩

@bflad bflad removed the waiting-response Maintainers are waiting on response from community or contributor. label Nov 7, 2018
bflad added a commit that referenced this issue Mar 3, 2019
…figuration block argument `ConflictsWith` usage and fix various related issues with deployment timing

References:
* #7773
* #3077
* #1074
* #260

Here we remove the problematic `viewer_certificate` argument `ConflictsWith` schema configuration as it interferes with Terraform Module usage until Terraform 0.12 is more prevalent. More details: #7773 (comment)

When writing acceptance testing to cover setting both the `viewer_certificate` configuration block `acm_certificate_arn` and `cloudfront_default_certificate` arguments being defined, the below error was consistently happening when the test configuration included `enabled = false`:

```
--- FAIL: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn (1935.57s)
    testing.go:599: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error applying: 1 error occurred:
          * aws_cloudfront_distribution.test (destroy): 1 error occurred:
          * aws_cloudfront_distribution.test: CloudFront Distribution E3GDAPNU6UPO0O cannot be deleted: PreconditionFailed: The request failed because it didn't meet the preconditions in one or more request-header fields.
          status code: 412, request id: 4e73a086-3c33-11e9-832f-7732257f45e8
```

While debugging this the following further issues were encountered:

* The resource did not wait for deployment to complete on creation and updates so in the acceptance testing the deletion function was always handling `InProgress` operations.
* Disabled distributions would always update the distribution on deletion to disable them without checking if it was necessary, causing unnecessary delays.
* The `PreconditionFailed` error seemed to be related to some eventual consistency issue within CloudFront right after disabling the distribution, which was always done. Retrying was a sufficient workaround for the error.
* The deletion process did not ignore `NoSuchDistribution` errors such as the below:

```
--- FAIL: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn (1835.97s)
    testing.go:599: Error destroying resource! WARNING: Dangling resources
        may exist. The full state and error is shown below.

        Error: Error applying: 1 error occurred:
          * aws_cloudfront_distribution.test (destroy): 1 error occurred:
          * aws_cloudfront_distribution.test: CloudFront Distribution E2HQM77NFHV9T cannot be deleted: NoSuchDistribution: The specified distribution does not exist.
```

This changeset bundles all these fixes together as they are related.

Previous output for `ConflictsWith` acceptance testing:

```
--- FAIL: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn_ConflictsWithCloudFrontDefaultCertificate (1.64s)
    testing.go:538: Step 0 error: config is invalid: 2 problems:

        - aws_cloudfront_distribution.test: "viewer_certificate.0.acm_certificate_arn": conflicts with viewer_certificate.0.cloudfront_default_certificate
        - aws_cloudfront_distribution.test: "viewer_certificate.0.cloudfront_default_certificate": conflicts with viewer_certificate.0.acm_certificate_arn
```

Output from acceptance testing:

```
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyDomainName (2.15s)
--- PASS: TestAccAWSCloudFrontDistribution_Origin_EmptyOriginID (2.19s)
--- PASS: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn_ConflictsWithCloudFrontDefaultCertificate (1915.48s)
--- PASS: TestAccAWSCloudFrontDistribution_ViewerCertificate_AcmCertificateArn (1958.08s)
--- PASS: TestAccAWSCloudFrontDistribution_noCustomErrorResponseConfig (2121.58s)
--- PASS: TestAccAWSCloudFrontDistribution_HTTP11Config (2123.60s)
--- PASS: TestAccAWSCloudFrontDistribution_orderedCacheBehavior (2126.73s)
--- PASS: TestAccAWSCloudFrontDistribution_noOptionalItemsConfig (2126.82s)
--- PASS: TestAccAWSCloudFrontDistribution_IsIPV6EnabledConfig (2176.09s)
--- PASS: TestAccAWSCloudFrontDistribution_customOrigin (2178.92s)
--- PASS: TestAccAWSCloudFrontDistribution_S3Origin (2178.98s)
--- PASS: TestAccAWSCloudFrontDistribution_multiOrigin (2179.08s)
--- PASS: TestAccAWSCloudFrontDistribution_S3OriginWithTags (3251.14s)
```
@bflad bflad added this to the v2.1.0 milestone Mar 4, 2019
@bflad
Copy link
Contributor

bflad commented Mar 4, 2019

The fix for PreconditionFailed errors on destroy should be resolved with version 2.1.0 of the Terraform AWS Provider, releasing likely middle of this week. 👍

@bflad
Copy link
Contributor

bflad commented Mar 8, 2019

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

@ghost
Copy link

ghost commented Mar 31, 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 31, 2020
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.
Projects
None yet
10 participants