Skip to content

Commit

Permalink
fix Invalid index error when creating a private cluster
Browse files Browse the repository at this point in the history
As google_container_cluster.primary.private_cluster_config may be empty,
we check its length before trying to access it.

When creating a new private cluster, a "Invalid index" error was showing
up during the planning.

By checking for variable length before trying to access it the plan (and
apply) works as expected.

Issue: [terraform-google-modules#419]

Co-authored-by: Morgante Pell <morgantep@google.com>
  • Loading branch information
endorama and morgante committed Feb 6, 2020
1 parent a20425f commit 5e940fb
Showing 1 changed file with 1 addition and 1 deletion.
2 changes: 1 addition & 1 deletion autogen/main/main.tf.tmpl
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ locals {
cluster_output_zones = local.cluster_output_regional_zones

{% if private_cluster %}
cluster_endpoint = var.enable_private_nodes ? (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.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
{% else %}
cluster_endpoint = google_container_cluster.primary.endpoint
{% endif %}
Expand Down

0 comments on commit 5e940fb

Please sign in to comment.