A template for deploying Node.js applications on Google Cloud Run with Terraform and GitHub Actions.
- Terraform CLI v0.13+
- Google Cloud SDK
- Google Cloud account with billing set up
Follow the steps below to set up your project for the first time.
-
Create a new repository from the template. Clone it to your computer.
-
Create a Google Cloud project:
# Create project
gcloud projects create "PROJECT_ID" --name="PROJECT NAME"
# Set proejct as default
gcloud config set project "PROJECT_ID"
- Set up billing
# List billing accounts available
gcloud beta billing accounts list
# Link billing account
gcloud beta billing projects link "PROJECT_ID" --billing-account="BILLING_ACCOUNT_ID"
- Create a bucket to store the remote Terraform state and update
infra/backend.tf
:
# Create bucket
gsutil mb gs://tfstate-PROJECT_ID
# infra/backend.tf
terraform {
required_version = ">= 0.13"
+ backend "gcs" {
+ bucket = "tfstate-PROJECT_ID"
+ }
required_providers {
google = ">= 3.3"
}
}
- Apply the Terraform configuration for the first time:
cd infra
terraform init
terraform plan -var project=PROJECT_ID
terraform apply -var project=PROJECT_ID
Create two GitHub secrets for your repository:
PROJECT_ID
Your Google Cloud project ID.
SERVICE_ACCOUNT_KEY
Key for the deployment service account. It was created by Terraform on the previous step. Run terraform output deployment_sa_key
to display the value.
- Commit modified files
git add .
git commit -m "update terraform config"
git push
- Done π
GitHub actions is configured to deploy a new image when a release is created.
Go here to create a new release and trigger a deployment.
MIT 2021