我正在尝试使用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计划在unsupported argument s3.tf文件中抛出policy的path错误,在policy.tf文件中抛出path和description,对于region抛出Computed attribute cannot be set错误。我可以在以前的terraform版本中对这些论点进行修正。他们现在不支持吗?如果现在不支持这些参数,那么是否有办法使、s3.tf、和policy.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.发布于 2020-12-08 23:02:42
(部分答覆)
地域
我认为region参数是在定义提供程序时指定的,而不是为每个资源指定的。这就是Terraform的AWS提供者的工作方式。
aws_s3_bucket_policy
同样适用于aws_s3_bucket_policy。医生们只为这种类型的资源清楚地指示了两个允许的参数:
适用于此策略的桶的名称(必需)。策略-(需要)策略的文本。有关使用Terraform构建AWS IAM策略文档的详细信息,请参阅AWS IAM策略文档指南。
https://stackoverflow.com/questions/65208042
复制相似问题