This is sample of how to deploy a simple web server that is serving behind a load balancer using Terraform to staging or production environment in GCP.
- Install Google Cloud CLI
gcloud
on your computer by following this documentation (https://cloud.google.com/sdk/docs/install) - Run the following command to authenticate terraform
gcloud auth application-default login
-
Install terraform (https://developer.hashicorp.com/terraform/downloads)
-
Change
project_id
value insideenvironments/staging/staging.tfvars
andenvironments/production/production.tfvars
with your project ID. -
Initialize terraform
terraform init
- Create terraform workspace for
staging
andproduction
terraform workspace new staging
terraform workspace new production
- Deploy to
staging
terraform workspace select staging
terraform plan -var-file=environments/staging/staging.tfvars
terraform apply -var-file=environments/staging/staging.tfvars
- Deploy to
production
terraform workspace select production
terraform plan -var-file=environments/production/production.tfvars
terraform apply -var-file=environments/production/production.tfvars