简体   繁体   English

使用相同的值更新 aws_cloudfront_public_key encoded_key 强制替换

[英]Updating aws_cloudfront_public_key encoded_key with the same value forces replacement

I am trying to create aws_cloudfront_public_key resource in terraform using below mentioned code,我正在尝试使用下面提到的代码在 terraform 中创建aws_cloudfront_public_key资源,

resource "aws_cloudfront_public_key" "key" {
  name        = "my-cf-pubkey"
  encoded_key = file("${path.module}/abcd.pem")
}

First time if terraform apply is getting executed then its getting created successfully.如果 terraform apply 第一次被执行,那么它就成功创建了。 But all terraform apply post it trying to recreate aws_cloudfront_public_key ie its getting destroyed and recreate again even if public key is not getting changed, which is wrong behaviour.但是所有 terraform apply post it trying to recreate aws_cloudfront_public_key即它被破坏并再次重新创建,即使公钥没有被更改,这是错误的行为。

How to over come this issue?如何克服这个问题?

Plan output is:计划输出是:

  # aws_cloudfront_public_key.documents-signing-key must be replaced
-/+ resource "aws_cloudfront_public_key" "documents-signing-key" {
      ~ caller_reference = "terraform-20221218060345896500000002" -> (known after apply)
      ~ encoded_key      = <<-EOT # forces replacement
            -----BEGIN PUBLIC KEY-----
            -----END PUBLIC KEY-----
        EOT
      ~ etag             = "E1PKWHEWOCNZS4" -> (known after apply)
      ~ id               = "K15GFD3XARNT0X" -> (known after apply)
        name             = "my-cf-pubkey"
      + name_prefix      = (known after apply)
        # (1 unchanged attribute hidden)
    }

you can try using lifecycle block to prevent Terraform from attempting to recreate the resource again as shown below您可以尝试使用生命周期块来防止 Terraform 再次尝试重新创建资源,如下所示

resource "aws_cloudfront_public_key" "key" {
  name        = "my-cf-pubkey"
  encoded_key = file("${path.module}/abcd.pem")
  
  lifecycle {
    create_before_destroy = true
  }
}

Let me know if this will help you.让我知道这是否对您有帮助。

If the encoded_key attribute of your resource is not changing between Terraform runs, then you can use the ignore_changes attribute to tell Terraform to not attempt to check for changes.如果您的资源的 encoded_key 属性在 Terraform 运行之间没有变化,那么您可以使用 ignore_changes 属性告诉 Terraform 不要尝试检查更改。

For example:例如:

resource "aws_cloudfront_public_key" "key" {
  name        = "my-cf-pubkey"
  encoded_key = file("${path.module}/abcd.pem")
  ignore_changes = ["encoded_key"]
}

@JatinPanchal @JatinPanchal

Its worked after just added the new line(enter key) at the end of pem file it worked.在它工作的 pem 文件末尾添加新行(输入键)后它就工作了。

-----BEGIN PUBLIC KEY-----
MFwwDQYJKoZIhvcNAQEBBQADSwAwSAJBAKj34GkxFhD90vcNLYLInFEX6Ppy1tPf
9Cnzj4p4WGeKLs1Pt8QuKUpRKfFLfRYC9AIKjbJTWit+CqvjWYzvQwECAwEAAQ==
-----END PUBLIC KEY-----

Ref: https://github.com/hashicorp/terraform-provider-aws/issues/20081参考: https ://github.com/hashicorp/terraform-provider-aws/issues/20081

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 在哪里放置 Cloudfront 密钥对以进行 Wordpress 身份验证 - Where to place Cloudfront Key Pairs for Wordpress Authentication 创建 terraform 资源 aws_key_pair 错误:InvalidKey.Format:密钥不是有效的 OpenSSH 公钥格式 - Creating terraform resource aws_key_pair error: InvalidKey.Format: Key is not in valid OpenSSH public key format aws cli:如何找到 kms 密钥 ID? - aws cli: how to find kms key id? 无法为 reCAPTCHA 流生成/检索公共加密密钥 - Failed to generate/retrieve public encryption key for reCAPTCHA flow Cloudfront 在没有公共访问的情况下为 S3 存储桶源提供通过 AWS CDK Python 创建的访问被拒绝的响应 - Cloudfront give Access denied response created through AWS CDK Python for S3 bucket origin without public Access AWS PowerShell 更新 CloudFront 分布 - AWS PowerShell update CloudFront distribution aws Dynamodb 通过 aws 管理控制台中的分区键获取多个项目 - aws Dynamodb get multiple items by partition key in aws management console 使用 aws cloudfront 后网站流量下降 - website traffic dropped after using aws cloudfront 获取公钥时出现 Google Cloud KMS 错误 - Google Cloud KMS error when getting public key 为 AWS lambda 存储 Firebase 管理员私钥文件的最佳方式 - Best way to store Firebase admin private key file for AWS lambda
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM