I want to create a network using the google-terraform-network
module. Additionally, I want to pass the firewall rules I made as a parameter to the module so that the created network contains these two rules.
When I pass the firewall rules directly, i.e.:
firewall_rules = [google_compute_firewall.allow_ssh, google_compute_firewall.allow_http]
I receive the following error: The given value is not suitable for module.vpc.module.firewall_rules.var.rules declared at .terraform/modules/vpc/modules/firewall-rules/variables.tf:27,1-17: element 0: attribute "log_config": object required.
.
On the other hand, when I pass the self_link
, i.e.:
firewall_rules = [google_compute_firewall.allow_ssh.self_link, google_compute_firewall.allow_http.self_link]
I get numerous errors of the following form:
Error: Invalid function argument
│
│ on .terraform/modules/vpc/main.tf line 70, in locals:
│ 70: deny = lookup(f, "deny", [])
│
│ Invalid value for "inputMap" parameter: lookup() requires a map as the first argument.
Here's the complete main.tf
:
provider "google" {
project = var.project
region = var.region
zone = var.zone
}
// firewall rule to allow ssh
resource "google_compute_firewall" "allow_ssh" {
name = "allow-ssh"
network = var.network_name
allow {
protocol = "tcp"
ports = ["22"]
}
source_ranges = ["0.0.0.0/0"]
}
// firewall rule to allow http
resource "google_compute_firewall" "allow_http" {
name = "allow-http"
network = var.network_name
allow {
protocol = "tcp"
ports = ["80"]
}
source_ranges = [""]
}
module "vpc" {
source = "terraform-google-modules/network/google"
version = "~> 7.0"
project_id = var.project
network_name = var.network_name
routing_mode = "GLOBAL"
subnets = [
{
subnet_name = var.subnet_name
subnet_ip = var.subnet_ip
subnet_region = var.region
},
]
firewall_rules = [google_compute_firewall.allow_ssh.self_link, google_compute_firewall.allow_http.self_link]
}