Little playground app for doing some terraform stuff
We'll do a small practical dive into Terraform with Google Cloud Platform (GCP) since it has a very safe free tier.
- Download Terraform 0.12.29 https://www.terraform.io/downloads.html (If you are on a mac, I recommend using Brew: https://formulae.brew.sh/formula/terraform)
- Download the
gcloud
SDK: https://cloud.google.com/sdk/docs/quickstarts
- Make a new gmail account so you can safely make new stuff in isolation
- Visit https://cloud.google.com/
- Make a new project (e.g. "Terraform-playground")
- Visit GCS (Google Cloud Storage): https://console.cloud.google.com/storage/browser
- Enable billing (don't worry, GCP won't bill you after the 12 months expire)
- Make a bucket for storing your terraform state
Don't worry if you get stuck doing this, we'll go through it together anyway. This guide is also useful: https://www.terraform.io/docs/providers/google/guides/getting_started.html
If you're on mac or linux, copy/paste the helpers in tf_helpers.sh into your ~/.bash_profile
You can use the bash helper to correctly generate your /terraform
directory:
# tfgenerator [project-id] [tf-bucket]
tfgenerator tf-playground-285720 jamsupreme-tf-bucket
- See instructions at https://cloud.google.com/docs/authentication/production#create_service_account for making a service account
- Copy the
.json
file into the/terraform
directory and rename it tocredentials.json
so git ignores it
(TODO: Double check if this step is necessary)
- Run
gcloud auth application-default login
and you'll be able to login - Set the project:
gcloud config set project tf-playground-285720
(You must use the ID, not name)
(If you don't log into the application-default, terraform doesn't correctly initialize)
Run the following to initialize your Terraform:
cd terraform
# shorthand: tfinit dev
terraform init -backend-config=config/backend-dev.conf
Let's make another bucket, but this time do it with Terraform.
First, create a file in your /terraform
directory:
touch /terraform/sample_bucket.tf
And let's fill it in:
# /terraform/sample_bucket.tf
resource "google_storage_bucket" "sample-bucket" {
name = "jamsupreme-another-bucket-vcool"
force_destroy = true
}
Now let's run:
# shorthand: tfapply dev
terraform apply -var-file="config/dev.tfvars"