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

Update vm-instance instructions to handle the case that there are zero instances #1413

Merged
Changes from all commits
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
18 changes: 12 additions & 6 deletions modules/compute/vm-instance/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -29,12 +29,18 @@ output "internal_ip" {
value = google_compute_instance.compute_vm[*].network_interface[0].network_ip
}

locals {
no_instance_instructions = "No instances were created."
first_instance_name = try(google_compute_instance.compute_vm[0].name, "no-instance")
ssh_instructions = <<-EOT
Use the following commands to SSH into the first VM created:
gcloud compute ssh --zone ${var.zone} ${local.first_instance_name} --project ${var.project_id}
If not accessible from the public internet, use an SSH tunnel through IAP:
gcloud compute ssh --zone ${var.zone} ${local.first_instance_name} --project ${var.project_id} --tunnel-through-iap
EOT
}

output "instructions" {
description = "Instructions on how to SSH into the created VM. Commands may fail depending on VM configuration and IAM permissions."
value = <<-EOT
Use the following commands to SSH into the first VM created:
gcloud compute ssh --zone ${var.zone} ${google_compute_instance.compute_vm[0].name} --project ${var.project_id}
If not accessible from the public internet, use an SSH tunnel through IAP:
gcloud compute ssh --zone ${var.zone} ${google_compute_instance.compute_vm[0].name} --project ${var.project_id} --tunnel-through-iap
EOT
value = var.instance_count > 0 ? local.ssh_instructions : local.no_instance_instructions
}