Bitzu

Associate Cloud Engineer ยท Infrastructure as code and AI-assisted tooling

Terraform on Google Cloud: the workflow and state

Providers, resources, state (remote state in Cloud Storage), init/plan/apply/destroy, drift, authentication from a pipeline.

Key points

  • You declare resources in configuration files; the google provider talks to the Google Cloud APIs.
  • Loop: init (download providers, set up backend), plan (preview), apply (make changes), destroy (remove everything).
  • State records what Terraform manages.
  • Teams: remote state in a Cloud Storage bucket with Object Versioning and tight write access.
  • Manual console changes cause drift: the next plan shows the difference.

Source: https://docs.cloud.google.com/docs/terraform/resource-management/store-state

Practice questions

Single choice

Which Terraform command previews the changes it would make without changing any infrastructure?

  1. terraform init
  2. terraform plan
  3. terraform apply
  4. terraform destroy
Show answer

Answer: B. terraform plan

terraform plan compares configuration, state and real resources and prints the proposed changes. apply makes changes, destroy removes resources, and init only prepares the working directory.

Select all that apply

Which practices fit keeping Terraform state in a Cloud Storage bucket?

  1. Enable Object Versioning on the bucket
  2. Give bucket admin rights only to a small group
  3. Commit the state file to the Git repository
  4. Allow public read so every tool can fetch it
  5. Assume state never contains sensitive data
Show answer

Answer: A. Enable Object Versioning on the bucket, B. Give bucket admin rights only to a small group

Object Versioning keeps earlier state versions for recovery, and limiting bucket admin rights protects the file that describes your whole environment. State should not be committed to source control, and it can contain sensitive values, so public access is wrong.

True or false

True or false: if someone edits a Terraform-managed resource by hand in the console, Terraform instantly reverts the change on its own.

Show answer

Answer: False

False. Terraform only acts when you run it. The next plan detects the drift and proposes to bring the resource back to the configuration; nothing runs in the background.

Practice 8 questions on this topic in Bitzu

Short lessons, instant explanations and spaced review of what you get wrong. Free on iOS and Android.

Download on the App StoreGet it on Google Play

More Associate Cloud Engineer topics in this module