Google Cloud Professional Cloud DevOps Engineer — Question 106
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?
Answer options
- A. Create a new pipeline to delete old infrastructure stacks when they are no longer needed.
- B. Confirm that the pipeline is storing and retrieving the terraform.tfstate file from Cloud Storage with the Terraform gcs backend.
- C. Verify that the pipeline is storing and retrieving the terraform.tfstate file from a source control.
- D. Update the pipeline to remove any existing infrastructure before you apply the latest configuration.
Correct answer: B
Explanation
The correct answer is B because using the Terraform gcs backend allows for proper state management in Google Cloud, preventing multiple instances of the infrastructure stack. Options A and D do not address the root cause of the issue, and C is incorrect since source control is not a recommended method for storing tfstate files in this context.