【问题标题】:Terraform Error - Inappropriate Value for attribute : string requiredTerraform 错误 - 属性值不合适:需要字符串
【发布时间】:2021-06-23 07:08:07
【问题描述】:

执行 terraform apply 时,出现以下错误。
我对 terraform 很陌生,请原谅。
我正在尝试使用 terraform 脚本在 AWS s3 中创建以下存储桶。
有什么修复错误的建议吗?

  1. x-d-dev/some/IN/

  2. x-d-dev/some/OUT/

  3. x-d-qa/some/IN/

  4. x-d-qa/some/OUT/

  5. x-d-prod/some/IN/

  6. 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


    【解决方案1】:

    您当前正在传递整个存储桶对象,而您应该只传递存储桶名称。

    改变这个:

     bucket        = aws_s3_bucket.b[count.index]
    

    到这里:

     bucket        = aws_s3_bucket.b[count.index].bucket
    

    【讨论】:

    • 这有效,但没有创建我预期的所有文件夹。 ``` 1) xd-dev/some/IN/ 2) xd-dev/some # /OUT 缺失 3) xd-qa/some 4) xd-qa/some/OUT/ 5) xd-prod # some// OUT 缺失 6) xd-prod #some//IN 缺失 ````
    猜你喜欢
    • 2021-11-27
    • 2020-04-09
    • 2020-08-09
    • 2021-07-17
    • 1970-01-01
    • 1970-01-01
    • 2021-02-09
    • 2021-06-18
    • 2019-12-28
    相关资源
    最近更新 更多