linkshrink-terraform
is a Terraform project for provisioning and deploying the LinkShrink Web App and its backend API on Google Cloud Platform (GCP). This project uses Terraform Cloud for remote state management and follows the principle of one project per environment in GCP.
- Terraform installed locally
- A GCP account with appropriate permissions
- Terraform Cloud account
- Run
terraform login
and follow the instructions to authenticate your Terraform CLI with Terraform Cloud.
- Create workspaces in Terraform Cloud for each environment, e.g.,
linkshrink-dev
,linkshrink-prod
.
- In each GCP project (e.g.,
linkshrink-dev
,linkshrink-prod
), create a service account namedgcp-tf-infra-operator
. - Assign the following roles to this account:
- Artifact Registry Administrator
- Cloud Memorystore Redis Admin
- Cloud Run Admin
- Cloud SQL Admin
- DNS Administrator
- Secret Manager Admin
- Serverless VPC Access Admin
- Serverless VPC Access Service Agent
- Service Account User
- Service Networking Service Agent
- Generate a private key (JSON format) for this service account.
For each workspace in Terraform Cloud, set the following variables:
environment
: The deployment environment (e.g.,prod
)gcp_tf_infra_operator_key
: The raw JSON key of the GCP service accountproject_id
: The GCP project ID (e.g.,linkshrink-prod
)region
: The GCP region for resource deployment (e.g.,us-east1
)service_version
: The version of the Docker imagelinkshrink-service
to deploy (e.g.,v1.0.0
)web_app_version
: The version of the Docker imagelinkshrink-web-app
to deploy (e.g.,v1.0.0
)subnet_cidr
: CIDR for the VPC Subnet (e.g.,10.0.0.0/24
)vpc_connector_cidr
: CIDR for the VPC Connector (e.g.,10.0.1.0/28
)
- Edit
providers.tf
to configure the remote backend with your Terraform Cloud organization name and workspace prefix.
- Run
terraform init
. Select a workspace if prompted. - Execute
terraform plan
andterraform apply
to deploy resources.
- To switch workspaces, use
terraform workspace select <workspace>
.
After completing the setup, you can manage your GCP resources for each environment by switching between Terraform Cloud workspaces and running Terraform commands as needed.
Contributions to linkshrink-terraform
are welcome. Please follow the standard Git workflow for submitting changes.