hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.32k stars 1.72k forks source link

Support use of Private Service Connect endpoint in GKE google_container_cluster resource #15064

Closed ncapps closed 1 year ago

ncapps commented 1 year ago

Community Note

Description

Creating a VPC network peering connection between the cluster VPC and the control plane VPC is not allowed in some enterprise uses cases. An alternative solution is connect the cluster VPC and control plane VPC using a Private Service Connect (PSC) endpoint.

The Terraform resource, google_container_cluster, should allow creating a private cluster without specifying the master_ipv4_cidr_block. This use case is supported with the gcloud container clusters create command.

gcloud container clusters create private-cluster \
    --enable-master-authorized-networks \
    --enable-ip-alias \
    --enable-private-nodes \
    --enable-private-endpoint \
    --network="shared-vpc" \
    --subnetwork="shared-vpc-subnet" \
    --private-endpoint-subnetwork="shared-vpc-subnet-nodes"

Using Terraraform, we currently cannot create a private cluster without providing a value for master_ipv4_cidr_block.

This configuration results in a Terraform build phase error.

private_cluster_config {
    enable_private_endpoint     = true
    enable_private_nodes        = true
    private_endpoint_subnetwork = "projects/project-id/regions/region/subnetworks/shared-vpc-subnet-nodes"
}

Error message:

module.kubernetes-engine.google_container_cluster.cluster: Creating...
╷
│ Error: master_ipv4_cidr_block must be set if enable_private_nodes is true

New or Affected Resource(s)

Potential Terraform Configuration

resource "google_container_cluster" "cluster" {
...
    private_cluster_config {
        enable_private_endpoint     = true
        enable_private_nodes        = true
        private_endpoint_subnetwork = "projects/project-id/regions/region/subnetworks/shared-vpc-subnet-nodes"
    }
}

References

ncapps commented 1 year ago

I will work on a fix for this issue.

sanmaym commented 1 year ago

@ncapps @rileykarson Can I get some clarification on this PR ? Are you trying to create a GKE cluster with private nodes which operates with PSC instead of VPC Peering? Is that possible today? My understanding was that its only supported for public GKE clusters and GKE cluster with private nodes was not supported yet

ncapps commented 1 year ago

Hi @sanmaym, Yes - we are creating GKE clusters with private nodes that use PSC. We have been using this configuration for over a year now. We needed to provision and manage the clusters using gcloud until this change was applied to the Google Terraform provider.

github-actions[bot] commented 1 year ago

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues. If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.