TERRAFORM-ASSOCIATE-003 practice question 20 of 30

[Understand Terraform Basics and CLI] You have a simple Terraform configuration containing one virtual machine (VM) in a cloud provider. You run terraform apply and the VM is created successfully. What will happen if you terraform apply again immediately afterward without changing any Terraform code?

Full set: 226 questions
Answer options
A: Terraform will terminate and recreate the VM.
B: Terraform will create another duplicate VM.
C: Terraform will apply the VM to the state file.
D: Nothing Correct answer
Correct Answer:
D. Nothing
Explanation

Terraform is idempotent, meaning that applying the same configuration multiple times will result in the same infrastructure state. After the first successful terraform apply, Terraform records the created VM and its attributes in a state file. When you run terraform apply again without any changes to the configuration, Terraform compares the desired state (your code) with the current state (recorded in the state file and verified against the cloud provider). Since they are identical, Terraform determines that no changes are needed and will take no action on the infrastructure, simply reporting that it is already up-to-date.

Why Incorrect

A. Terraform only terminates and recreates resources if a configuration change requires it (e.g., changing an immutable property) or if the resource is tainted.
B. The state file tracks managed resources, preventing Terraform from creating duplicates for the same resource block in the configuration.
C. The VM's state was already recorded in the state file during the first successful apply command.

References

1. HashiCorp Terraform Documentation

"Core Terraform Workflow": The "Apply" section describes this behavior: "If the plan is acceptable

Terraform will proceed with the actions in the correct order... If you run terraform apply again

Terraform will look at your infrastructure and see that nothing has changed

so it won't do anything."

Source: HashiCorp

"Core Terraform Workflow"

https://developer.hashicorp.com/terraform/language/core-workflow. Accessed under the "Apply" section.

2. HashiCorp Terraform Documentation

"Command: apply": "If you run terraform apply with no pending changes

Terraform will inform you that no changes are needed and exit immediately."

Source: HashiCorp

"Command: apply"

https://developer.hashicorp.com/terraform/cli/commands/apply. Accessed under the "Usage" and main description sections.

3. HashiCorp Terraform Documentation

"Purpose of Terraform State": "This state is used by Terraform to map real world resources to your configuration

keep track of metadata

and to improve performance for large infrastructures... This allows Terraform to detect drift and determine which changes to make."

Source: HashiCorp

"Purpose of Terraform State"

https://developer.hashicorp.com/terraform/language/state. Accessed under the introductory paragraphs.

Scroll to Top