diff --git a/main.tf b/main.tf index e3db381..f3e9594 100644 --- a/main.tf +++ b/main.tf @@ -80,3 +80,13 @@ resource "null_resource" "kubeconfig" { } } } + +data "external" "external_ips" { + program = ["bash", "-c", "gcloud compute instances list --filter=\"name~${var.name}\" --format=\"json(networkInterfaces[0].accessConfigs[0].natIP)\" | jq 'to_entries | map({key: (.key|tostring), value: (.value|tostring)}) | from_entries'"] +} + +locals { + external_ips = [ + for value in data.external.external_ips.result : jsondecode(value).networkInterfaces[0].accessConfigs[0].natIP + ] +} \ No newline at end of file diff --git a/outputs.tf b/outputs.tf index b613591..f29b186 100644 --- a/outputs.tf +++ b/outputs.tf @@ -12,6 +12,11 @@ // See the License for the specific language governing permissions and // limitations under the License. +output "external_ips" { + value = local.external_ips + description = "External IPs of the nodes" +} + output "id" { value = module.main.cluster_id } @@ -21,5 +26,5 @@ output "path_to_kubeconfig_file" { } output "zones" { - value = "module.main.zones" + value = module.main.zones }