hashicorp / terraform-provider-aws

The AWS Provider enables Terraform to manage AWS resources.
https://registry.terraform.io/providers/hashicorp/aws
Mozilla Public License 2.0
9.7k stars 9.07k forks source link

[Bug]: unable to set "name" argument in aws_api_gateway_vpc_link when using as a module. #32101

Closed vysh0x50 closed 7 months ago

vysh0x50 commented 1 year ago

Terraform Core Version

1.5.0

AWS Provider Version

4.67.0

Affected Resource(s)

aws_api_gateway_vpc_link

Expected Behavior

It should support "name" argument as per the documentaion.

Actual Behavior

Getting the error: │ An argument named "name" is not expected here.

Relevant Error/Panic Output Snippet

╷
│ Error: Unsupported argument
│ 
│   on main.tf line 4, in module "vpclink":
│    4:   name        = var.vpclink_name
│ 
│ An argument named "name" is not expected here.
╵

Terraform Configuration Files

tree .
.
├── main.tf
├── modules
│   └── vpc_link
│       ├── main.tf
│       ├── outputs.tf
│       └── variables.tf
├── outputs.tf
├── provider.tf
├── terraform.tfstate
├── terraform.tfstate.backup
├── terraform.tfvars
└── variables.tf

-> modules/vpc_link/main.tf

resource "aws_api_gateway_vpc_link" "vpclink" {
  name        = var.vpclink_name
  target_arns = var.target_arn
}

-> modules/vpc_link/variables.tf

variable "vpclink_name" {
  type = string
  default = ""
}

variable "target_arn" {
  type = list(string)
  default = [ "" ]
}

->modules/vpc_link/outputs.tf

output "vpclink_id" {
  description = "The ID of the VPC Link"
  value       = aws_api_gateway_vpc_link.vpclink.id
}

->main.tf

module "vpclink" {
  source = "./modules/vpc_link"

  name        = var.vpclink_name
  target_arn = var.target_arn
}

->variables.tf

variable "vpclink_name" {
  type = string
  default = ""
}

variable "target_arn" {
  type = list(string)
}

->terraform.tfvars

vpclink_name = "ms-vpclink"
target_arn   = ["<<load_balancer_arn>>"]

->outputs.tf

output "vpc_link_id" {
  value = module.vpclink.id
}

Steps to Reproduce

  1. Include your name and target_arn in the terraform.tfvars
  2. terraform validate

Debug Output

