【问题标题】:terraform plan throws Unsupported argument and attribute cannot be set errorterraform plan 抛出 Unsupported argument and attribute cannot be set 错误
【发布时间】:2021-03-20 07:30:22
【问题描述】:

我正在尝试使用 terraform 创建一个 s3 存储桶。以下是我的 s3.tf 文件

resource "aws_s3_bucket" "b" {
  bucket = "my-bucket"
  acl    = "private"
  force_destroy = "true"
  policy = ""
  region = "us-east-1"

  tags = {
    org = "xyz"
    Environment = "CI"
    project = "abc"
  }

  versioning {
    enabled = "true"
  }

  cors_rule {
    allowed_headers = ["*"]
    allowed_methods = ["PUT", "POST"]
    allowed_origins = ["https://s3-website-test.hashicorp.com"]
    expose_headers  = ["ETag"]
    max_age_seconds = 3000
  }



}

// S3 bucket-level Public Access Block configuration
resource "aws_s3_bucket_public_access_block" "b" {
  bucket = aws_s3_bucket.b.id

  block_public_acls       = true
  block_public_policy     = true
  ignore_public_acls      = true
  restrict_public_buckets = true
}

Policy.tf 文件

resource "aws_s3_bucket_policy" "b" {
  bucket = aws_s3_bucket.b.id
  path = "/"
  description = "Policy for api to access S3 Bucket"

  policy = <<POLICY
{
    "Version": "2012-10-17",
    "Statement": [
        {
            "Effect": "Allow",
            "Action": [
                "s3:ListBucket"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket"
            ]
        },
        {
            "Effect": "Allow",
            "Action": [
                "s3:*"
            ],
            "Resource": [
                "arn:aws:s3:::my-bucket/*"
            ]
        }
    ]
}
POLICY
}

terraform 计划为 s3.tf 文件中的 policypolicy.tf 文件中的 pathdescription 和 @ 抛出 unsupported argument 错误region 的 987654327@ 错误。我可以在以前版本的 terraform 中初始化这些参数。他们现在不支持吗?如果现在不支持它们,有没有办法在 s3.tfpolicy.tf 文件中初始化这些参数?

错误信息:

Error: Unsupported argument

  on s3.tf line 6, in resource "aws_s3_bucket" "b":
   6:   bucket_policy = ""

An argument named "policy" is not expected here.

Error: Computed attribute cannot be set

  on s3.tf line 7, in resource "aws_s3_bucket" "b":
   7:   region = "us-east-1"

Error: Unsupported argument

  on policy.tf line 30, in resource "aws_s3_bucket_policy" "b":
  30:   path = "/"

An argument named "path" is not expected here.

Error: Unsupported argument

  on policy.tf line 31, in resource "aws_s3_bucket_policy" "b":
  31:   description = "Policy for api to access S3 Bucket"

An argument named "description" is not expected here.


【问题讨论】:

  • "throw unsupported argument error for region and policy in s3.tf" - 请粘贴准确的错误信息
  • @GrzegorzOledzki 我添加了错误消息

标签: amazon-web-services amazon-s3 terraform terraform-provider-aws


【解决方案1】:

(部分回答)

地区

我认为region 参数是在您定义提供者时指定的,而不是针对每个资源。这就是适用于 Terraform 的 AWS 提供商的工作方式。

aws_s3_bucket_policy

​​>

aws_s3_bucket_policy 也是如此。 The docs 明确指出此类资源只允许使用两个参数:

bucket -(必需)要应用策略的存储桶的名称。

policy - (必需)策略的文本。有关使用 Terraform 构建 AWS IAM 策略文档的更多信息,请参阅 AWS IAM 策略文档指南。

【讨论】:

  • 但是我可以在之前版本的 terraform 中添加这些资源。它们是否已弃用或删除?
  • 我不知道这些变化,但它是 AWS Terraform 提供程序的不同版本,而不是 Terraform 本身的版本,这会导致这样的变化。您可以使用旧版本的 AWS 插件/提供程序尝试新的 Terraform 版本。
猜你喜欢
  • 2023-04-05
  • 1970-01-01
  • 2018-11-28
  • 2022-12-17
  • 2023-02-02
  • 2017-09-28
  • 2017-08-07
  • 2022-12-01
  • 1970-01-01
相关资源
最近更新 更多