Run Spoke on GCP with Terraform.
This is very much a work in progress. Currently, it deploys a very simple Spoke service on Cloud Run backed by a Cloud SQL Postgres instance using local auth.
Note that, much like the Terraform configuration itself, these instructions are very much a work in progress.
- Download and install the Google Cloud SDK.
- Download and install Terraform.
- Create (or choose an existing) GCP project where you plan to deploy Spoke:
$ PROJECT_ID=<your GCP project ID>
- You will need to enable billing on the project. Spoke instances do not fall within free tier limits and will incur charges.
- Set your default project for
gcloud:$ gcloud config set project ${PROJECT_ID}
- Configure your GCP default application credentials:
$ gcloud auth application-default login
- Build and push a Spoke container image to Container Registry:
# From the root directory of your Spoke repository: Spoke$ IMAGE_NAME=spoke Spoke$ gcloud builds submit --tag gcr.io/${PROJECT_ID}/${IMAGE_NAME}
- Note that there are some code changes required in order for Spoke to run on Cloud Run. You can find experimental code with the necessary changes at https://github.com/navinsivakumar/Spoke/tree/gcp
- Run Terraform:
# From the root directory of your spoke-on-gcp repository: # us-central1, us-east1, or us-west1 should give the lowest charges spoke-on-gcp$ REGION=us-central1 spoke-on-gcp$ terraform init spoke-on-gcp$ CONTAINER_URL=gcr.io/${PROJECT_ID}/${IMAGE_NAME} # Optionally run `terraform plan` with the same flags as below to preview # changes. spoke-on-gcp$ terraform apply -var="project=${PROJECT_ID}" -var="region=${REGION}" -var="spoke_container=gcr.io/${PROJECT_ID}/${IMAGE_NAME}"
- The output from the
terraform applycommand will show the URL that you can visit to use your Spoke instance. You can also view the URL again by runningspoke-on-gcp$ terraform output spoke_url
You can delete your instance with terraform destroy:
# Optionally run `terraform plan -destroy` with the same flags to preview
# changes.
spoke-on-gcp$ terraform destroy -var="project=${PROJECT_ID}" -var="region=${REGION}" -var="spoke_container=gcr.io/${PROJECT_ID}/${IMAGE_NAME}"