Practice Free Terraform Associate 004 Exam Online Questions
What does terraform import do?
- A . Imports existing resources into the state file
- B . Imports all infrastructure from a given cloud provider
- C . Imports a new Terraform module
- D . Imports clean copies of tainted resources
- E . None of the above
A
Explanation:
The terraform import command is used to import existing infrastructure into your Terraform state. This command takes the existing resource and associates it with a resource defined in your Terraform configuration, updating the state file accordingly. It does not generate configuration for the resource, only the state.
Which of the following does terraform apply change after you approve the execution plan? (Choose two.)
- A . Cloud infrastructure
- B . The.terraform directory
- C . The execution plan
- D . State file
- E . Terraform code
A,D
Explanation:
The terraform apply command changes both the cloud infrastructure and the state file after you approve the execution plan. The command creates, updates, or destroys the infrastructure resources to match the configuration. It also updates the state file to reflect the new state of the infrastructure. The.terraform directory, the execution plan, and the Terraform code are not changed by the terraform apply command.
Reference = Command: apply and Purpose of Terraform State
Exhibit:
data "aws_ami" "web" {
most_recent = true
owners = ["self"]
tags = {
Name = "web-server"
}
}
A data source is shown in the exhibit.
How do you reference the id attribute of this data source?
- A . aws_ami.web.id
- B . web.id
- C . data.aws_ami.web.id
- D . data.web.id
C
Explanation:
Rationale for Correct Answer
Data sources are referenced using the address
format:data.<DATA_SOURCE_TYPE>.<NAME>.<ATTRIBUTE>Here, the type is aws_ami, the name is web, and the attribute is id, so the correct reference is data.aws_ami.web.id.
Analysis of Incorrect Options (Distractors):
A (aws_ami.web.id): Incorrect because it omits the required data. prefix. This looks like a managed resource reference, not a data source.
B (web.id): Incorrect because Terraform references must include the full address (type and name); web alone is ambiguous.
D (data.web.id): Incorrect because it omits the data source type (aws_ami). Key Concept: Terraform addressing and attribute references for data sources.
Reference: Terraform Objectives ― Read, Generate, and Modify Configurations (resource/data
references and expressions).
Which command must you first run before performing further Terraform operations in a working directory?
- A . terraform import
- B . terraform workspace
- C . terraform plan
- D . terraform init
D
Explanation:
terraform init is the first command that should be run after writing a new Terraform configuration or cloning an existing one from version control. It initializes a working directory containing Terraform configuration files and downloads any required providers and modules. The other commands are used for different purposes, such as importing existing resources, switching between workspaces, generating execution plans, etc.
Infrastructure as Code (laC) can be stored in a version control system along with application code.
- A . True
- B . False
A
Explanation:
Infrastructure as Code (IaC) can indeed be stored in a version control system along with application code. This practice is a fundamental principle of modern infrastructure management, allowing teams to apply software development practices like versioning, peer review, and CI/CD to infrastructure management. Storing IaC configurations in version control facilitates collaboration, history tracking, and change management.
Reference = While this concept is a foundational aspect of IaC and is widely accepted in the industry, direct references from the HashiCorp Terraform Associate (003) study materials were not found in the provided files. However, this practice is encouraged in Terraform’s best practices and various HashiCorp learning resources.
What Terraform command always causes a state file to be updated with changes that might have been made outside of Terraform?
- A . Terraform plan Crefresh-only
- B . Terraform show Cjson
- C . Terraform apply Clock-false
- D . Terraform plan target-state
A
Explanation:
This is the command that always causes a state file to be updated with changes that might have been made outside of Terraform, as it will only refresh the state file with the current status of the real resources, without making any changes to them or creating a plan.
Which are examples of infrastructure as code? Choose two correct answers.
- A . Cloned virtual machine images
- B . Versioned configuration files
- C . Change management database records
- D . Doctor files
B
Explanation:
These are examples of infrastructure as code (IaC), which is a practice of managing and provisioning infrastructure through machine-readable definition files, rather than physical hardware configuration or interactive configuration tools.
Terraformrequiresthe Go runtime as a prerequisite for installation.
- A . True
- B . False
B
Explanation:
Terraformis written in Go, but it isdistributed as a standalone binaryanddoes notrequire the Go runtime.
Users do not need to install Go to run Terraform.
Official Terraform Documentation
Reference: Terraform Install Guide
When you include a module block in your configuration that references a module from the Terraform Registry, the "version" attribute is required.
- A . True
- B . False
B
Explanation:
The "version" attribute is optional when referencing a module from the Terraform Registry. If not specified, the latest version will be used, but it is often recommended to specify a version to ensure consistency across environments.
Reference: Terraform Module Versioning
What are some benefits of using Sentinel with Terraform Cloud/Terraform Cloud? Choose three correct answers.
- A . You can restrict specific resource configurations, such as disallowing the use of CIDR=0.0.0.0/0.
- B . You can check out and check in cloud access keys
- C . Sentinel Policies can be written in HashiCorp Configuration Language (HCL)
- D . Policy-as-code can enforce security best practices
- E . You can enforce a list of approved AWS AMIs
A,D,E
Explanation:
Sentinel is a policy-as-code framework that allows you to define and enforce rules on your Terraform configurations, states, and plans1. Some of the benefits of using Sentinel with Terraform Cloud/Terraform Enterprise are:
• You can restrict specific resource configurations, such as disallowing the use of CIDR=0.0.0.0/0, which would open up your network to the entire internet. This can help you prevent misconfigurations or security vulnerabilities in your infrastructure2.
• Policy-as-code can enforce security best practices, such as requiring encryption, authentication, or compliance standards. This can help you protect your data and meet regulatory requirements3.
• You can enforce a list of approved AWS AMIs, which are pre-configured images that contain the operating system and software you need to run your applications. This can help you ensure consistency, reliability, and performance across your infrastructure4.
Reference =
• 1: Terraform and Sentinel | Sentinel | HashiCorp Developer
• 2: Terraform Learning Resources: Getting Started with Sentinel in Terraform Cloud
• 3: Exploring the Power of HashiCorp Terraform, Sentinel, Terraform Cloud …
• 4: Using New Sentinel Features in Terraform Cloud C Medium
