Skip to content

Commit

Permalink
fix: use private endpoint
Browse files Browse the repository at this point in the history
  • Loading branch information
apeabody committed Nov 18, 2024
1 parent 5e67ff4 commit 58fd1bb
Show file tree
Hide file tree
Showing 26 changed files with 94 additions and 47 deletions.
9 changes: 9 additions & 0 deletions autogen/main/cluster.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -632,6 +632,15 @@ resource "google_container_cluster" "primary" {
}
}
}

dynamic "control_plane_endpoints_config" {
for_each = var.enable_private_endpoint && var.deploy_using_private_endpoint ? [1] : [0]
content {
dns_endpoint_config {
allow_external_traffic = var.deploy_using_private_endpoint
}
}
}
{% endif %}

{% if autopilot_cluster != true %}
Expand Down
2 changes: 1 addition & 1 deletion autogen/main/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ locals {
cluster_output_zones = local.cluster_output_regional_zones

{% if private_cluster %}
cluster_endpoint = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? (var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config[0].private_endpoint : google_container_cluster.primary.private_cluster_config[0].public_endpoint) : google_container_cluster.primary.endpoint
cluster_endpoint = var.deploy_using_private_endpoint || var.enable_private_endpoint ? google_container_cluster.primary.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint : google_container_cluster.primary.endpoint
cluster_peering_name = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? google_container_cluster.primary.private_cluster_config[0].peering_name : null
cluster_endpoint_for_nodes = var.master_ipv4_cidr_block
{% else %}
Expand Down
14 changes: 7 additions & 7 deletions autogen/main/versions.tf.tmpl
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -24,33 +24,33 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
{% elif beta_cluster and autopilot_cluster %}
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.5.0, < 6.11.0"
version = ">= 6.5.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.5.0, < 6.11.0"
version = ">= 6.5.0, < 7"
}
{% elif autopilot_cluster %}
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.5.0, < 6.11.0"
version = ">= 6.5.0, < 7"
}
{% else %}
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.7.0, < 7"
}
{% endif %}
kubernetes = {
Expand Down
2 changes: 2 additions & 0 deletions examples/safer_cluster_iap_bastion/bastion.tf
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ module "bastion" {
startup_script = templatefile("${path.module}/templates/startup-script.tftpl", {})
members = var.bastion_members
shielded_vm = "false"

service_account_roles = ["roles/container.viewer"]
}
6 changes: 0 additions & 6 deletions examples/simple_regional_beta/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,12 +20,6 @@ locals {

data "google_client_config" "default" {}

provider "kubernetes" {
host = "https://${module.gke.endpoint}"
token = data.google_client_config.default.access_token
cluster_ca_certificate = base64decode(module.gke.ca_certificate)
}

module "gke" {
source = "terraform-google-modules/kubernetes-engine/google//modules/beta-public-cluster"
version = "~> 34.0"
Expand Down
3 changes: 0 additions & 3 deletions examples/simple_regional_beta/versions.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,5 @@ terraform {
google-beta = {
source = "hashicorp/google-beta"
}
kubernetes = {
source = "hashicorp/kubernetes"
}
}
}
9 changes: 9 additions & 0 deletions modules/beta-autopilot-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -326,6 +326,15 @@ resource "google_container_cluster" "primary" {
}
}

dynamic "control_plane_endpoints_config" {
for_each = var.enable_private_endpoint && var.deploy_using_private_endpoint ? [1] : [0]
content {
dns_endpoint_config {
allow_external_traffic = var.deploy_using_private_endpoint
}
}
}


dynamic "database_encryption" {
for_each = var.database_encryption
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-autopilot-private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ locals {
cluster_output_regional_zones = google_container_cluster.primary.node_locations
cluster_output_zones = local.cluster_output_regional_zones

cluster_endpoint = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? (var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config[0].private_endpoint : google_container_cluster.primary.private_cluster_config[0].public_endpoint) : google_container_cluster.primary.endpoint
cluster_endpoint = var.deploy_using_private_endpoint || var.enable_private_endpoint ? google_container_cluster.primary.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint : google_container_cluster.primary.endpoint
cluster_peering_name = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? google_container_cluster.primary.private_cluster_config[0].peering_name : null
cluster_endpoint_for_nodes = var.master_ipv4_cidr_block

Expand Down
6 changes: 3 additions & 3 deletions modules/beta-autopilot-private-cluster/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,11 +21,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.5.0, < 6.11.0"
version = ">= 6.5.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.5.0, < 6.11.0"
version = ">= 6.5.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
6 changes: 3 additions & 3 deletions modules/beta-autopilot-public-cluster/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,11 +21,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.5.0, < 6.11.0"
version = ">= 6.5.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.5.0, < 6.11.0"
version = ">= 6.5.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
9 changes: 9 additions & 0 deletions modules/beta-private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,15 @@ resource "google_container_cluster" "primary" {
}
}

dynamic "control_plane_endpoints_config" {
for_each = var.enable_private_endpoint && var.deploy_using_private_endpoint ? [1] : [0]
content {
dns_endpoint_config {
allow_external_traffic = var.deploy_using_private_endpoint
}
}
}

remove_default_node_pool = var.remove_default_node_pool

dynamic "database_encryption" {
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-private-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ locals {
cluster_output_regional_zones = google_container_cluster.primary.node_locations
cluster_output_zones = local.cluster_output_regional_zones

cluster_endpoint = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? (var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config[0].private_endpoint : google_container_cluster.primary.private_cluster_config[0].public_endpoint) : google_container_cluster.primary.endpoint
cluster_endpoint = var.deploy_using_private_endpoint || var.enable_private_endpoint ? google_container_cluster.primary.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint : google_container_cluster.primary.endpoint
cluster_peering_name = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? google_container_cluster.primary.private_cluster_config[0].peering_name : null
cluster_endpoint_for_nodes = var.master_ipv4_cidr_block

Expand Down
6 changes: 3 additions & 3 deletions modules/beta-private-cluster-update-variant/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,11 +21,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
9 changes: 9 additions & 0 deletions modules/beta-private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -546,6 +546,15 @@ resource "google_container_cluster" "primary" {
}
}

dynamic "control_plane_endpoints_config" {
for_each = var.enable_private_endpoint && var.deploy_using_private_endpoint ? [1] : [0]
content {
dns_endpoint_config {
allow_external_traffic = var.deploy_using_private_endpoint
}
}
}

remove_default_node_pool = var.remove_default_node_pool

dynamic "database_encryption" {
Expand Down
2 changes: 1 addition & 1 deletion modules/beta-private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,7 @@ locals {
cluster_output_regional_zones = google_container_cluster.primary.node_locations
cluster_output_zones = local.cluster_output_regional_zones

cluster_endpoint = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? (var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config[0].private_endpoint : google_container_cluster.primary.private_cluster_config[0].public_endpoint) : google_container_cluster.primary.endpoint
cluster_endpoint = var.deploy_using_private_endpoint || var.enable_private_endpoint ? google_container_cluster.primary.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint : google_container_cluster.primary.endpoint
cluster_peering_name = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? google_container_cluster.primary.private_cluster_config[0].peering_name : null
cluster_endpoint_for_nodes = var.master_ipv4_cidr_block

Expand Down
6 changes: 3 additions & 3 deletions modules/beta-private-cluster/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,11 +21,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
6 changes: 3 additions & 3 deletions modules/beta-public-cluster-update-variant/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,11 +21,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
6 changes: 3 additions & 3 deletions modules/beta-public-cluster/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,11 +21,11 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
google-beta = {
source = "hashicorp/google-beta"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.11.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
9 changes: 9 additions & 0 deletions modules/private-cluster-update-variant/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ resource "google_container_cluster" "primary" {
}
}

dynamic "control_plane_endpoints_config" {
for_each = var.enable_private_endpoint && var.deploy_using_private_endpoint ? [1] : [0]
content {
dns_endpoint_config {
allow_external_traffic = var.deploy_using_private_endpoint
}
}
}

remove_default_node_pool = var.remove_default_node_pool

dynamic "database_encryption" {
Expand Down
2 changes: 1 addition & 1 deletion modules/private-cluster-update-variant/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ locals {
cluster_output_regional_zones = google_container_cluster.primary.node_locations
cluster_output_zones = local.cluster_output_regional_zones

cluster_endpoint = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? (var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config[0].private_endpoint : google_container_cluster.primary.private_cluster_config[0].public_endpoint) : google_container_cluster.primary.endpoint
cluster_endpoint = var.deploy_using_private_endpoint || var.enable_private_endpoint ? google_container_cluster.primary.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint : google_container_cluster.primary.endpoint
cluster_peering_name = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? google_container_cluster.primary.private_cluster_config[0].peering_name : null
cluster_endpoint_for_nodes = var.master_ipv4_cidr_block

Expand Down
4 changes: 2 additions & 2 deletions modules/private-cluster-update-variant/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.7.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
9 changes: 9 additions & 0 deletions modules/private-cluster/cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -499,6 +499,15 @@ resource "google_container_cluster" "primary" {
}
}

dynamic "control_plane_endpoints_config" {
for_each = var.enable_private_endpoint && var.deploy_using_private_endpoint ? [1] : [0]
content {
dns_endpoint_config {
allow_external_traffic = var.deploy_using_private_endpoint
}
}
}

remove_default_node_pool = var.remove_default_node_pool

dynamic "database_encryption" {
Expand Down
2 changes: 1 addition & 1 deletion modules/private-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -111,7 +111,7 @@ locals {
cluster_output_regional_zones = google_container_cluster.primary.node_locations
cluster_output_zones = local.cluster_output_regional_zones

cluster_endpoint = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? (var.deploy_using_private_endpoint ? google_container_cluster.primary.private_cluster_config[0].private_endpoint : google_container_cluster.primary.private_cluster_config[0].public_endpoint) : google_container_cluster.primary.endpoint
cluster_endpoint = var.deploy_using_private_endpoint || var.enable_private_endpoint ? google_container_cluster.primary.control_plane_endpoints_config[0].dns_endpoint_config[0].endpoint : google_container_cluster.primary.endpoint
cluster_peering_name = (var.enable_private_nodes && length(google_container_cluster.primary.private_cluster_config) > 0) ? google_container_cluster.primary.private_cluster_config[0].peering_name : null
cluster_endpoint_for_nodes = var.master_ipv4_cidr_block

Expand Down
4 changes: 2 additions & 2 deletions modules/private-cluster/versions.tf
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/**
* Copyright 2022 Google LLC
* Copyright 2022-2024 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand All @@ -21,7 +21,7 @@ terraform {
required_providers {
google = {
source = "hashicorp/google"
version = ">= 6.7.0, < 6.11.0"
version = ">= 6.7.0, < 7"
}
kubernetes = {
source = "hashicorp/kubernetes"
Expand Down
2 changes: 1 addition & 1 deletion test/fixtures/safer_cluster_iap_bastion/example.tf
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@
*/

locals {
test_command = "gcloud beta compute ssh ${module.example.bastion_name} --tunnel-through-iap --verbosity=error --project ${var.project_ids[1]} --zone ${module.example.bastion_zone} --ssh-flag=\"-T\" -q -- curl -sS https://${module.example.endpoint}/version -k"
test_command = "gcloud beta compute ssh ${module.example.bastion_name} --tunnel-through-iap --verbosity=error --project ${var.project_ids[1]} --zone ${module.example.bastion_zone} -q --command='curl -H \"Authorization: Bearer $(gcloud auth print-access-token)\" -H \"Content-Type: application/json\" -sS https://${module.example.endpoint}/version -k'"
}

module "example" {
Expand Down
Loading

0 comments on commit 58fd1bb

Please sign in to comment.