TERRAFORM-ASSOCIATE-003 practice question 16 of 30

[Understand Terraform Basics and CLI] Which two steps are required to provision new infrastructure in the Terraform workflow? Choose two correct answers.

Full set: 226 questions
Answer options
A: Plan
B: Import
C: Alidate
D: Init Correct answer
E: apply Correct answer
Correct Answer:
D. Init; E. apply
Explanation

The core Terraform workflow to provision new infrastructure consists of two mandatory steps. First, terraform init is run to initialize the working directory. This command downloads the necessary provider plugins and configures the backend, preparing the environment for subsequent operations. Second, terraform apply is executed to create, update, or destroy infrastructure. This command creates an execution plan, prompts the user for confirmation (unless a plan file is provided or auto-approval is enabled), and then carries out the planned actions to build the resources defined in the configuration files.

Why Incorrect

A. Plan: While terraform plan is a critical best practice for previewing changes, it is not strictly required. The terraform apply command will automatically generate a plan and ask for confirmation if run without a saved plan file.
B. Import: The terraform import command is used to bring existing infrastructure, created outside of Terraform, under Terraform's management. It is not part of the workflow for provisioning new infrastructure.
C. Validate: The terraform validate command checks the syntax of Terraform configuration files. It is a useful pre-flight check but is not a required step in the core provisioning workflow.

References

1. HashiCorp Learn, "Terraform Core Workflow": This official tutorial outlines the standard workflow. It states, "The core Terraform workflow consists of three stages: Write... Plan... Apply." However, it clarifies the relationship between plan and apply: "To deploy your infrastructure, run the terraform apply command... Terraform will print out the execution plan... and will prompt you to approve it." This shows apply incorporates the planning action. The init step is presented as the prerequisite first command. (See "Initialize your project" and "Apply your configuration" sections).

2. HashiCorp, Terraform Documentation, "Command: init": "The terraform init command is used to initialize a working directory containing Terraform configuration files. This is the first command that should be run after writing a new Terraform configuration or after cloning an existing one from version control."

3. HashiCorp, Terraform Documentation, "Command: apply": "The terraform apply command executes the actions proposed in a Terraform plan to create, update, or destroy infrastructure... If you run terraform apply without passing a saved plan file, Terraform automatically creates a new plan and prompts you to approve it before taking any action."

4. HashiCorp, Terraform Documentation, "Command: plan": "The terraform plan command creates an execution plan... This command is a convenient way to check whether the proposed changes match what you expect before you apply them..." This positions plan as a verification step rather than a mandatory provisioning step.

Scroll to Top