我正在尝试使用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
}
地形规划在文件中抛出policy
错误unsupported argument
s3.tfpath
,policy.tf文件中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.
(部分答案)
地区
我认为region
参数是在定义提供程序时指定的,而不是为每个资源指定的。这就是 AWS 提供商 for Terraform 的工作方式。
aws_s3_bucket_policy
同样适用于aws_s3_bucket_policy
.文档清楚地指出了此类资源仅允许的两个参数:
策略存储桶 - (必需)要应用策略的存储桶的名称。
-(必需)策略的文本。有关使用 Terraform 构建 AWS IAM 策略文档的更多信息,请参阅 AWS IAM 策略文档指南。