Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

deploy/gcp: Retrieve real number of node locations of the cluster #801

Merged
merged 2 commits into from
Aug 21, 2019
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion deploy/modules/gcp/tidb-cluster/data.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,4 +18,13 @@ data "external" "monitor_port" {
program = ["bash", "-c", "kubectl --kubeconfig ${var.kubeconfig_path} get svc -n ${var.cluster_name} ${var.cluster_name}-grafana -o json | jq '.spec.ports | .[] | select( .name == \"grafana\") | {port: .port|tostring}'"]
}

data "google_compute_zones" "available" {}
locals {
# TODO Update related code when node locations is avaiable in attributes of cluster resource.
cmd_get_cluster_locations = <<EOT
gcloud --project ${var.gcp_project} container clusters list --filter='name=${var.gke_cluster_name}' --format='json[no-heading](locations)' --region ${var.gke_cluster_location} | jq '.[0] | .locations |= join(",")'
EOT
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Example output:

{
  "locations": "us-central1-b,us-central1-c,us-central1-f"
}

}

data "external" "cluster_locations" {
program = ["bash", "-c", local.cmd_get_cluster_locations]
}
4 changes: 2 additions & 2 deletions deploy/modules/gcp/tidb-cluster/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -125,7 +125,7 @@ resource "google_container_node_pool" "monitor_pool" {
}

locals {
num_availability_zones = length(data.google_compute_zones.available.names)
num_availability_zones = length(split(",", data.external.cluster_locations.result["locations"]))
}

module "tidb-cluster" {
Expand All @@ -143,7 +143,7 @@ module "tidb-cluster" {

resource "null_resource" "wait-lb-ip" {
depends_on = [
google_container_node_pool.tidb_pool,
module.tidb-cluster
]
provisioner "local-exec" {
interpreter = ["bash", "-c"]
Expand Down