From 62f789c24981477c4b34d8aade2c8553557b076f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Wiktor=20Niesiob=C4=99dzki?= Date: Fri, 21 Feb 2025 16:34:51 +0000 Subject: [PATCH] Add execution/invocation commands to outputs --- modules/cloud-function-v1/README.md | 9 +++++---- modules/cloud-function-v1/outputs.tf | 9 +++++++++ modules/cloud-function-v2/README.md | 17 +++++++++-------- modules/cloud-function-v2/outputs.tf | 9 +++++++++ modules/cloud-run-v2/README.md | 17 +++++++++-------- modules/cloud-run-v2/outputs.tf | 14 ++++++++++++++ modules/cloud-run/README.md | 13 +++++++------ modules/cloud-run/outputs.tf | 9 +++++++++ modules/compute-vm/README.md | 13 +++++++------ modules/compute-vm/outputs.tf | 5 +++++ 10 files changed, 83 insertions(+), 32 deletions(-) diff --git a/modules/cloud-function-v1/README.md b/modules/cloud-function-v1/README.md index 952de25ad..6b427e654 100644 --- a/modules/cloud-function-v1/README.md +++ b/modules/cloud-function-v1/README.md @@ -410,10 +410,11 @@ module "cf-http" { | [function](outputs.tf#L29) | Cloud function resources. | | | [function_name](outputs.tf#L34) | Cloud function name. | | | [id](outputs.tf#L39) | Fully qualified function id. | | -| [service_account](outputs.tf#L44) | Service account resource. | | -| [service_account_email](outputs.tf#L49) | Service account email. | | -| [service_account_iam_email](outputs.tf#L54) | Service account email. | | -| [vpc_connector](outputs.tf#L62) | VPC connector resource if created. | | +| [invoke_command](outputs.tf#L44) | Command to invoke Cloud Function. | | +| [service_account](outputs.tf#L53) | Service account resource. | | +| [service_account_email](outputs.tf#L58) | Service account email. | | +| [service_account_iam_email](outputs.tf#L63) | Service account email. | | +| [vpc_connector](outputs.tf#L71) | VPC connector resource if created. | | ## Fixtures diff --git a/modules/cloud-function-v1/outputs.tf b/modules/cloud-function-v1/outputs.tf index 258d668eb..16fddf15e 100644 --- a/modules/cloud-function-v1/outputs.tf +++ b/modules/cloud-function-v1/outputs.tf @@ -41,6 +41,15 @@ output "id" { value = google_cloudfunctions_function.function.id } +output "invoke_command" { + description = "Command to invoke Cloud Function." + value = var.trigger_config != null ? null : <<-EOT + curl -H "Authorization: bearer $(gcloud auth print-identity-token)" \ + ${google_cloudfunctions_function.function.https_trigger_url} \ + -X POST -d 'data' + EOT +} + output "service_account" { description = "Service account resource." value = try(google_service_account.service_account[0], null) diff --git a/modules/cloud-function-v2/README.md b/modules/cloud-function-v2/README.md index 2e6c08ce5..366eac29d 100644 --- a/modules/cloud-function-v2/README.md +++ b/modules/cloud-function-v2/README.md @@ -343,14 +343,15 @@ module "cf-http" { | [function](outputs.tf#L29) | Cloud function resources. | | | [function_name](outputs.tf#L34) | Cloud function name. | | | [id](outputs.tf#L39) | Fully qualified function id. | | -| [service_account](outputs.tf#L44) | Service account resource. | | -| [service_account_email](outputs.tf#L49) | Service account email. | | -| [service_account_iam_email](outputs.tf#L54) | Service account email. | | -| [trigger_service_account](outputs.tf#L62) | Service account resource. | | -| [trigger_service_account_email](outputs.tf#L67) | Service account email. | | -| [trigger_service_account_iam_email](outputs.tf#L72) | Service account email. | | -| [uri](outputs.tf#L80) | Cloud function service uri. | | -| [vpc_connector](outputs.tf#L85) | VPC connector resource if created. | | +| [invoke_command](outputs.tf#L44) | Command to invoke Cloud Run Function. | | +| [service_account](outputs.tf#L53) | Service account resource. | | +| [service_account_email](outputs.tf#L58) | Service account email. | | +| [service_account_iam_email](outputs.tf#L63) | Service account email. | | +| [trigger_service_account](outputs.tf#L71) | Service account resource. | | +| [trigger_service_account_email](outputs.tf#L76) | Service account email. | | +| [trigger_service_account_iam_email](outputs.tf#L81) | Service account email. | | +| [uri](outputs.tf#L89) | Cloud function service uri. | | +| [vpc_connector](outputs.tf#L94) | VPC connector resource if created. | | ## Fixtures diff --git a/modules/cloud-function-v2/outputs.tf b/modules/cloud-function-v2/outputs.tf index 380402460..d2256d256 100644 --- a/modules/cloud-function-v2/outputs.tf +++ b/modules/cloud-function-v2/outputs.tf @@ -41,6 +41,15 @@ output "id" { value = google_cloudfunctions2_function.function.id } +output "invoke_command" { + description = "Command to invoke Cloud Run Function." + value = var.trigger_config != null ? null : <<-EOT + curl -H "Authorization: bearer $(gcloud auth print-identity-token)" \ + ${google_cloudfunctions2_function.function.service_config[0].uri} \ + -X POST -d 'data' + EOT +} + output "service_account" { description = "Service account resource." value = try(google_service_account.service_account[0], null) diff --git a/modules/cloud-run-v2/README.md b/modules/cloud-run-v2/README.md index e0e59fcca..0a651c41a 100644 --- a/modules/cloud-run-v2/README.md +++ b/modules/cloud-run-v2/README.md @@ -569,14 +569,15 @@ module "cloud_run" { | name | description | sensitive | |---|---|:---:| | [id](outputs.tf#L17) | Fully qualified job or service id. | | -| [job](outputs.tf#L22) | Cloud Run Job. | | -| [service](outputs.tf#L27) | Cloud Run Service. | | -| [service_account](outputs.tf#L32) | Service account resource. | | -| [service_account_email](outputs.tf#L37) | Service account email. | | -| [service_account_iam_email](outputs.tf#L42) | Service account email. | | -| [service_name](outputs.tf#L50) | Cloud Run service name. | | -| [service_uri](outputs.tf#L55) | Main URI in which the service is serving traffic. | | -| [vpc_connector](outputs.tf#L60) | VPC connector resource if created. | | +| [invoke_command](outputs.tf#L22) | Command to invoke Cloud Run Service / submit job. | | +| [job](outputs.tf#L36) | Cloud Run Job. | | +| [service](outputs.tf#L41) | Cloud Run Service. | | +| [service_account](outputs.tf#L46) | Service account resource. | | +| [service_account_email](outputs.tf#L51) | Service account email. | | +| [service_account_iam_email](outputs.tf#L56) | Service account email. | | +| [service_name](outputs.tf#L64) | Cloud Run service name. | | +| [service_uri](outputs.tf#L69) | Main URI in which the service is serving traffic. | | +| [vpc_connector](outputs.tf#L74) | VPC connector resource if created. | | ## Fixtures diff --git a/modules/cloud-run-v2/outputs.tf b/modules/cloud-run-v2/outputs.tf index 4be653f83..0abcebd09 100644 --- a/modules/cloud-run-v2/outputs.tf +++ b/modules/cloud-run-v2/outputs.tf @@ -19,6 +19,20 @@ output "id" { value = var.create_job ? google_cloud_run_v2_job.job[0].id : google_cloud_run_v2_service.service[0].id } +output "invoke_command" { + description = "Command to invoke Cloud Run Service / submit job." + value = ( + var.create_job ? <<-EOT + gcloud run jobs execute --project ${var.project_id} --region ${var.region} --wait ${google_cloud_run_v2_job.job[0].name} --args= + EOT + : <<-EOT + curl -H "Authorization: bearer $(gcloud auth print-identity-token)" \ + ${google_cloud_run_v2_service.service[0].uri} \ + -X POST -d 'data' + EOT + ) +} + output "job" { description = "Cloud Run Job." value = var.create_job ? google_cloud_run_v2_job.job[0] : null diff --git a/modules/cloud-run/README.md b/modules/cloud-run/README.md index 0e36d1a0d..9dbf641af 100644 --- a/modules/cloud-run/README.md +++ b/modules/cloud-run/README.md @@ -450,10 +450,11 @@ module "cloud_run" { | name | description | sensitive | |---|---|:---:| | [id](outputs.tf#L18) | Fully qualified service id. | | -| [service](outputs.tf#L23) | Cloud Run service. | | -| [service_account](outputs.tf#L28) | Service account resource. | | -| [service_account_email](outputs.tf#L33) | Service account email. | | -| [service_account_iam_email](outputs.tf#L38) | Service account email. | | -| [service_name](outputs.tf#L46) | Cloud Run service name. | | -| [vpc_connector](outputs.tf#L52) | VPC connector resource if created. | | +| [invoke_command](outputs.tf#L23) | Command to invoke Cloud Run Service / submit job. | | +| [service](outputs.tf#L32) | Cloud Run service. | | +| [service_account](outputs.tf#L37) | Service account resource. | | +| [service_account_email](outputs.tf#L42) | Service account email. | | +| [service_account_iam_email](outputs.tf#L47) | Service account email. | | +| [service_name](outputs.tf#L55) | Cloud Run service name. | | +| [vpc_connector](outputs.tf#L61) | VPC connector resource if created. | | diff --git a/modules/cloud-run/outputs.tf b/modules/cloud-run/outputs.tf index 5e05dab82..dcca33374 100644 --- a/modules/cloud-run/outputs.tf +++ b/modules/cloud-run/outputs.tf @@ -20,6 +20,15 @@ output "id" { value = google_cloud_run_service.service.id } +output "invoke_command" { + description = "Command to invoke Cloud Run Service / submit job." + value = <<-EOT + curl -H "Authorization: bearer $(gcloud auth print-identity-token)" \ + ${google_cloud_run_service.service.status[0].url} \ + -X POST -d 'data' + EOT +} + output "service" { description = "Cloud Run service." value = google_cloud_run_service.service diff --git a/modules/compute-vm/README.md b/modules/compute-vm/README.md index 50f3dabb0..c359d8623 100644 --- a/modules/compute-vm/README.md +++ b/modules/compute-vm/README.md @@ -953,12 +953,13 @@ module "sole-tenancy" { | [instance](outputs.tf#L36) | Instance resource. | ✓ | | [internal_ip](outputs.tf#L42) | Instance main interface internal IP address. | | | [internal_ips](outputs.tf#L50) | Instance interfaces internal IP addresses. | | -| [self_link](outputs.tf#L58) | Instance self links. | | -| [service_account](outputs.tf#L63) | Service account resource. | | -| [service_account_email](outputs.tf#L68) | Service account email. | | -| [service_account_iam_email](outputs.tf#L73) | Service account email. | | -| [template](outputs.tf#L82) | Template resource. | | -| [template_name](outputs.tf#L87) | Template name. | | +| [login_command](outputs.tf#L58) | Command to SSH into the machine. | | +| [self_link](outputs.tf#L63) | Instance self links. | | +| [service_account](outputs.tf#L68) | Service account resource. | | +| [service_account_email](outputs.tf#L73) | Service account email. | | +| [service_account_iam_email](outputs.tf#L78) | Service account email. | | +| [template](outputs.tf#L87) | Template resource. | | +| [template_name](outputs.tf#L92) | Template name. | | ## Fixtures diff --git a/modules/compute-vm/outputs.tf b/modules/compute-vm/outputs.tf index 8e6422377..dc5a80266 100644 --- a/modules/compute-vm/outputs.tf +++ b/modules/compute-vm/outputs.tf @@ -55,6 +55,11 @@ output "internal_ips" { ] } +output "login_command" { + description = "Command to SSH into the machine." + value = "gcloud compute ssh --project ${var.project_id} --zone ${var.zone} ${var.name}" +} + output "self_link" { description = "Instance self links." value = try(google_compute_instance.default[0].self_link, null)