【问题标题】:Terraform plan err: Unsupported argumentTerraform 计划错误:不支持的参数
【发布时间】:2021-06-27 09:05:06
【问题描述】:

我有这样的资源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.

我该如何解决这个问题? 提前谢谢

【问题讨论】:

  • 嗯,这个模块是来自 github 还是来自 "../dynamodb_table"?当前您引用了一个本地模块,该模块是否有 name 变量?
  • 是的,我从本地使用它,我已经初始化成功Initializing modules... - dynamo_table in ../dynamo Initializing the backend... Initializing provider plugins... - Reusing previous version of hashicorp/aws from the dependency lock file - Using previously-installed hashicorp/aws v3.34.0 Terraform has been successfully initialized!
  • 那么github链接就无关紧要了,问题是:你本地的dynamodb_tablename变量吗?答案可能是:不会。
  • @luk2302 我已经在问题的开头展示了 dynamo/main.tf,它有 name 属性
  • 那不是变量。

标签: terraform terraform-provider-aws


【解决方案1】:

正如@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 的名字。

【讨论】:

    猜你喜欢
    • 2021-01-30
    • 2021-01-16
    • 2021-01-16
    • 2021-01-09
    • 1970-01-01
    • 2020-10-15
    • 2021-11-11
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多