HashiCorp Certified: Terraform Associate (004) (HCTA0-004) Questions and Answers
The public Terraform Module Registry is free to use.
terraform apply will fail if you have not run terraform plan first to update the plan output.
When you use a backend that requires authentication, it is best practice to:
What command can you run to generateDOT (Graphviz)formatted data to visualize Terraform dependencies?
You have provisioned some virtual machines (VMs) on Google Cloud Platform (GCP) using the gcloud command line tool. However, you are standardizing with Terraform and want to manage these VMs using Terraform instead. What are the two things you must do to achieve this? Choose two correct answers.
What is terraform plan -refresh-only intended to detect?
Which of these are features of HCP Terraform/Terraform Cloud? (Pick the 2 correct responses)
Which of the following should you add in the required_providers block to define a provider version constraint?
When should you run terraform init?
Exhibit:
Error: Saved plan is stale
The given plan file can no longer be applied because the state was changed by another operation after the plan was created.
You have a saved execution plan containing desired changes for infrastructure managed by Terraform. After running terraform apply my.tfplan, you receive the error shown. How can you apply the desired changes? (Pick the 2 correct responses below.)
Which parameters does terraform import require? Choose two correct answers.
Which provider authentication method prevents credentials from being stored in the state file?
Which parameters does the import block require? (Pick the 2 correct responses below.)
Setting the TF_LOG environment variable to DEBUG causes debug messages to be logged into stdout.
You want to create a string that combines a generated random_id and a variable and reuse that string several times in your configuration. What is the simplest correct way to implement this without repeating the random_id and variable?
Which of the following module source paths does not specify a remote module?
Which command must you run before you run a plan or apply for the first time?
_______backends support state locking.
You add a new provider to your configuration and immediately run terraform apply in the CD using the local backend. Why does the apply fail?
All standard backend types support state locking, and remote operations like plan, apply, and destroy.
Your Terraform configuration declares a variable. You want to enforce that its value meets your specific requirements, and you want to block the Terraform operation if it does not. What should you add to your configuration?
Which of the following is not true of Terraform providers?
You are updating a child module with the resource block shown in the exhibit below. The public_ip attribute of the resource needs to be accessible to the parent module.
Exhibit:
resource " aws_instance " " example " {
ami = " ami-0a123456789abcdef "
instance_type = " t3.micro "
}
How do you meet this requirement?
Which of the following command would be use to access all of the attributes and details of a resource managed by Terraform?
How does the use of Infrastructure as Code (IaC) enhance the reliability of your infrastructure?
Pick the two correct responses below.
Which of these actions are forbidden when the Terraform state file is locked? (Pick the 3 correct responses)
Infrastructure as Code (laC) can be stored in a version control system along with application code.
Which of the following is not a key principle of infrastructure as code?
What kind of configuration block will manage an infrastructure object with settings specified within the block?
You can install community and partner plugins using terraform init.
You ' re building a CI/CD (continuous integration/continuous delivery) pipeline and need to inject sensitive variables into your Terraform run. How can you do this safely?
Which command must you first run before performing further Terraform operations in a working directory?
When declaring a variable, setting the sensitive argument to true will prevent the value from being stored in the state file.
You have deployed a new webapp with a public IP address on a cloud provider. However, you did not create any outputs for your code. What is the best method to quickly find the IP address of the resource you deployed?
What does terraform import do?
Which of these ate secure options for storing secrets for connecting to a Terraform remote backend? Choose two correct answers.
The exhibit below shows part of a Terraform configuration you have been asked to update. The name of the Azure Virtual Network should be set to the name of the resource group followed by a dash and the word vnet.
Exhibit:
data " azurerm_resource_group " " example " {
name = var.resource_group_name
}
resource " azurerm_virtual_network " " example " {
name = ______________________
}
Which expression fulfills this requirement?
Which of the following is true about terraform apply?(Pick 2 correct responses)
Your risk management organization requires that new AWS S3 buckets must be private and encrypted at rest. How can Terraform Cloud automatically and proactively enforce this security control?
You have declared a variable called var.list which is a list of objects that all have an attribute id . Which options will produce a list of the IDs? Choose two correct answers.
Exhibit:
resource " aws_instance " " example " {
ami = " ami-0a123456789abcdef "
instance_type = " t3.micro "
}
You are updating a child module with the resource block shown in the exhibit. The public_ip attribute of the resource needs to be accessible to the parent module. How do you meet this requirement?
You have a Terraform configuration that defines a single virtual machine with no references to it, You have run terraform apply to create the resource, and then removed the resource definition from your Terraform configuration file.
What will happen you run terraform apply in the working directory again?
Terraform configuration (including any module references) can contain only one Terraform provider type.
As a developer, you want to ensure your plugins are up to date with the latest versions. Which Terraform command should you use?
In a HCP Terraform/Terraform Cloud workspace linked to a version control repository, speculative plan runs start automatically when you merge or commit changes to version control.
When you initialize Terraform, where does it cache modules from the public Terraform Registry?
How can you trigger a run in a Terraform Cloud workspace that is connected to a Version Control System (VCS) repository?
You want to bring an existing database under Terraform management. What information is required to create a new import block for the database?
Pick the 2 correct responses below:
Variables declared within a module are accessible outside of the module.
Which type of information does the Terraform Registry provide about the modules it hosts?
You have two separate Terraform configurations:
Configuration A provisions a virtual network and subnets.
Configuration B provisions compute resources that must be attached to those subnets.
In Configuration B, you have a terraform_remote_state data source configured to read Configuration A’s local state file. When running terraform plan for Configuration B in a CI/CD pipeline, Terraform fails because the state file cannot be found and is not accessible to the pipeline runtime.
What is the best solution to reliably access the state data from Configuration A in this scenario?
You have set the TF_LOG_PATH environment variable for Terraform, and you would like to ensure the logs contain all debug-level messages and verbose process logs.
Which action should you take?
If a DevOps team adopts AWS CloudFormation as their standardized method for provisioning public cloud resoruces, which of the following scenarios poses a challenge for this team?
What is modified when executing Terraform inrefresh-only mode?
How does the Terraform cloud integration differ from other state backends such as S3, Consul,etc?
Your DevOps team is currently using the local backend for your Terraform configuration. You would like to move to a remote backend to store the state file in a central location. Which of the following backends would not work?
Any user can publish modules to the public Terraform Module Registry.
You used Terraform to create an ephemeral development environment in the cloud and are now ready to destroy all the infrastructure described by your Terraform configuration. To be safe, you would like to first see all the infrastructure that Terraform will delete.
Which command should you use to show all the resources that will be deleted? (Pick the 2 correct responses)
Define the purpose of state in Terraform.
When does Sentinel enforce policy logic during a Terraform Cloud run?
You modified your Terraform configuration and run Terraform plan to review the changes. Simultaneously, your teammate manually modified the infrastructure component you are working on. Since you already ran terraform plan locally, the execution plan for terraform apply will be the same.
Which command doesnotcause Terraform to refresh its state?
You decide to move a Terraform state file to Amazon S3 from another location. You write the code below into a file called backend.tf.
Which command will migrate your current state file to the new S3 remote backend?
You cannot install third party plugins using terraform init.
A child module can always access variables declared in its parent module.
What functionality do providers offer in Terraform? (Pick the 3 correct responses below.)
What is a Terraform provider not responsible for?
Which of the following should you put into the required_providers block?
Only the user that generated a terraform plan may apply it.
Which are forbidden actions when the terraform state file is locked? Choose three correct answers.
When do you need to explicitly execute Terraform in refresh-only mode?
What does this code do?
terraform { required_providers { aws = " > = 3.0 " }}
When you use a remote backend that needs authentication, HashiCorp recommends that you:
You modified your Terraform configuration to fix a typo in the resource ID by renaming it from photoes to photos. What configuration will you add to update the resource ID in state without destroying the existing resource?
Original configuration:
resource " aws_s3_bucket " " photoes " {
bucket_prefix = " images "
}
Updated configuration:
resource " aws_s3_bucket " " photos " {
bucket_prefix = " images "
}
You have used Terraform lo create an ephemeral development environment in the (loud and are now ready to destroy all the Infrastructure described by your Terraform configuration To be safe, you would like to first see all the infrastructure that Terraform will delete.
Which command should you use to show all of the resources that mil be deleted? Choose two correct answers.
You have created a main.tf Terraform configuration consisting of an application server, a database and a load balanced. You ran terraform apply and Terraform created all of the resources successfully.
Now you realize that you do not actually need the load balancer, so you run terraform destroy without any flags. What will happen?
You need to destroy all of the resources in your Terraform workspace, except for aws_instance.ubuntu[1], which you want to keep. How can you tell Terraform to stop managing that specific resource without destroying it?
How can terraform plan aid in the development process?
If a module declares a variable with a default, that variable must also be defined within the module.
You are writing a child Terraform module that provisions an AWS instance. You want to reference the IP address returned by the child module in the root configuration. You name the instance resource " main ' .
Which of these is the correct way to define the output value?
Terraform installs its providers during which phase?
You have a simple Terraform configuration containing one VM (virtual machine) in a cloud provider. You run terraform apply and the VM is created successfully. What will happen if you run terraform apply again immediately afterwards without changing any Terraform code?
Only the user that generated a plan may apply it.
The -refresh-only parameter will update your state file when used with terraform plan.
terraform destroy is the only way to remove infrastructure with Terraform.
How do you specify a module’s version when publishing it to the public terraform Module Registry?
When using multiple configuration of the same Terraform provider, what meta-argument must you include in any non-default provider configurations?
Which statements are true about terraform apply? (Choose TWO correct answers)
What task does the terraform import command perform?
Where does HashiCorp recommend you store API tokens and other secrets within your team ' s Terraform workspaces?
Pick three correct responses below:
You want to define a single input variable to capture configuration values for a server. The values must represent memory as a number, and the server name as a string.
Which variable type could you use for this input?
The HCP Terraform private registry keeps the module configurations confidential within your organization.
Does terraform init create an example main.tf file in the current directory?
Where can Terraform not load a provider from?
One cloud block always maps to a single HCP Terraform/Terraform Cloud workspace.
Part of a configuration is shown in the exhibit below.
You want to pass the id of the vsphere_datacenter data source to the datacenter_id argument of the vsphere_folder resource.
Which reference would you use?
Your team is using version 3.1.4 of a module from the public Terraform Registry, and they are worried about possible breaking changes in future versions of the module. Which version argument should you add to the module block to prevent newer versions from being used?
Which of the following does HCP Terraform perform during a health assessment for a workspace?
Which of the following methods, used to provision resources into a public cloud, demonstrates the concept of infrastructure as code?
Exhibit:
provider " aws " { region = " us-east-1 " }
provider " aws " { region = " us-west-2 " }
You need to deploy resources into two different AWS regions in the same Terraform configuration using the provider blocks shown in the exhibit. What do you need to add to the provider configuration to deploy a resource to the us-west-2 AWS region?
A Terraform provider is NOT responsible for:
Which Terraform collection type stores values as key/value pairs?
You ' re writing a Terraform configuration that needs to read input from a local file called id_rsa.pub . Which built-in Terraform function can you use to import the file ' s contents as a string?
INcheck block ' s assertion fails, Terraform blocks the current operation from executing.
Which command add existing resources into Terraform state?
You want to use API tokens and other secrets within your team ' s Terraform workspaces. Where does HashiCorp recommend you store these sensitive values?
(Pick 3 correct responses)
You can develop a custom provider to manage its resources using Terraform.
Your team often uses API calls to create and manage cloud infrastructure. In what ways does Terraform differ from conventional infrastructure management approaches?
Which method for sharing Terraform modules fulfills the following criteria:
Keeps the module configurations confidential within your organization.
Supports Terraform ' s semantic version constraints.
Provides a browsable directory of your modules.