GCP project is already created and linked to a billing account.
Note
You can skip this step if you use an existing bucket for Terraform state.
-
Set up variables.
PROJECT="cloud-run-template-naka" REGION="asia-northeast1" BUCKET="cloud-run-template-naka-terraform"
-
Login
gcloud auth login
-
Create a GCS bucket for Terraform state.
gsutil mb -p "$PROJECT" -l "$REGION" gs://"$BUCKET"
-
Create your new GitHub repository from this template.
gh repo create <your new repo name> --template=nakabonne/cloud-run-app-template
-
Write your own
terraform.tfvars
andterraform.tfbackend
file.cp terraform.tfvars.example terraform.tfvars
Example of
terraform.tfvars
:project = "cloud-run-template-naka" region = "asia-northeast1" service_name = "cloud-run-template"
cp terraform.tfbackend.example terraform.tfbackend
Example of
backend.tfbackend
:bucket = "cloud-run-template-naka-terraform" prefix = "terraform/state"
-
Log in to GCP.
gcloud auth application-default login
-
Init
terraform init -backend-config=terraform.tfbackend
-
Apply
terraform apply
[!WARNING] It might fail for the first time, because it takes some time to enable the Cloud Run service API. Please try again.
-
Set GitHub repository secrets
gh secret set PROVIDER_NAME --body=$(terraform output github_actions_provider_name | tr -d '"') gh secret set SA_EMAIL --body=$(terraform output github_actions_sa_email | tr -d '"')
-
Create a PR!
GitHub Actions will be run with the service account created by Terraform.
If you want to configure more, please refer to the following repositories.
Warning
This will delete all resources created by Terraform.
terraform destroy