这是我的代码源
\nresource "aws_s3_bucket_object" "object" {\n count = var.s3_create[1] ? 1 : 0 \n depends_on = [aws_s3_bucket.bucket_backup]\n for_each = local.buckets_and_folders \n bucket = each.value.bucket_backup\n key = format("%s/", each.value.folder)\n force_destroy = true\n} \nRun Code Online (Sandbox Code Playgroud)\n换句话说,我正在尝试创建aws_s3_bucket_object依赖于变量的对象s3_create对象...如果为真则创建,否则不创建。
问题:我无法在创建 terraform 资源时使用以下语法的组合,我正在了解:
\nError: Invalid combination of "count" and "for_each"\n\xe2\x94\x82\n\xe2\x94\x82 on ..\\s3\\resources.tf line 51, in resource "aws_s3_bucket_object" "object":\n\xe2\x94\x82 51: for_each = local.buckets_and_folders\n\xe2\x94\x82\n\xe2\x94\x82 The "count" and "for_each" meta-arguments are mutually-exclusive, only one should be used to be explicit about the number …Run Code Online (Sandbox Code Playgroud) 使用 terraform,我尝试使用 count.index 将计数包含在我的资源标签中,但出现此错误:
\n\n\n错误:资源“aws_subnet”“prod_sn”中 ..\\modules\\sn\\ressources.tf 第 16 行上的属性值类型\n\xe2\x94\x82\n\xe2\x94\x82 不正确:\n \xe2\x94\x82 16: 标签 = var.sn_tags[count.index]\n\xe2\x94\x82 \xe2\x94\x9c\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80 \xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2 \x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\xe2\x94\x80\n\xe2\x94\x82 \xe2\x94\x82 count.index 是一个数字,已知仅在 apply\n\xe2\x94\x82 \xe2\x94\x82 var.sn_tags 是字符串列表,仅在 apply\n\xe2\x94\x82\n\xe2\x94\x82 后才知道 属性值不合适“tags”:所需字符串的映射。
\n
变量.tf
\nvariable "sn_tags" {\n type = list (string)\n default = ["aa", "bb"]\n}\nRun Code Online (Sandbox Code Playgroud)\n资源.tf
\nresource "aws_subnet" "prod_sn" {\n count = length(var.sn_cidr)\n vpc_id = var.vpc_id\n cidr_block = var.sn_cidr[count.index]\n availability_zone = data.aws_availability_zones.azs.names[count.index]\n tags = var.sn_tags[count.index] \n}\nRun Code Online (Sandbox Code Playgroud)\n主.tf
\n# Create Public Subnet on availability_zone "3a"\nmodule "publicSn-a" {\n …Run Code Online (Sandbox Code Playgroud)