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
Which Terraform command previews the changes it would make without changing any infrastructure?
- terraform init
- terraform plan
- terraform apply
- 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.
Which practices fit keeping Terraform state in a Cloud Storage bucket?
- Enable Object Versioning on the bucket
- Give bucket admin rights only to a small group
- Commit the state file to the Git repository
- Allow public read so every tool can fetch it
- 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: 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.
