I have the next config.
main.tf
./modules/vpc
vpc.tf
./modules/compute_engine
ce.tf
on main I have
module "vpc" {
source = "./modules/vpc"
}
module "compute_engine_controller" {
source = "./modules/compute_engine"
vpc_name = module.vpc.vpc_network_name
}
on vpc I have
output "vpc_network_name" {
value = google_compute_network.vpc_network.name
}
on ce I have
resource "google_compute_instance" "controller" {
...
network_interface {
network = var.vpc_name
}
...
}
I get an error
│ Error: Unsupported argument
│
│ on main.tf line 34, in module "compute_engine_controller":
│ 34: vpc_name = module.vpc.vpc_network_name
│
│ An argument named "vpc_name" is not expected here.
why?
>Solution :
Since the module is complaining about not expecting an argument called vpc_name
, that means that the corresponding variable has not been defined in the variables.tf
of the module. To fix this, what needs to be added is:
variable "vpc_name" {
type = string
description = "The name of the VPC to be used."
}