nerdexam
Google

PROFESSIONAL-CLOUD-DEVOPS-ENGINEER · Question #58

You are using Terraform to manage infrastructure as code within a CI/CD pipeline. You notice that multiple copies of the entire infrastructure stack exist in your Google Cloud project, and a new…

The correct answer is B. Confirm that the pipeline is storing and retrieving the terraform.tfstate file from Cloud Storage with. To optimize cloud spend by ensuring only a single instance of infrastructure exists when using Terraform in a CI/CD pipeline, confirm that the pipeline is consistently storing and retrieving the terraform.tfstate file from Cloud Storage.

Submitted by dimitri_ru· Apr 18, 2026Building and implementing CI/CD pipelines for a service

Question

You are using Terraform to manage infrastructure as code within a CI/CD pipeline. You notice that multiple copies of the entire infrastructure stack exist in your Google Cloud project, and a new copy is created each time a change to the existing infrastructure is made. You need to optimize your cloud spend by ensuring that only a single instance of your infrastructure stack exists at a time. You want to follow Google-recommended practices. What should you do?

Options

  • ACreate a new pipeline to delete old infrastructure stacks when they are no longer needed.
  • BConfirm that the pipeline is storing and retrieving the terraform.tfstate file from Cloud Storage with
  • CVerify that the pipeline is storing and retrieving the terraform.tfstate file from a source control.
  • DUpdate the pipeline to remove any existing infrastructure before you apply the latest

How the community answered

(54 responses)
  • A
    4% (2)
  • B
    72% (39)
  • C
    17% (9)
  • D
    7% (4)

Why each option

To optimize cloud spend by ensuring only a single instance of infrastructure exists when using Terraform in a CI/CD pipeline, confirm that the pipeline is consistently storing and retrieving the `terraform.tfstate` file from Cloud Storage.

ACreate a new pipeline to delete old infrastructure stacks when they are no longer needed.

Creating a separate pipeline to delete old stacks is a reactive cleanup measure, not a proactive solution to prevent the creation of multiple infrastructure copies in the first place.

BConfirm that the pipeline is storing and retrieving the terraform.tfstate file from Cloud Storage withCorrect

Terraform relies on its state file (`terraform.tfstate`) to understand the current infrastructure it manages; storing this state remotely in a backend like Cloud Storage ensures that all CI/CD pipeline runs operate against a consistent, shared view of the deployed infrastructure. This allows Terraform to detect existing resources and perform updates instead of creating duplicate infrastructure stacks, directly preventing redundant resource creation and optimizing cloud spend.

CVerify that the pipeline is storing and retrieving the terraform.tfstate file from a source control.

Storing the `terraform.tfstate` file in source control is generally not recommended due to potential for merge conflicts, exposure of sensitive data, and lack of locking mechanisms, which can lead to state corruption and inconsistent infrastructure management.

DUpdate the pipeline to remove any existing infrastructure before you apply the latest

Updating the pipeline to remove any existing infrastructure before applying the latest configuration would be destructive, causing unnecessary downtime and is contrary to Terraform's design for managing infrastructure updates incrementally.

Concept tested: Terraform remote state management in CI/CD

Source: https://cloud.google.com/docs/terraform/best-practices-for-using-terraform#state-management

Topics

#Terraform#CI/CD#State Management#Cloud Cost Optimization

Community Discussion

No community discussion yet for this question.

Full PROFESSIONAL-CLOUD-DEVOPS-ENGINEER Practice