2023-06-20T14:46:42.641+0530 [INFO]  Terraform version: 1.5.0
2023-06-20T14:46:42.641+0530 [DEBUG] using github.com/hashicorp/go-tfe v1.26.0
2023-06-20T14:46:42.641+0530 [DEBUG] using github.com/hashicorp/hcl/v2 v2.16.2
2023-06-20T14:46:42.641+0530 [DEBUG] using github.com/hashicorp/terraform-svchost v0.1.0
2023-06-20T14:46:42.641+0530 [DEBUG] using github.com/zclconf/go-cty v1.12.2
2023-06-20T14:46:42.641+0530 [INFO]  Go runtime version: go1.20.5
2023-06-20T14:46:42.641+0530 [INFO]  CLI args: []string{"terraform", "validate", "-no-color"}
2023-06-20T14:46:42.641+0530 [TRACE] Stdout is not a terminal
2023-06-20T14:46:42.641+0530 [TRACE] Stderr is not a terminal
2023-06-20T14:46:42.641+0530 [TRACE] Stdin is a terminal
2023-06-20T14:46:42.641+0530 [DEBUG] Attempting to open CLI config file: /home/vyshnavlal/.terraformrc
2023-06-20T14:46:42.641+0530 [DEBUG] File doesn't exist, but doesn't need to. Ignoring.
2023-06-20T14:46:42.641+0530 [DEBUG] ignoring non-existing provider search directory terraform.d/plugins
2023-06-20T14:46:42.641+0530 [DEBUG] ignoring non-existing provider search directory /home/vyshnavlal/.terraform.d/plugins
2023-06-20T14:46:42.641+0530 [DEBUG] ignoring non-existing provider search directory /home/vyshnavlal/.local/share/terraform/plugins
2023-06-20T14:46:42.641+0530 [DEBUG] ignoring non-existing provider search directory /home/vyshnavlal/.local/share/flatpak/exports/share/terraform/plugins
2023-06-20T14:46:42.641+0530 [DEBUG] ignoring non-existing provider search directory /var/lib/flatpak/exports/share/terraform/plugins
2023-06-20T14:46:42.641+0530 [DEBUG] ignoring non-existing provider search directory /usr/local/share/terraform/plugins
2023-06-20T14:46:42.641+0530 [DEBUG] ignoring non-existing provider search directory /usr/share/terraform/plugins
2023-06-20T14:46:42.641+0530 [INFO]  CLI command args: []string{"validate", "-no-color"}
2023-06-20T14:46:42.642+0530 [TRACE] providercache.fillMetaCache: scanning directory .terraform/providers
2023-06-20T14:46:42.642+0530 [TRACE] getproviders.SearchLocalDirectory: found registry.terraform.io/hashicorp/aws v4.67.0 for linux_amd64 at .terraform/providers/registry.terraform.io/hashicorp/aws/4.67.0/linux_amd64
2023-06-20T14:46:42.642+0530 [TRACE] providercache.fillMetaCache: including .terraform/providers/registry.terraform.io/hashicorp/aws/4.67.0/linux_amd64 as a candidate package for registry.terraform.io/hashicorp/aws 4.67.0
2023-06-20T14:46:43.339+0530 [DEBUG] checking for provisioner in "."
2023-06-20T14:46:43.344+0530 [DEBUG] checking for provisioner in "/usr/bin"
2023-06-20T14:46:43.344+0530 [TRACE] terraform.NewContext: starting
2023-06-20T14:46:43.344+0530 [TRACE] terraform.NewContext: complete
2023-06-20T14:46:43.344+0530 [DEBUG] Building and walking validate graph
2023-06-20T14:46:43.344+0530 [TRACE] building graph for walkValidate
2023-06-20T14:46:43.344+0530 [TRACE] Executing graph transform *terraform.ConfigTransformer
2023-06-20T14:46:43.344+0530 [TRACE] ConfigTransformer: Starting for path:
2023-06-20T14:46:43.344+0530 [TRACE] ConfigTransformer: Starting for path: module.vpclink
2023-06-20T14:46:43.344+0530 [TRACE] Completed graph transform *terraform.ConfigTransformer with new graph:
  module.vpclink.aws_api_gateway_vpc_link.vpclink - *terraform.NodeValidatableResource
  ------
2023-06-20T14:46:43.344+0530 [TRACE] Executing graph transform *terraform.RootVariableTransformer
2023-06-20T14:46:43.344+0530 [TRACE] Completed graph transform *terraform.RootVariableTransformer with new graph:
  module.vpclink.aws_api_gateway_vpc_link.vpclink - *terraform.NodeValidatableResource
  var.target_arn - *terraform.NodeRootVariable
  var.vpclink_name - *terraform.NodeRootVariable
  ------
2023-06-20T14:46:43.344+0530 [TRACE] Executing graph transform *terraform.ModuleVariableTransformer
2023-06-20T14:46:43.344+0530 [TRACE] Completed graph transform *terraform.ModuleVariableTransformer (no changes)

Error: Unsupported argument

  on main.tf line 4, in module "vpclink":
   4:   name        = var.vpclink_name

An argument named "name" is not expected here.

Panic Output

No response

Important Factoids

There are no errors when creating the resource "aws_api_gateway_vpc_link" without using a module. The documentaion includes name = "example" in the example usage.

References

Adding the respective documentation

No other source found in internet regarding the "name" behavior issue.

Would you like to implement a fix?

None

github-actions[bot] commented 1 year ago

Community Note

Voting for Prioritization

Volunteering to Work on This Issue

justinretzolk commented 1 year ago

Hey @vyshnavlal 👋 Thank you for taking the time to raise this! In your vpc_link module, the name argument of the aws_api_gateway_vpc_link resource is set to var.vpclink_name. This (paired with the variable definition found in the modules/vpc_link/variables.tf file) means that this module expects an argument of vpclink_name, rather than name in order to set the name of the VPC link resource.

In order to correctly call the vpc_link module, you'll need to pass the arguments that it's expecting; vpclink_name and target_arn.

Note I'm intentionally ignoring that the variables have default values. Since those values are required in order to create a functional configuration, I'd personally remove the default values, but that's a different topic entirely.

The updated configuration in main.tf would look like this:

module "vpclink" {
  source = "./modules/vpc_link"

  vpclink_name  = var.vpclink_name
  target_arn    = var.target_arn
}
justinretzolk commented 7 months ago

Since we haven't heard back, I'm going to close this issue. If you're still having trouble, please feel free to open a new issue, referencing this one for context as needed.

github-actions[bot] commented 6 months ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.