“”虽然我正在使用terraform创建s3存储桶的vpc流日志模块,但其抛出错误如下: 此处不应使用名为“ flow_log_destination_type”的参数。 此处不应使用名为“ flow_log_destination_arn”的参数。 在Terraform文档中,我可以看到要填充的详细信息,例如log_destination_type和log_destination_arn, 并且我在GitHub上找到了一些文档,它们完全说出了相同的代码,但是在尝试时对我不起作用
产生以下错误:
Error: Unsupported argument
on main.tf line 52, in module "vpc_with_flow_logs_s3_bucket":
52: flow_log_destination_type = "s3"
An argument named "flow_log_destination_type" is not expected here.
Error: Unsupported argument
on main.tf line 53, in module "vpc_with_flow_logs_s3_bucket":
53: flow_log_destination_arn = "${aws_s3_bucket.terra-test2-lifecycle.arn}"
An argument named "flow_log_destination_arn" is not expected here.
Error: Unsupported argument
on main.tf line 55, in module "vpc_with_flow_logs_s3_bucket":
55: vpc_flow_log_tags = {
An argument named "vpc_flow_log_tags" is not expected here.
我在哪里做错了?”
module "vpc" {
source = "terraform-aws-modules/vpc/aws"
version = "2.33.0"
# Interpolated from the workspace
name = "${terraform.workspace}"
cidr = var.vpc_cidr
azs = var.vpc_azs
private_subnets = var.vpc_private_subnets
public_subnets = var.vpc_public_subnets
enable_nat_gateway = var.vpc_enable_nat_gw
single_nat_gateway = var.vpc_single_nat_gw
public_subnet_tags = {
Name = "${terraform.workspace}-public"
}
private_subnet_tags = {
Name = "${terraform.workspace}-private"
}
tags = {
Name = "${terraform.workspace}"
}
vpc_tags = {
owner = "PEDevOps"
environment = "${terraform.workspace}"
version = "0.0.1"
managedby = "Terraform"
}
}
module "vpc_with_flow_logs_s3_bucket" {
source = "../../"
log_destination_type = "s3"
log_destination_arn = "${aws_s3_bucket.terra-test2-lifecycle.arn}"
vpc_flow_log_tags = {
Name = "vpc-flow-logs-s3-bucket"
}
}
resource "aws_s3_bucket" "terra-test-lifecycle" {
bucket = "terra-test-lifecycle"
acl = "private"
lifecycle_rule {
id = "log"
enabled = true
prefix = "log/"
tags = {
"rule" = "log"
"autoclean" = "true"
}
transition {
days = 30
storage_class = "STANDARD_IA" # or "ONEZONE_IA"
}
expiration {
days = 60
}
}
lifecycle_rule {
id = "tmp"
prefix = "tmp/"
enabled = true
expiration {
date = "2020-06-06"
}
}
}
为什么Terraform失败并显示“这里不应该有一个名为“ flow_log_destination_type”的参数”?
答案 0 :(得分:0)
如果传递模块不期望的变量,则会发生此错误。
例如
module "vpc_with_flow_logs_s3_bucket" {
source = "../../"
log_destination_type = "s3"
log_destination_arn = "${flow_log_destination_arn}"
vpc_flow_log_tags = {
Name = "vpc-flow-logs-s3-bucket"
}
}
如果您指定此选项,则如果在main.tf中定义了flow_log_destination_arn变量,而在未在variables.tf中定义了变量,则将引发错误。
来源: ../../ vpc_with_flow_logs_s3_bucket / main.tf resource "aws_flow_log" "example" {
iam_role_arn = "${aws_iam_role.example.arn}"
log_destination = "${aws_cloudwatch_log_group.example.arn}"
traffic_type = "ALL"
vpc_id = "${aws_vpc.example.id}"
}
答案 1 :(得分:0)
位于“ ../../”的模块未声明任何 log_destination_type , log_destination_arn 或 vpc_flow_log_tags 变量和Terraform认为在这样的模块块中分配未声明的变量是错误的:
module "vpc_with_flow_logs_s3_bucket" {
source = "../../"
log_destination_type = "s3"
log_destination_arn = "${flow_log_destination_arn}"
vpc_flow_log_tags = {
Name = "vpc-flow-logs-s3-bucket"
}
}
“ ../../”最有可能是 vpc_with_flow_logs_s3_bucket 模块的错误源路径,您应该对此进行修复。如果您位于声明了此模块块的模块的源路径中,并且运行cd ../../
,您是否会使用 vpc_with_flow_logs_s3_bucket Terraform代码进入目录?如果不是,则源设置不正确,您需要对其进行修复。
如果“ ../../”是正确的路径,则应添加缺少的变量声明。
variable "log_destination_type" {
type = string
}
variable "log_destination_arb" {
type = string
}
variable "vpc_flow_log_tags" {
type = map(string)
}
答案 2 :(得分:0)
我将分享此错误的另一个可能原因。
这样编写配置块:
scaling_config = {
desired_size = 2
max_size = 2
min_size = 2
}
代替(注意=
等号):
scaling_config {
desired_size = 2
max_size = 2
min_size = 2
}
将给出错误An argument named "scaling_config" is not expected here
。
(*)请注意,更改后,如果确实不支持块类型,则错误标题将更改为:
Error: Unsupported argument
收件人:
Error: Unsupported block type
错误消息为:
Blocks of type "scaling_config" are not expected here.