Skip to content

S3 Bucket Provisioning and Orchestration in GCP via Terraform

License

Notifications You must be signed in to change notification settings

thebuttonclan/cas-shelf

 
 

Repository files navigation

Google Cloud Storage - Terraform

Terraform script to create GCS buckets in Montreal region based on namespace and application variables passed in. It creates 4 buckets, dev, test, prod, tools for each application.

Steps

  1. Download Terraform based on your operating system and architecture.

  2. Select an existing project or create a new one to have the project ID.

  3. Create a service account private key and download it as JSON format.

    • Go to IAM & Admin
    • GO to Service accounts
    • Create a Service account or select an exisiting one
    • Create a private key to download (credentials.json)
  4. Set basic Terraform environment variables

export TF_VAR_credentials=service_account_key_filepath # required, eg) credentials.json
export TF_VAR_project_name=project-name # required
export TF_VAR_backend_bucket=backend-bucket-name # required
export TF_VAR_envs='["dev", "test", "prod", "tools"]' # optional, default to ["dev", "test", "prod", "tools"]
  • Once application environment list is overridden via TF_VAR_envs, it will affect all other namespace sets.
  1. Create an initial GCS bucket to store Terraform state files.
cd remote-state
terraform init
terraform apply -auto-approve
cd ..
  1. Initialize a working directory and build or change infrastructure based on the configuration file main.tf.

    • Note that init command includes the backend configuration using required environment variables.
terraform init -backend-config="bucket=$TF_VAR_backend_bucket" -backend-config="credentials=$TF_VAR_credentials"
terraform apply -var="namespace=button" -var="application=cas" -auto-approve

About

S3 Bucket Provisioning and Orchestration in GCP via Terraform

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Shell 85.9%
  • JavaScript 5.9%
  • HCL 5.5%
  • Go 1.6%
  • Makefile 1.1%