[英]Cross region replication of AWS ECR repository
我正在嘗試使用 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"
}
}}}
誰能幫幫我?
謝謝,
您的replicate_region
應該是 string ,而不是字符串列表。 它應該是,例如:
variable "replicate_region" {
description = "value"
type = string
default = "us-east-1"
}
更新
使用動態塊進行迭代。
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"
}
}
}}}
更簡單的方法:
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"
}
}
}
}
variable "replicas" {
description = "ECR replicas region list"
type = list(string)
default = [
{
region = "aaa"
registry_id = "11111111"
},
{
region = "bbb"
registry_id = "22222222"
}
]
}
resource "aws_ecr_replication_configuration" "replication" {
count = length(var.replicas) != 0 ? 1 : 0
replication_configuration {
rule {
dynamic "destination" {
for_each = var.replicas
content {
region = destination.value.region
registry_id = destination.value.registry_id
}
}
repository_filter {
filter = var.filter
filter_type = "PREFIX_MATCH"
}
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.