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.
Question
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)- A4% (2)
- B72% (39)
- C17% (9)
- D7% (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.
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.
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.
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.
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
Community Discussion
No community discussion yet for this question.