Terraform 计划错误:不支持的参数
Terraform plan err: Unsupported argument
我有这样的资源repo/dynamo/main.tf
:
resource "aws_dynamodb_table" "infra_locks" {
name = "infra-locks"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
我将上面的文件作为模块引用 github repo
我引用上面文件的tf文件repo/example/main.tf
:
provider "aws" {
region = var.region
}
module "dynamodb_table" {
source = "../dynamodb_table"
name = "my-table"
}
我 terraform init
成功,但在 运行 terraform plan
时失败
Error: Unsupported argument
on main.tf line 14, in module "dynamodb_table":
14: name = "my-table"
An argument named "name" is not expected here.
我该如何解决这个问题?
提前谢谢
正如@luk2302 所说:
resource "aws_dynamodb_table" "infra_locks" {}
上述资源确实具有 name
属性,但它不是变量,因此我们无法为其分配任何内容。
这里有点迷糊。
我已经通过稍微更改来修复:repo/dynamo/main.tf
resource "aws_dynamodb_table" "infra_locks" {
name = var.name
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
repo/dynamo/variable.tf
variable "name" {
description = "dynamo table name"
default = null
}
最后,我们可以配置您的 dynamo_table
的名字。
我有这样的资源repo/dynamo/main.tf
:
resource "aws_dynamodb_table" "infra_locks" {
name = "infra-locks"
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
我将上面的文件作为模块引用 github repo
我引用上面文件的tf文件repo/example/main.tf
:
provider "aws" {
region = var.region
}
module "dynamodb_table" {
source = "../dynamodb_table"
name = "my-table"
}
我 terraform init
成功,但在 运行 terraform plan
Error: Unsupported argument
on main.tf line 14, in module "dynamodb_table":
14: name = "my-table"
An argument named "name" is not expected here.
我该如何解决这个问题? 提前谢谢
正如@luk2302 所说:
resource "aws_dynamodb_table" "infra_locks" {}
上述资源确实具有 name
属性,但它不是变量,因此我们无法为其分配任何内容。
这里有点迷糊。
我已经通过稍微更改来修复:repo/dynamo/main.tf
resource "aws_dynamodb_table" "infra_locks" {
name = var.name
billing_mode = "PAY_PER_REQUEST"
hash_key = "LockID"
attribute {
name = "LockID"
type = "S"
}
}
repo/dynamo/variable.tf
variable "name" {
description = "dynamo table name"
default = null
}
最后,我们可以配置您的 dynamo_table
的名字。