Stay organized with collections Save and categorize content based on your preferences.
This tutorial demonstrates how to deploy an HTTP function by uploading a function source code zip file to a Cloud Storage bucket, using Terraform to provision the resources. Terraform is an open source tool that lets you provision Google Cloud resources with declarative configuration files.
This tutorial uses a Node.js HTTP function as an example, but it also works with Python, Go, and Java HTTP functions. The instructions are the same regardless of which of these runtimes you are using.
When you deploy with Terraform, you must upload your function's zipped source file to a Cloud Storage bucket (source_archive_bucket
), and also specify the Cloud Storage object name (source_archive_object
) in the Terraform configuration. For more information, see the Terraform specification guide.
Cloud Run functions copies the source file you upload in the source_archive_bucket
to a bucket in your project with a bucket name that follows the format gcf-v2-sources-PROJECT_NUMBER-REGION
(Cloud Run functions), or gcf-sources-PROJECT_NUMBER-REGION
Cloud Run functions (1st gen). This configuration varies depending on the CMEK dependency.
In this document, you use the following billable components of Google Cloud:
For details, see Cloud Run functions pricing.
To generate a cost estimate based on your projected usage, use the pricing calculator.
New Google Cloud users might be eligible for a
free trial.
Before you beginIn the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Functions, Cloud Run, Cloud Build, Artifact Registry, and Cloud Storage APIs.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud init
In the Google Cloud console, on the project selector page, select or create a Google Cloud project.
Note: If you don't plan to keep the resources that you create in this procedure, create a project instead of selecting an existing project. After you finish these steps, you can delete the project, removing all resources associated with the project.Verify that billing is enabled for your Google Cloud project.
Enable the Cloud Functions, Cloud Run, Cloud Build, Artifact Registry, and Cloud Storage APIs.
Install the Google Cloud CLI.
If you're using an external identity provider (IdP), you must first sign in to the gcloud CLI with your federated identity.
To initialize the gcloud CLI, run the following command:
gcloud init
If you already have the gcloud CLI installed, update it by running the following command:
gcloud components update
Users deploying functions must have the Cloud Functions Developer (roles/cloudfunctions.developer
) IAM role or a role that includes the same permissions. See also Additional configuration for deployment.
To get the permissions to access the Cloud Storage bucket, ask your administrator to grant the IAM identity that deploys the function the Storage Admin (roles/storage.admin
) role. For more details on Cloud Storage roles and permissions, see IAM for Cloud Storage.
In this tutorial, you run commands in Cloud Shell. Cloud Shell is a shell environment with the Google Cloud CLI already installed, including the Google Cloud CLI, and with values already set for your current project. Cloud Shell can take several minutes to initialize:
Preparing the applicationIn Cloud Shell, perform the following steps:
Clone the sample app repository to your Cloud Shell instance:
git clone https://github.com/terraform-google-modules/terraform-docs-samples.git
Change to the directory that contains the Cloud Run functions sample code examples:
cd terraform-docs-samples/functions/basic
The Node.JS sample used in this tutorial is a basic "Hello World" HTTP function. Here is the main.tf
file:
In the terraform-docs-samples/functions/basic
directory containing the main.tf
file, run this command to add the necessary plugins and build the .terraform
directory:
terraform init
Apply the Terraform configuration
In the same terraform-docs-samples/functions/basic
directory containing the main.tf
file, deploy the function by applying the configuration. When prompted, enter yes
:
terraform apply
Test the function
When the function finishes deploying, take note of the URI property or find it using the following command:
gcloud functions describe function-v2 --gen2 --region=us-central1 --format="value(serviceConfig.uri)"
Make a request to this URL to see your function's "Hello World" message. Note that the function is deployed requiring authentication. Therefore you must provide credentials in your request:
curl -H "Authorization: Bearer $(gcloud auth print-identity-token)" YOUR_FUNCTION_URL
After completing the tutorial, you can delete everything that you created so that you don't incur any further costs.
Terraform lets you remove all the resources defined in the configuration file by running the terraform destroy
command in the terraform-docs-samples/functions/basic
directory containing your main.tf
file:
terraform destroy
Enter yes
to allow Terraform to delete your resources.
Except as otherwise noted, the content of this page is licensed under the Creative Commons Attribution 4.0 License, and code samples are licensed under the Apache 2.0 License. For details, see the Google Developers Site Policies. Java is a registered trademark of Oracle and/or its affiliates.
Last updated 2025-08-07 UTC.
[[["Easy to understand","easyToUnderstand","thumb-up"],["Solved my problem","solvedMyProblem","thumb-up"],["Other","otherUp","thumb-up"]],[["Hard to understand","hardToUnderstand","thumb-down"],["Incorrect information or sample code","incorrectInformationOrSampleCode","thumb-down"],["Missing the information/samples I need","missingTheInformationSamplesINeed","thumb-down"],["Other","otherDown","thumb-down"]],["Last updated 2025-08-07 UTC."],[[["This tutorial guides you through deploying an HTTP Cloud Run function using Terraform, which involves uploading a function's source code zip file to a Cloud Storage bucket."],["The process demonstrates deploying a Node.js HTTP function, although the same method is applicable to Python, Go, and Java HTTP functions."],["The tutorial uses billable Google Cloud components, including Cloud Run functions, Cloud Build, Cloud Storage, and Artifact Registry, and it shows how to initialize, apply and destroy the deployment."],["A `main.tf` file is used to manage the Terraform configuration, which is customizable for different runtimes, function entry points, and source directories."],["The tutorial shows how to test the function by using a `curl` command that requires authentication by default, but has the possibility to enable unauthenticated access after deployment."]]],[]]
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4