I have a separate module with its own State File for the Networking resources in AWS. I’m using the terraform-aws-modules/vpc/aws and terraform-aws-modules/vpc/aws//modules/vpc-endpoints modules for this.
I have an S3 bucket for my backend and a DynamoDB table to control the locking. There is already infrastructure deployed, and when I modify something and try to apply the terraform plan
command, I get the following messages:
╷
│ Error: Duplicate variable declaration
│
│ on .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/variables.tf line 25:
│ 25: variable "subnet_ids" {
│
│ A variable named "subnet_ids" was already declared at .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/variables 3.tf:25,1-22. Variable names must be unique within a module.
╵
╷
│ Error: Duplicate variable declaration
│
│ on .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/variables.tf line 31:
│ 31: variable "tags" {
│
│ A variable named "tags" was already declared at .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/variables 3.tf:31,1-16. Variable names must be unique within a module.
╵
╷
│ Error: Duplicate variable declaration
│
│ on .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/variables.tf line 37:
│ 37: variable "timeouts" {
│
│ A variable named "timeouts" was already declared at .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/variables 3.tf:37,1-20. Variable names must be unique within a module.
╵
╷
│ Error: Duplicate required providers configuration
│
│ on .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/versions.tf line 4, in terraform:
│ 4: required_providers {
│
│ A module may have only one required providers configuration. The required providers were previously configured at .terraform/modules/vpc_endpoints_nocreate/modules/vpc-endpoints/versions 3.tf:4,3-21.
(and many more like the above)
If I do the following:
rm -rf .terraform && .terraform.lock.hcl
terraform init
terraform workspace select prod
terraform refresh
terraform plan
terraform apply
It will work. But then after the apply
is completed, if I modify something again and try to perform terraform plan
I get the same errors… then, I need to redo the steps above in order for me to be able to plan/apply the changes.
What can I do here? Any help is much appreciated!
Terraform v1.1.5
on darwin_arm64
+ provider registry.terraform.io/hashicorp/aws v3.74.1
+ provider registry.terraform.io/hashicorp/template v2.2.0