【问题标题】:Cross region replication of AWS ECR repositoryAWS ECR 存储库的跨区域复制
【发布时间】:2021-07-13 07:36:58
【问题描述】:

我正在尝试使用 terraform 将我的 AWS ECR 存储库复制到同一账户中的多个区域。我从 AWS 控制台手动尝试它工作正常,但从 terraform 中,我无法找到解决方案。 我尝试了什么: 我尝试为名为 replicate_region 的区域创建一个单独的变量,并尝试在列表中提供该区域,但它不断给我一个名为

的错误

属性“区域”的值不合适:需要字符串。

这里是变量代码:

variable "replicate_region" {
 description = "value"
 type = list(string)
}

这是我的 ecr 复制代码:

resource "aws_ecr_replication_configuration" "replication" {
 replication_configuration {
  rule {
   destination {
     region      = var.replicate_region
     registry_id = "xxxxxxxx"
  }
}}}

谁能帮帮我?

谢谢,

【问题讨论】:

    标签: amazon-web-services terraform amazon-ecr terragrunt elastic-container-registry


    【解决方案1】:

    您的replicate_region 应该是字符串,而不是字符串列表。应该是,例如:

    variable "replicate_region" {
     description = "value"
     type = string
     default = "us-east-1"
    }
    

    更新

    使用dynamic block进行迭代。

    variable "replicate_region" {
     description = "value"
     type = list(string)
     default = ["us-east-1", "ap-southeast-1", "ap-south-1"]
    }
    
    resource "aws_ecr_replication_configuration" "replication" {
    
     replication_configuration {
      rule {
    
       dynamic "destination" {
    
           for_each = toset(var.replicate_region) 
    
           content {
             region      = destination.key
             registry_id = "xxxxxxxx"
          }
      }
    }}}
    

    【讨论】:

    • 是的,对于单个区域,我可以按照您建议的方式使用它。但我需要多个区域作为复制的一部分。例如,如果我在 us-east-1 区域创建 ECR 存储库,并希望在 ap-southeast-1 和 ap-south-1 中复制它。
    • @pawan19 然后你必须像更新的答案一样迭代。但我不确定您是否可以拥有多个 aws_ecr_replication_configuration,或者 AWS 只支持一个。
    • 它起作用了,但是以一种奇怪的方式,我在默认值 [ap-southeast-1 和 ap-south-1] 中只输入了两个区域,并且 terraform 被视为从 Southeast-1 到 south- 的区域变化1...你能给我一个提示来解决这个问题吗? 〜区域=“ap-southeast-1”->“ap-south-1”
    • @pawan19 我不确定你所说的改变是什么意思? TF申请后,它改变了地区?
    • 非常感谢 Marcin 的所有帮助...它已解决 :)
    【解决方案2】:

    更简单的方法:

    resource "aws_ecr_replication_configuration" "replication" {
      replication_configuration {
        rule {
          destination {
            region      = "us-east-2"
            registry_id = "xxxxxxxx"
          }
          destination {
            region      = "ap-southeast-1"       
            registry_id = "xxxxxxxx"
          }
        }
      }
    }
    

    【讨论】:

      猜你喜欢
      • 2020-06-24
      • 2021-10-16
      • 1970-01-01
      • 2018-03-31
      • 1970-01-01
      • 1970-01-01
      • 2021-11-15
      • 1970-01-01
      • 2022-08-04
      相关资源
      最近更新 更多