1
votes

I have a resource like this 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"
  }
}

And I refer above file as a module follow github repo

Tf file where I refer to above file repo/example/main.tf:

provider "aws" {
  region = var.region
}

module "dynamodb_table" {
  source = "../dynamodb_table"

  name      = "my-table"
}

I have terraform init success but fail when run 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.

How can i fix this? Tks in advance

1
Well, is the module from github or is it from "../dynamodb_table"? Currently you reference a local module, does that module have a name variable?luk2302
Yes, I use it from local, I have init success 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!Tho Quach
Then the github link is irrelevant and the question is: does your local dynamodb_table have a name variable? The answer probably is: no.luk2302
@luk2302 I have show the dynamo/main.tf in beginning of the question, it has name attributeTho Quach
That is not a variable.luk2302

1 Answers

0
votes

As @luk2302 has said:

resource "aws_dynamodb_table" "infra_locks" {}

The above resource exactly has name attribute but it 's not a variable so we can not assign anything to it.

There is a confused right here. I have fixed by change a little bit: 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
}

And final, we can configure your dynamo_table 's name.