Agr*_*rim 3 amazon-web-services terraform devops
我正在尝试使用 terraform 来设置 S3 + Cloudfront 静态站点。最初,我按照https://alimac.io/static-websites-with-s3-and-hugo-part-1/中的步骤成功设置了该网站
但是,后来我将 terraform 状态后端从 更改为local
Now s3
,当我执行时,terraform apply
出现以下错误:
Error: Error applying plan:
2 error(s) occurred:
* aws_cloudfront_distribution.primary_domain: 1 error(s) occurred:
* aws_cloudfront_distribution.primary_domain: CNAMEAlreadyExists: One or more of the CNAMEs you provided are already associated with a different resource.
status code: 409, request id: <removed>
* aws_cloudfront_distribution.secondary_domain: 1 error(s) occurred:
* aws_cloudfront_distribution.secondary_domain: CNAMEAlreadyExists: One or more of the CNAMEs you provided are already associated with a different resource.
status code: 409, request id: <removed>
Run Code Online (Sandbox Code Playgroud)
关于为什么会发生这种情况以及我能做些什么来解决这个问题有什么想法吗?
Terraform 使用状态文件来跟踪其管理的资源。如果它没有特定资源(在本例中可能是您的aws_cloudfront_distribution.primary_domain
资源),它将创建一个新资源并将该新资源的 ID 存储在您的状态文件中。
看起来您terraform apply
对本地状态文件做了 a,将后端更改为 s3,而不将状态移植到 s3,然后terraform apply
再次运行。第二次 S3 支持的运行处于空白状态,因此它尝试aws_cloudfront_distribution
再次重新创建您的资源。看起来该错误表明两个发行版使用相同的 CNAME 存在冲突,如果您运行 Terraform 两次而不跟踪其间的状态,就会发生这种情况。
您有几个选项可以解决此问题:
terraform destroy
删除它创建的资源,切换回 s3,然后
terraform apply
重新开始。请注意,这实际上会删除资源。terraform import
将您使用本地状态文件创建的资源放入 S3 后端。用 执行此操作terraform import
aws_cloudfront_distribution.primary_domain <EXISTING CLOUDFRONT DIST.
ID>
。 归档时间: |
|
查看次数: |
4582 次 |
最近记录: |