I’m attempting to deploy a GKE cluster to Google cloud. Our network is governed via a shared VPC. The cluster i’m attempting to deploy is in a separate VPC. I’m receiving the error message above. I am using a self created module as a template.
resource "google_container_cluster" "main_cluster_template" {
name = var.cluster_name
description = var.cluster_description
location = "europe-west2"
remove_default_node_pool = true
initial_node_count = 1
project = var.project_name
#ID of project
network = var.network
subnetwork = var.subnetwork_self_link
release_channel {
channel = var.release_channel
# Set to the regular channel by Default.
}
ip_allocation_policy {
cluster_secondary_range_name = var.pod_range_name
services_secondary_range_name = var.service_range_name
}
private_cluster_config {
enable_private_nodes = true
enable_private_endpoint = false
master_ipv4_cidr_block = var.master_ip_range
master_global_access_config {
enabled = true
}
}
}
resource "google_container_node_pool" "main_cluster_node_pool" {
name = var.node_pool_name
cluster = google_container_cluster.main_cluster_template.name
location = "europe-west2"
node_count = var.node_count
node_config {
machine_type = var.machine_type
labels = {
created-by = "terraform"
}
}
autoscaling {
max_node_count = 4
min_node_count = 1
}
upgrade_settings {
max_surge = 1
max_unavailable = 0
}
}
The above is the code for the module.
module "test_gke_cluster" {
project_name = "test-project-1"
source = "../../../../modules/GKE/"
cluster_name = "test-cluster"
machine_type = "e2-medium"
master_ip_range = "172.16.0.0/28"
node_count = "1"
node_pool_name = "test-pool"
pod_range_name = "pod-range"
service_range_name = "service-range"
subnetwork_self_link = "projects/shared-vpc-network/global/subnetworks/test-terraform-subnet"
network = "projects/shared-vpc-network/global/networks/shared-vpc"
}
This is the cluster which is using the module as a base.
The error messaged received is:
Error: googleapi: Error 400: Project in network field shared-vpc-network" does not match project in subnetwork field "test-project-1"., badRequest