【发布时间】:2021-06-23 07:08:07
【问题描述】:
执行 terraform apply 时,出现以下错误。
我对 terraform 很陌生,请原谅。
我正在尝试使用 terraform 脚本在 AWS s3 中创建以下存储桶。
有什么修复错误的建议吗?
-
x-d-dev/some/IN/
-
x-d-dev/some/OUT/
-
x-d-qa/some/IN/
-
x-d-qa/some/OUT/
-
x-d-prod/some/IN/
-
x-d-prod/some/OUT/
variable "s3_bucket_env" {
type = list(string)
default = ["x-d-dev", "x-d-qa","x-d-prod"]
}
resource "aws_s3_bucket" "b" {
count = length(var.s3_bucket_env) //count will be 3
bucket = var.s3_bucket_env[count.index]
acl = "private"
}
variable "s3_bucket_names" {
type = list
default = ["some/IN/", "some/OUT/"]
}
resource "aws_s3_bucket_object" "some_s3_bucket" {
count = length(var.s3_bucket_names) //count will be 3
bucket = aws_s3_bucket.b[count.index]
key = var.s3_bucket_names[count.index]
acl = "private"
}
错误
PS C:\S3\S3_Creation\another-optiin> terraform apply
aws_s3_bucket.b[0]: Refreshing state... [id=x-d-dev]
aws_s3_bucket_object.x_s3_buckets[1]: Refreshing state... [id=some/OUT/]
aws_s3_bucket_object.x_s3_buckets[0]: Refreshing state... [id=some/IN/]
Error: Incorrect attribute value type
on 1.tf line 49, in resource "aws_s3_bucket_object" "x_s3_buckets":
49: bucket = aws_s3_bucket.b[count.index]
|----------------
| aws_s3_bucket.b is tuple with 3 elements
| count.index is 1
Inappropriate value for attribute "bucket": string required.
Error: Incorrect attribute value type
```on 1.tf line 49, in resource "aws_s3_bucket_object" "x_s3_buckets":
49: bucket = aws_s3_bucket.b[count.index]
|----------------
| aws_s3_bucket.b is tuple with 3 elements
| count.index is 0
Inappropriate value for attribute "bucket": string required.```
【问题讨论】:
标签: amazon-web-services amazon-s3 terraform