I’m trying to create a cluster which will use a shared_vpc but I’m not sure what needs to be done in order to get it working. I’ve configured the google_compute_shared_vpc_host_project and the google_compute_shared_vpc_service_project but I’m unsure what I need to do inside of google_container_cluster to be able to utilize the shared vpc network. According to the docs I need to “set this to the self link of the shared network.”. I’m not sure how I go about setting “network” to the self link of the shared network. There seems to be no self_link option on either google_compute_shared_vpc_host_project. or google_compute_shared_vpc_service_project.. I’m sure I’m missing something I just don’t know what. Any help is appreciated. Configs are below.
vpc.tf
variable "shared_vpc_host_project" {
type = string
default = "my-shared-vpc-1"
}
# A host project provides network resources to associated service projects.
resource "google_compute_shared_vpc_host_project" "vpc_host" {
project = var.shared_vpc_host_project
}
# A service project gains access to network resources provided by its associated host project.
resource "google_compute_shared_vpc_service_project" "vpc_service1" {
host_project = google_compute_shared_vpc_host_project.vpc_host.project
service_project = var.project
}
cluster.tf
resource "google_container_cluster" "vpc_native_cluster" {
name = var.cluster_name
location = var.region
remove_default_node_pool = true
initial_node_count = 1
network = google_compute_shared_vpc_service_project.vpc_service1
subnetwork = "us-central1-dev-2-gke-79-0"
ip_allocation_policy {
cluster_secondary_range_name = "dev-2-gke-pods"
services_secondary_range_name = "dev-2-gke-services"
}
private_cluster_config {
enable_private_nodes = true
enable_private_endpoint = true
master_ipv4_cidr_block = "x.x.x.x/28" #masked
}
}