Hi all,
I begin with terraform and gcp and I try to create some compute instance in GCP using terraform.
But I have error when I do terraform plan.
Could you help me please?
The error is :
Error reading config for google_compute_instance[www-1]: google_compute_subnetwork.net-webapp: resource variables must be three parts: TYPE.NAME.ATTR in:
${google_compute_subnetwork.net-webapp}
here is my code:
front-www.tf
resource "google_compute_instance" "www-1" {
name = "simm-${var.web-hostname[0]}"
zone = "${var.area[0]}"
machine_type = "${var.compute_web}"
boot_disk {
initialize_params {
image = "debian-9-stretch-v20190916"
}
}
can_ip_forward = false
network {
subnetwork = "${google_compute_subnetwork.net-webapp}"
network_interface {
network = "default"
}
}
}
resource "google_compute_instance" "www-2" {
name = "simm-${var.web-hostname[1]}"
zone ="${var.area[1]}"
machine_type = "${var.compute_web}"
boot_disk {
initialize_params {
image = "debian-9-stretch-v20190916"
}
}
can_ip_forward = false
network {
subnetwork = "${google_compute_subnetwork.net-webapp}"
network_interface {
network = "default"
}
}
networks.tf
resource "google_compute_network" "vpc" {
name = "global-vpc"
auto_create_subnetworks = "false"
}
resource "google_compute_subnetwork" "net-bastion" {
name = "vlan-front"
ip_cidr_range = "10.33.80.0/24"
network = "${google_compute_network.vpc.self_link}"
}
resource "google_compute_subnetwork" "net-webapp" {
name = "vlan-db"
ip_cidr_range = "10.33.81.0/24"
network = "${google_compute_network.vpc.self_link}"
region = "${var.region}"
}
firewalls.tf
resource "google_compute_firewall" "SshIn" {
name = "http_ingress"
network = "${google_compute_subnetwork.net-bastion.name}"
target_tags = ["bastion"]
source_ranges = ["0.0.0.0/0"]
allow {
protocol = "tcp"
ports = ["22"]
}
}
resource "google_compute_firewall" "HttpIn" {
name = "ssh-db"
network = "${google_compute_subnetwork.net-webapp.name}"
target_tags = ["webapp"]
source_ranges = ["0.0.0.0/0"]
allow {
protocol = "tcp"
ports = ["80"]
}
allow {
protocol = "tcp"
ports = ["443"]
}
}
vars.tf
variable "project" {default= "eco2019"}
variable "compute_web" { default = "n1-standard-1"}
variable "web-hostname" { default = ["www-1", "wwww-2"] }
variable "region" { default = "europe-west1"}
variable "area" { default = ["europe-west-a","europe-west-b","europe-west-c"]} `
Thank you