hashicorp / terraform-provider-google

Terraform Provider for Google Cloud Platform
https://registry.terraform.io/providers/hashicorp/google/latest/docs
Mozilla Public License 2.0
2.34k stars 1.74k forks source link

Add ability to call Cloud Functions and receive results #6209

Open dinvlad opened 4 years ago

dinvlad commented 4 years ago

Community Note

Description

Cloud Functions API exposes projects.locations.functions.call method to synchronously invoke a function for testing purposes [1].

Having an ability to do that from inside a Terraform template would significantly raise extensibility of the provider, including an ability to:

This would also mirror similar functionality in other providers and systems, e.g. aws_lambda_invocation or AWS::CloudFormation::CustomResource.

New or Affected Resource(s)

Potential Terraform Configuration

data "google_cloudfunctions_function_call" "call" {
  project        = google_cloudfunctions_function.function.project
  region         = google_cloudfunctions_function.function.region
  cloud_function = google_cloudfunctions_function.function.name

  data = jsonencode({ hello = "world" })
}

locals {
  cloud_function_output = data.google_cloudfunctions_function_call.call.result
}

References

fishpen0 commented 1 year ago

See: https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/lambda_invocation for the AWS equivalent.

This is often used for fetching data or resources terraform cannot natively support:

data "aws_lambda_invocation" "data_terraform_cant_get" {
  function_name = "myfunction"
}

output "mydata" {
  value = data.aws_lambda_invocation.data_terraform_cant_get.result
}

resource "other_resource" "other" {
  resource_argument = data.aws_lambda_invocation.data_terraform_cant_get.result
}
SarahFrench commented 4 months ago

Note from triage: Moving out of backlog due to prior art in the AWS provider, but the documentation for this new data source should warn that the Cloud Function shouldn't have side effects. This data source heavily depends on what the CF does.