Soru

Zorluk: OrtaDeploying Infrastructure using Deployment Manager or Terraform

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?

  1. terraform apply -target=google_storage_bucket.analytics_dataCevap
  2. B
    terraform apply -resource=google_storage_bucket.analytics_data
  3. C
    terraform plan -only=google_storage_bucket.analytics_data
  4. D
    terraform import google_storage_bucket.analytics_data

Cevap

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.

Adım Adım Çözüm

1
Identify the goal of targeted resource deployment
The engineer needs to isolate the Cloud Storage bucket resource update from other uncommitted configuration additions in the same directory.
Running a standard `terraform apply` would attempt to provision all defined resources, including the unwanted virtual machine instance.
2
Select the correct Terraform CLI targeting flag
Use `-target=resource_type.resource_name` during the execution phase.
The `-target` option instructs Terraform to focus only on the specified resource address and any of its direct dependencies.

Anahtar Kavram

Resource Targeting in Terraform Deployments
Bu soruyu puanla