I am trying to deploy one firewall rule in multiple projects I declare in variable file. I have created terraform module for this. Below is my parent module's main.tf file.
module "google_iap_access_fw_rule" {
source = "../../modules/networking/firewall"
for_each = var.vpc-subnets
project = each.value.project_id
network = each.value.vpc_name
name = "${each.value.vpc_name}-allow-iap"
protocol = "tcp"
ports = [22, 3389]
source_ranges = ["35.235.240.0/20"] # Google IAP access range, do not modify
source_tags = []
target_tags = [] # Rule applies to all instances in the network
}
Below is my terraform.tfvars file,
vpc-subnets = {
vpc-subnet-01 = {
project_id = "PROJECT_ID_1"
vpc_name = "vpc-01"
},
vpc-subnet-02 = {
project_id = "PROJECT_ID_2"
vpc_name = "vpc-02"
}
}
Below is my child module looks like,
resource "google_compute_firewall" "new-firewall" {
project = var.project
name = var.name
network = var.network
disabled = var.disabled
allow {
protocol = var.protocol
ports = var.ports
}
target_tags = var.target_tags
source_ranges = var.source_ranges
source_tags = var.source_tags
}
when I try to run this code, I get below error
│ Error: Unsupported argument
│
│ on main.tf line 26, in module "google_iap_access_fw_rule":
│ 4: project = each.value.project_id
│
│ An argument named "project" is not expected here.
╵
what am I doing wrong here ?