ExamGecko
Home Home / HashiCorp / Terraform Associate 003

HashiCorp Terraform Associate 003 Practice Test - Questions Answers, Page 14

Question list
Search
Search

Which option cannot be used to keep secrets out of Terraform configuration files?

A.
A Terraform provider
A.
A Terraform provider
Answers
B.
Environment variables
B.
Environment variables
Answers
C.
A -var flag
C.
A -var flag
Answers
D.
secure string
D.
secure string
Answers
Suggested answer: D

Explanation:

A secure string is not a valid option to keep secrets out of Terraform configuration files. A secure string is a feature of AWS Systems Manager Parameter Store that allows you to store sensitive data encrypted with a KMS key. However, Terraform does not support secure strings natively and requires a custom data source to retrieve them. The other options are valid ways to keep secrets out of Terraform configuration files. A Terraform provider can expose secrets as data sources that can be referenced in the configuration. Environment variables can be used to set values for input variables that contain secrets. A -var flag can be used to pass values for input variables that contain secrets from the command line or a file.Reference= [AWS Systems Manager Parameter Store], [Terraform AWS Provider Issue #55], [Terraform Providers], [Terraform Input Variables]

When using Terraform to deploy resources into Azure, which scenarios are true regarding state files? (Choose two.)

A.
When you change a Terraform-managed resource via the Azure Cloud Console, Terraform updates the state file to reflect the change during the next plan or apply
A.
When you change a Terraform-managed resource via the Azure Cloud Console, Terraform updates the state file to reflect the change during the next plan or apply
Answers
B.
Changing resources via the Azure Cloud Console records the change in the current state file
B.
Changing resources via the Azure Cloud Console records the change in the current state file
Answers
C.
When you change a resource via the Azure Cloud Console, Terraform records the changes in a new state file
C.
When you change a resource via the Azure Cloud Console, Terraform records the changes in a new state file
Answers
D.
Changing resources via the Azure Cloud Console does not update current state file
D.
Changing resources via the Azure Cloud Console does not update current state file
Answers
Suggested answer: A, D

Explanation:

Terraform state is a representation of the infrastructure that Terraform manages. Terraform uses state to track the current status of the resources it creates and to plan future changes. However, Terraform state is not aware of any changes made to the resources outside of Terraform, such as through the Azure Cloud Console, the Azure CLI, or the Azure API. Therefore, changing resources via the Azure Cloud Console does not update the current state file, and it may cause inconsistencies or conflicts with Terraform's desired configuration. To avoid this, it is recommended to manage resources exclusively through Terraform or to use theterraform importcommand to bring existing resources under Terraform's control.

When you change a Terraform-managed resource via the Azure Cloud Console, Terraform does not immediately update the state file to reflect the change. However, the next time you runterraform planorterraform apply, Terraform will compare the state file with the actual state of the resources in Azure and detect any drifts or differences. Terraform will then update the state file to match the current state of the resources and show you the proposed changes in the execution plan. Depending on the configuration and the change, Terraform may try to undo the change, modify the resource further, or recreate the resource entirely. To avoid unexpected or destructive changes, it is recommended to review the execution plan carefully before applying it or to use theterraform refreshcommand to update the state file without applying any changes.

Reference=Purpose of Terraform State,Terraform State,Managing State,Importing Infrastructure, [Command: plan], [Command: apply], [Command: refresh]

Which of the following should you put into the required_providers block?

A.
version >= 3.1
A.
version >= 3.1
Answers
B.
version = ''>= 3.1''
B.
version = ''>= 3.1''
Answers
C.
version ~> 3.1
C.
version ~> 3.1
Answers
Suggested answer: B

Explanation:

Therequired_providersblock is used to specify the provider versions that the configuration can work with. Theversionargument accepts a version constraint string, which must be enclosed in double quotes. The version constraint string can use operators such as>=,~>,=, etc. to specify the minimum, maximum, or exact version of the provider. For example,version = '>= 3.1'means that the configuration can work with any provider version that is 3.1 or higher.Reference= [Provider Requirements] and [Version Constraints]

Which of the following methods, used to provision resources into a public cloud, demonstrates the concept of infrastructure as code?

A.
curl commands manually run from a terminal
A.
curl commands manually run from a terminal
Answers
B.
A sequence of REST requests you pass to a public cloud API endpoint Most Voted
B.
A sequence of REST requests you pass to a public cloud API endpoint Most Voted
Answers
C.
A script that contains a series of public cloud CLI commands
C.
A script that contains a series of public cloud CLI commands
Answers
D.
A series of commands you enter into a public cloud console
D.
A series of commands you enter into a public cloud console
Answers
Suggested answer: C

Explanation:

The concept of infrastructure as code (IaC) is to define and manage infrastructure using code, rather than manual processes or GUI tools. A script that contains a series of public cloud CLI commands is an example of IaC, because it uses code to provision resources into a public cloud. The other options are not examples of IaC, because they involve manual or interactive actions, such as running curl commands, sending REST requests, or entering commands into a console.Reference= [Introduction to Infrastructure as Code with Terraform] and [Infrastructure as Code]

Which are forbidden actions when the terraform state file is locked? Choose three correct answers.

A.
Terraform state list
A.
Terraform state list
Answers
B.
Terraform destroy
B.
Terraform destroy
Answers
C.
Terraform validate
C.
Terraform validate
Answers
D.
Terraform validate
D.
Terraform validate
Answers
E.
Terraform for
E.
Terraform for
Answers
F.
Terraform apply
F.
Terraform apply
Answers
Suggested answer: B, C, F

Explanation:

The terraform state file is locked when a Terraform operation that could write state is in progress. This prevents concurrent state operations that could corrupt the state. The forbidden actions when the state file is locked are those that could write state, such asterraform apply,terraform destroy,terraform refresh,terraform taint,terraform untaint,terraform import, andterraform state *. Theterraform validatecommand is also forbidden, because it requires an initialized working directory with the state file. The allowed actions when the state file is locked are those that only read state, such asterraform plan,terraform show,terraform output, andterraform console.Reference= [State Locking] and [Command: validate]

Which of these ate secure options for storing secrets for connecting to a Terraform remote backend? Choose two correct answers.

A.
A variable file
A.
A variable file
Answers
B.
Defined in Environment variables
B.
Defined in Environment variables
Answers
C.
Inside the backend block within the Terraform configuration
C.
Inside the backend block within the Terraform configuration
Answers
D.
Defined in a connection configuration outside of Terraform
D.
Defined in a connection configuration outside of Terraform
Answers
Suggested answer: B, D

Explanation:

Environment variables and connection configurations outside of Terraform are secure options for storing secrets for connecting to a Terraform remote backend. Environment variables can be used to set values for input variables that contain secrets, such as backend access keys or tokens. Terraform will read environment variables that start with TF_VAR_ and match the name of an input variable.For example, if you have an input variable called backend_token, you can set its value with the environment variable TF_VAR_backend_token1. Connection configurations outside of Terraform are files or scripts that provide credentials or other information for Terraform to connect to a remote backend.For example, you can use a credentials file for the S3 backend2, or a shell script for the HTTP backend3. These files or scripts are not part of the Terraform configuration and can be stored securely in a separate location. The other options are not secure for storing secrets. A variable file is a file that contains values for input variables. Variable files are usually stored in the same directory as the Terraform configuration or in a version control system. This exposes the secrets to anyone who can access the files or the repository.You should not store secrets in variable files1. Inside the backend block within the Terraform configuration is where you specify the type and settings of the remote backend. The backend block is part of the Terraform configuration and is usually stored in a version control system. This exposes the secrets to anyone who can access the configuration or the repository.You should not store secrets in the backend block4.Reference= [Terraform Input Variables]1, [Backend Type: s3]2, [Backend Type: http]3, [Backend Configuration]4

Which of these statements about Terraform Cloud workspaces is false?

A.
They have role-based access controls
A.
They have role-based access controls
Answers
B.
You must use the CLI to switch between workspaces
B.
You must use the CLI to switch between workspaces
Answers
C.
Plans and applies can be triggered via version control system integrations
C.
Plans and applies can be triggered via version control system integrations
Answers
D.
They can securely store cloud credentials
D.
They can securely store cloud credentials
Answers
Suggested answer: B

Explanation:

The statement that you must use the CLI to switch between workspaces is false. Terraform Cloud workspaces are different from Terraform CLI workspaces. Terraform Cloud workspaces are required and represent all of the collections of infrastructure in an organization. They are also a major component of role-based access in Terraform Cloud. You can grant individual users and user groups permissions for one or more workspaces that dictate whether they can manage variables, perform runs, etc.You can create, view, and switch between Terraform Cloud workspaces using the Terraform Cloud UI, the Workspaces API, or the Terraform Enterprise Provider5. Terraform CLI workspaces are optional and allow you to create multiple distinct instances of a single configuration within one working directory. They are useful for creating disposable environments for testing or experimenting without affecting your main or production environment.You can create, view, and switch between Terraform CLI workspaces using the terraform workspace command6. The other statements about Terraform Cloud workspaces are true. They have role-based access controls that allow you to assign permissions to users and teams based on their roles and responsibilities.You can create and manage roles using the Teams API or the Terraform Enterprise Provider7. Plans and applies can be triggered via version control system integrations that allow you to link your Terraform Cloud workspaces to your VCS repositories.You can configure VCS settings, webhooks, and branch tracking to automate your Terraform Cloud workflow8. They can securely store cloud credentials as sensitive variables that are encrypted at rest and only decrypted when needed.You can manage variables using the Terraform Cloud UI, the Variables API, or the Terraform Enterprise Provider9.Reference= [Workspaces]5, [Terraform CLI Workspaces]6, [Teams and Organizations]7, [VCS Integration]8, [Variables]9

When should you use the force-unlock command?

A.
You have a high priority change
A.
You have a high priority change
Answers
B.
Automatic unlocking failed
B.
Automatic unlocking failed
Answers
C.
apply failed due to a state lock
C.
apply failed due to a state lock
Answers
D.
You see a status message that you cannot acquire the lock
D.
You see a status message that you cannot acquire the lock
Answers
Suggested answer: B

Explanation:

You should use the force-unlock command when automatic unlocking failed. Terraform will lock your state for all operations that could write state, such as plan, apply, or destroy. This prevents others from acquiring the lock and potentially corrupting your state. State locking happens automatically on all operations that could write state and you won't see any message that it is happening. If state locking fails, Terraform will not continue. You can disable state locking for most commands with the -lock flag but it is not recommended. If acquiring the lock is taking longer than expected, Terraform will output a status message. If Terraform doesn't output a message, state locking is still occurring if your backend supports it. Terraform has a force-unlock command to manually unlock the state if unlocking failed. Be very careful with this command. If you unlock the state when someone else is holding the lock it could cause multiple writers. Force unlock should only be used to unlock your own lock in the situation where automatic unlocking failed. To protect you, the force-unlock command requires a unique lock ID. Terraform will output this lock ID if unlocking fails. This lock ID acts as a nonce, ensuring that locks and unlocks target the correct lock. The other situations are not valid reasons to use the force-unlock command. You should not use the force-unlock command if you have a high priority change, if apply failed due to a state lock, or if you see a status message that you cannot acquire the lock. These situations indicate that someone else is holding the lock and you should wait for them to finish their operation or contact them to resolve the issue. Using the force-unlock command in these cases could result in data loss or inconsistency.Reference= [State Locking], [Command: force-unlock]

Which is the best way to specify a tag of v1.0.0 when referencing a module stored in Git (for example.

Git::https://example.com/vpc.git)?

A.
Append pref=v1.0.0 argument to the source path
A.
Append pref=v1.0.0 argument to the source path
Answers
B.
Add version = ''1.0.0'' parameter to module block
B.
Add version = ''1.0.0'' parameter to module block
Answers
C.
Nothing modules stored on GitHub always default to version 1.0.0
C.
Nothing modules stored on GitHub always default to version 1.0.0
Answers
Suggested answer: A

Explanation:

The best way to specify a tag of v1.0.0 when referencing a module stored in Git is to append?ref=v1.0.0argument to the source path. This tells Terraform to use a specific Git reference, such as a branch, tag, or commit, when fetching the module source code. For example,source = 'git::https://example.com/vpc.git?ref=v1.0.0'. This ensures that the module version is consistent and reproducible across different environments.Reference= [Module Sources], [Module Versions]

Terraform configuration can only import modules from the public registry.

A.
True
A.
True
Answers
B.
False
B.
False
Answers
Suggested answer: B

Explanation:

Terraform configuration can import modules from various sources, not only from the public registry. Modules can be sourced from local file paths, Git repositories, HTTP URLs, Mercurial repositories, S3 buckets, and GCS buckets. Terraform supports a number of common conventions and syntaxes for specifying module sources, as documented in the [Module Sources] page.Reference= [Module Sources]

Total 195 questions
Go to page: of 20