Skip to content

Commit

Permalink
Make GKE module cluster_name computed attribute
Browse files Browse the repository at this point in the history
  • Loading branch information
Sam Naser committed Mar 28, 2022
1 parent 9f06ef4 commit 72908b6
Show file tree
Hide file tree
Showing 14 changed files with 112 additions and 12 deletions.
12 changes: 12 additions & 0 deletions autogen/main/outputs.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,18 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
{% if autopilot_cluster != true %}
google_container_node_pool.pools,
{% endif %}
]
}

output "type" {
Expand Down
6 changes: 3 additions & 3 deletions cluster.tf
Original file line number Diff line number Diff line change
Expand Up @@ -100,15 +100,15 @@ resource "google_container_cluster" "primary" {

addons_config {
http_load_balancing {
disabled = !var.http_load_balancing
disabled = ! var.http_load_balancing
}

horizontal_pod_autoscaling {
disabled = !var.horizontal_pod_autoscaling
disabled = ! var.horizontal_pod_autoscaling
}

network_policy_config {
disabled = !var.network_policy
disabled = ! var.network_policy
}

gcp_filestore_csi_driver_config {
Expand Down
6 changes: 3 additions & 3 deletions dns.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ module "gcloud_delete_default_kube_dns_configmap" {
source = "terraform-google-modules/gcloud/google//modules/kubectl-wrapper"
version = "~> 3.1"

enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && !var.skip_provisioners
enabled = (local.custom_kube_dns_config || local.upstream_nameservers_config) && ! var.skip_provisioners
cluster_name = google_container_cluster.primary.name
cluster_location = google_container_cluster.primary.location
project_id = var.project_id
Expand All @@ -43,7 +43,7 @@ module "gcloud_delete_default_kube_dns_configmap" {
Create kube-dns confimap
*****************************************/
resource "kubernetes_config_map" "kube-dns" {
count = local.custom_kube_dns_config && !local.upstream_nameservers_config ? 1 : 0
count = local.custom_kube_dns_config && ! local.upstream_nameservers_config ? 1 : 0

metadata {
name = "kube-dns"
Expand All @@ -68,7 +68,7 @@ EOF
}

resource "kubernetes_config_map" "kube-dns-upstream-namservers" {
count = !local.custom_kube_dns_config && local.upstream_nameservers_config ? 1 : 0
count = ! local.custom_kube_dns_config && local.upstream_nameservers_config ? 1 : 0

metadata {
name = "kube-dns"
Expand Down
2 changes: 1 addition & 1 deletion examples/simple_zonal_with_asm/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ data "google_project" "project" {
module "gke" {
source = "../../"
project_id = var.project_id
name = "${local.cluster_type}-cluster${var.cluster_name_suffix}"
name = "test-prefix-cluster-test-suffix"
regional = false
region = var.region
zones = var.zones
Expand Down
10 changes: 5 additions & 5 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -133,11 +133,11 @@ locals {
cluster_monitoring_service = local.cluster_output_monitoring_service
cluster_node_pools_names = local.cluster_output_node_pools_names
cluster_node_pools_versions = local.cluster_output_node_pools_versions
cluster_network_policy_enabled = !local.cluster_output_network_policy_enabled
cluster_http_load_balancing_enabled = !local.cluster_output_http_load_balancing_enabled
cluster_horizontal_pod_autoscaling_enabled = !local.cluster_output_horizontal_pod_autoscaling_enabled
workload_identity_enabled = !(var.identity_namespace == null || var.identity_namespace == "null")
cluster_workload_identity_config = !local.workload_identity_enabled ? [] : var.identity_namespace == "enabled" ? [{
cluster_network_policy_enabled = ! local.cluster_output_network_policy_enabled
cluster_http_load_balancing_enabled = ! local.cluster_output_http_load_balancing_enabled
cluster_horizontal_pod_autoscaling_enabled = ! local.cluster_output_horizontal_pod_autoscaling_enabled
workload_identity_enabled = ! (var.identity_namespace == null || var.identity_namespace == "null")
cluster_workload_identity_config = ! local.workload_identity_enabled ? [] : var.identity_namespace == "enabled" ? [{
workload_pool = "${var.project_id}.svc.id.goog" }] : [{ workload_pool = var.identity_namespace
}]

Expand Down
9 changes: 9 additions & 0 deletions modules/beta-autopilot-private-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
]
}

output "type" {
Expand Down
9 changes: 9 additions & 0 deletions modules/beta-autopilot-public-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,15 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
]
}

output "type" {
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-private-cluster-update-variant/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
google_container_node_pool.pools,
]
}

output "type" {
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-private-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
google_container_node_pool.pools,
]
}

output "type" {
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-public-cluster-update-variant/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
google_container_node_pool.pools,
]
}

output "type" {
Expand Down
10 changes: 10 additions & 0 deletions modules/beta-public-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
google_container_node_pool.pools,
]
}

output "type" {
Expand Down
10 changes: 10 additions & 0 deletions modules/private-cluster-update-variant/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
google_container_node_pool.pools,
]
}

output "type" {
Expand Down
10 changes: 10 additions & 0 deletions modules/private-cluster/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
google_container_node_pool.pools,
]
}

output "type" {
Expand Down
10 changes: 10 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,16 @@ output "cluster_id" {
output "name" {
description = "Cluster name"
value = local.cluster_name
depends_on = [
/* Nominally, the cluster name is populated as soon as it is known to Terraform.
* However, the cluster may not be in a usable state yet. Therefore any
* resources dependent on the cluster being up will fail to deploy. With
* this explicit dependency, dependent resources can wait for the cluster
* to be up.
*/
google_container_cluster.primary,
google_container_node_pool.pools,
]
}

output "type" {
Expand Down

0 comments on commit 72908b6

Please sign in to comment.