A Cloud Engineer maintains an existing infrastructure repository managed with Terraform. The engineer modifies the configuration files to update the lifecycle rules of a Google Cloud Storage bucket named `google_storage_bucket.analytics_data` and add a new Compute Engine virtual machine instance. Before running a full deployment across the entire workspace, the engineer needs to deploy ONLY the storage bucket resource changes without creating the virtual machine or altering any other resources. Which Terraform CLI command should the engineer execute?
- terraform apply -target=google_storage_bucket.analytics_dataAnswer
- Bterraform apply -resource=google_storage_bucket.analytics_data
- Cterraform plan -only=google_storage_bucket.analytics_data
- Dterraform import google_storage_bucket.analytics_data
Answer
The command `terraform apply -target=google_storage_bucket.analytics_data` targets and applies changes exclusively to the specified resource.
The `-target` flag allows cloud engineers to isolate a single resource (or module) for plan and apply operations. Executing `terraform apply -target=google_storage_bucket.analytics_data` forces Terraform to apply changes exclusively to the targeted Cloud Storage bucket while ignoring unrelated resource declarations like the new Compute Engine VM.
Step-by-Step Solution
Key Concept
Resource Targeting in Terraform Deployments