I am still new to terraform. I am trying to create a gke cluster in cluster-project with network in network-project. It is a shared vpc. I am using the data module to import that network information;but it doesn’t seems to be working. Everytime I run terraform apply; I get “Error: googleapi: Error 404: Not found: project “cluster-project” does not have a subnetwork named “terraform-test” in region “us-central1”., notFound”
cluster-project = project I am trying to build the cluster in network-project = project that host the vpc and subnets
Here is my full main.tf file
data "google_compute_network" "main-default-vpc" {
name = "default"
project = "network-project"
}
data "google_compute_subnetwork" "subnet-for-k8s" {
name = "terraform-test"
project = "network-project"
region = "us-central1"
self_link = "https://www.googleapis.com/compute/v1/projects/project-name/regions/us-central1/subnetworks/terraform-test"
}
resource "google_container_cluster" "primary" {
location = "us-central1"
project = cluster-project
name = var.cluster_name
node_locations = var.zones
network = data.google_compute_network.main-default-vpc.name
subnetwork = data.google_compute_subnetwork.subnet-for-k8s.name
initial_node_count = "1"
remove_default_node_pool = "true"
master_authorized_networks_config {
cidr_blocks {
cidr_block = "ip"
display_name = ""
}
cidr_blocks {
cidr_block = "ip"
display_name = ""
}
cidr_blocks {
cidr_block = "ip"
display_name = ""
}
cidr_blocks {
cidr_block = "ip"
display_name = ""
}
cidr_blocks {
cidr_block = "ip"
display_name = ""
}
cidr_blocks {
cidr_block = "ip"
display_name = ""
}
cidr_blocks {
cidr_block = "ip"
display_name = ""
}
cidr_blocks {
display_name = "cloud-nat-2 "
cidr_block = "ip"
}
cidr_blocks {
display_name = "cloud-nat-3 "
cidr_block = "ip"
}
cidr_blocks {
display_name = "cloud-nat-4"
cidr_block = "ip"
}
cidr_blocks {
display_name = "cloud-nat-5"
cidr_block = "ip"
}
}
ip_allocation_policy {
cluster_secondary_range_name = data.google_compute_subnetwork.subnet-for-k8s.secondary_ip_range.0.range_name
services_secondary_range_name = data.google_compute_subnetwork.subnet-for-k8s.secondary_ip_range.1.range_name
}
monitoring_config {
enable_components = ["APISERVER","CONTROLLER_MANAGER","SYSTEM_COMPONENTS"]
}
}
resource "google_container_node_pool" "primary_preemptible_nodes" {
name = "default"
cluster = google_container_cluster.primary.name
autoscaling {
max_node_count = var.minnode
min_node_count = var.maxnode
}
node_config {
machine_type = "n1-standard-2"
preemptible = false
disk_type = "pd-standard"
disk_size_gb = var.disksize
}
}