Courseiva

HashiCorp Certified: Terraform Authoring and Operations Professional (AWS provider) (AWS provider) (AWS provider) — Questions 151193

193 questions total · 3pages · All types, answers revealed

Page 2

Page 3 of 3

151
MCQhard

You want to pass a complex object type to a module, but you need to ensure specific attributes are present. How do you define this in the variable block?

A.type = map(any)
B.type = list(object)
C.type = object({...})
D.type = tuple([...])
AnswerC

The object type constraint enforces both the presence and the type of specific attributes.

Why this answer

The 'object' type constraint allows you to define a schema with specific attributes and their corresponding types.

152
Multi-Selecteasy

Which THREE components are part of the 'Workspace' object in HCP Terraform?

Select 3 answers
A.State file
B.Billing invoice history
C.Global provider plugins
D.Run history
E.Variables
AnswersA, D, E

The workspace holds the current state.

Why this answer

A workspace includes state, variables, and history/runs.

153
MCQeasy

Which command helps verify if the providers are properly initialized?

A.terraform validate
B.terraform show
C.terraform plan
D.terraform providers
AnswerD

This command lists the initialized providers.

Why this answer

'terraform providers' lists all providers required by the configuration, confirming they are initialized.

154
Multi-Selecteasy

Which of these are required components when defining a provider in 'required_providers'? (Select TWO)

Select 2 answers
A.profile
B.version
C.source
D.region
E.alias
AnswersB, C

Version is the standard requirement.

Why this answer

The source address and the version are the two standard components for defining a provider requirement.

155
MCQmedium

When refactoring code, you rename a resource in your configuration. What happens if you run 'terraform plan' without updating the state?

A.Terraform will propose destroying the old resource and creating a new one.
B.Terraform will do nothing.
C.Terraform will automatically rename it in the state.
D.Terraform will throw an error and stop.
AnswerA

This is the default, disruptive behavior.

Why this answer

Terraform will assume the old resource has been deleted and the new one needs to be created, leading to unnecessary destruction of real resources.

156
MCQhard

You have a workspace configured for 'CLI-driven' workflow. What does this mean for how you apply changes?

A.The user triggers operations via the CLI
B.Operations are always automatic
C.It disables remote state
D.The plan happens locally, apply remotely
AnswerA

The CLI is the driver for the remote run.

Why this answer

CLI-driven workflows require the user to trigger the plan/apply locally, while the state is managed remotely.

157
MCQmedium

You need to ensure that all workspaces use a specific set of tags. How can this be enforced?

A.Using an HCP Terraform Sentinel policy.
B.Using a VCS branch protection rule.
C.Using a variable validation block.
D.Enabling 'Strict Mode' in the organization settings.
AnswerA

Sentinel can evaluate workspace attributes via the 'tfrun' import.

Why this answer

Sentinel can inspect the workspace configuration metadata, including tags, to ensure compliance.

158
MCQmedium

You have a list of strings that you want to convert into a set to use with for_each. Which function is preferred?

A.toset()
B.tomap()
C.distinct()
D.distinct()
E.tolist()
AnswerA

toset converts a list to a set, ideal for stable iteration.

Why this answer

The toset() function is the correct way to convert a list of strings into a set, which is required for for_each to avoid index-based instability.

159
MCQhard

When migrating from local state to HCP Terraform, which command is used to initialize the migration?

A.terraform login
B.terraform push
C.terraform init
D.terraform migrate
AnswerC

Running init with a new cloud backend configuration prompts migration.

Why this answer

'terraform init' detects the backend configuration and initiates the migration process.

160
Multi-Selecteasy

Which TWO of the following are standard stages of an HCP Terraform run pipeline?

Select 2 answers
A.Policy Check.
B.Code linting.
C.Plan.
D.Automatic refactoring.
E.State migration.
AnswersA, C

Policy checking follows the plan.

Why this answer

The pipeline consists of Plan, Policy Check, and Apply stages.

161
MCQmedium

If a user wants to ensure that a resource's lifecycle is managed by Terraform but wants to bypass the 'prevent_destroy' protection, what is the best approach?

A.Add 'ignore_changes = [prevent_destroy]' to the block.
B.Use 'terraform state rm' to remove the constraint.
C.Use 'terraform destroy -force-remove-prevent-destroy'.
D.Remove the prevent_destroy block from the configuration and apply.
AnswerD

This is the standard procedure to remove the protection.

Why this answer

You must remove the prevent_destroy rule from the code and then apply the configuration to update the state.

162
MCQeasy

Which block is used to configure provider-level settings like region or profile?

A.module {}
B.provider "aws" {}
C.terraform {}
D.resource "aws_instance" {}
AnswerB

This is the block for provider-specific settings.

Why this answer

The 'provider' block is used to configure the provider itself.

163
MCQeasy

You have accidentally committed a secret to your VCS repository. After rotating the secret, what is the best practice to ensure it is not used in your workspace?

A.Delete the repository
B.Disable VCS integration
C.Run terraform destroy
D.Use HCP Terraform sensitive variables
AnswerD

Sensitive variables ensure secrets are not stored in VCS.

Why this answer

You must remove the secret from the VCS and update the workspace variable to use a secure, non-version-controlled source.

164
MCQeasy

Which command is used to move a resource from one state file to another, commonly used when refactoring modules?

A.terraform migrate
B.terraform plan -refactor
C.terraform refresh
D.terraform state mv
AnswerD

This is the correct command for moving resources.

Why this answer

terraform state mv is the standard tool for moving resources between states or renaming them in the state file.

165
MCQhard

You are designing a module that should conditionally create resources based on a boolean input. What feature should you use?

A.Define multiple resources and use 'depends_on' to link them.
B.Use the 'count' meta-argument with a ternary expression.
C.Use an 'if' block around the resource definition.
D.Use the 'module' meta-argument inside the resource.
AnswerB

Setting 'count = var.enabled ? 1 : 0' is the standard pattern for conditional resource creation.

Why this answer

The 'count' meta-argument is commonly used to toggle resource creation based on a boolean value.

166
MCQmedium

If you need to share output values between workspaces, what is the best practice in HCP Terraform?

A.Emailing the values
B.Hardcoding the IDs
C.Exporting to a flat file
D.Using the 'terraform_remote_state' data source
AnswerD

This is the native way to access remote state outputs.

Why this answer

Using a workspace data source allows one workspace to read outputs from another safely.

167
MCQhard

A provider binary is not found in the local Terraform registry cache. What command should you run to force Terraform to download the provider again?

A.terraform plan -refresh-only
B.terraform init -upgrade
C.terraform providers install
D.terraform refresh
AnswerB

The -upgrade flag forces the re-download of providers based on constraints.

Why this answer

terraform init -upgrade forces Terraform to re-evaluate and download the latest allowed versions of providers.

168
Multi-Selectmedium

Which THREE of the following are valid ways to pass data to a module dynamically?

Select 3 answers
A.Using variables
B.Directly editing the state
C.Using a dynamic block for module calling
D.Using for_each on a module block
E.Using complex object types
AnswersA, D, E

Standard approach.

Why this answer

Passing variables, using for_each in the module block (if supported), or local variable composition are standard.

169
MCQeasy

Your team is using HCP Terraform. You need to isolate development, staging, and production environments using the same set of configuration files. Which feature should you implement?

A.Modules
B.Sentinel Policies
C.Workspaces
D.Run Triggers
AnswerC

Workspaces allow distinct state and variables for different environments.

Why this answer

Workspaces in HCP Terraform provide a way to maintain separate state files and variable sets for the same configuration.

170
MCQhard

If a developer wants to use a provider that is not in the public registry, can they still use it?

A.Yes, by using a local registry or filesystem mirror.
B.No, only registry providers are supported.
C.Yes, by setting the env var TF_IN_AUTOMATION.
D.Yes, by recompiling Terraform binary.
AnswerA

These are standard ways to handle private providers.

Why this answer

Yes, by using a custom provider installation method like the filesystem mirror.

171
MCQmedium

What is the effect of running 'terraform init -upgrade' on the '.terraform.lock.hcl' file?

A.It deletes the file.
B.It makes the file read-only.
C.It hides the file.
D.It updates the file to reflect new provider versions.
AnswerD

This is the correct function of the upgrade flag.

Why this answer

The -upgrade flag causes Terraform to ignore existing lock file constraints and update to the latest compatible versions, updating the lock file accordingly.

172
MCQmedium

You are using a module that depends on a specific provider version. Where should this constraint be defined?

A.In the 'required_providers' block within the module's 'terraform' block.
B.In the 'provider' block of the calling root module.
C.In the root module only.
D.In a shell environment variable.
AnswerA

This guarantees that the module's requirements are met during execution.

Why this answer

The 'required_providers' block within the 'terraform' block of the module is the correct location to pin versions.

173
MCQmedium

You want to use a module that is hosted in a private GitHub repository. Which authentication method should Terraform use to access it?

A.Use the same credentials that 'git clone' would use for that repository.
B.The module must be public for Terraform to access it.
C.Terraform requires a special 'git_token' variable in the module block.
D.Embed your GitHub password in the source URL.
AnswerA

Terraform leverages the underlying git command, so existing authenticated git configurations work.

Why this answer

Terraform uses the credentials configured in the local environment (e.g., ~/.git-credentials or SSH keys) to authenticate with private repositories.

174
Multi-Selecteasy

Which TWO of the following are true about the '.terraform' directory?

Select 2 answers
A.It contains the module source code downloaded from registries.
B.It should be committed to version control.
C.It contains the permanent state file.
D.It is created by 'terraform init'.
E.It is where custom provider binaries are compiled.
AnswersA, D

Downloaded modules are stored here.

Why this answer

The '.terraform' directory is used locally by Terraform to store module files and provider plugins.

175
MCQhard

When should you use the 'for_each' meta-argument within a module?

A.To iterate over a list of variables inside a resource block.
B.To replace the 'count' meta-argument when you only need one instance.
C.To instantiate multiple copies of a module based on a map or set.
D.To speed up the execution of the provider.
AnswerC

'for_each' is specifically designed for creating multiple module instances.

Why this answer

'for_each' is used to create multiple instances of a module based on a map or set of strings.

176
MCQmedium

If a user omits the 'version' in 'required_providers', what version does Terraform use?

A.It will fail to initialize.
B.The latest available version.
C.Version 1.0.0.
D.The oldest available version.
AnswerB

Without a constraint, the latest is pulled.

Why this answer

Terraform will attempt to use the latest version available in the registry if no constraint is provided.

177
Multi-Selectmedium

What are common reasons to use multiple provider instances? (Select TWO)

Select 2 answers
A.Increasing performance of the Terraform CLI.
B.Installing multiple versions of the same provider.
C.Bypassing the need for a state file.
D.Using different credentials for different resources.
E.Deploying resources to multiple AWS regions.
AnswersD, E

This is a standard use case.

Why this answer

Multiple instances are primarily used for multi-region or multi-account deployments.

178
MCQeasy

What command do you run to view the documentation for a module that has been published to a registry?

A.'terraform view-module'
B.'terraform show'
C.Check the registry website for the module page.
D.'terraform doc <module>'
AnswerC

Registry documentation is provided via the web interface.

Why this answer

The registry automatically renders documentation in the UI; no CLI command is required to 'view' the documentation directly.

179
Multi-Selectmedium

Which TWO meta-arguments can be used within a module block?

Select 2 answers
A.'count'
B.'provisioner'
C.'for_each'
D.'depends_on'
E.'lifecycle'
AnswersA, C

'count' is a valid meta-argument for modules.

Why this answer

'count' and 'for_each' are the two meta-arguments available for module blocks.

180
MCQhard

What happens if you set 'ignore_changes = all' in a resource lifecycle block?

A.It disables the prevent_destroy rule.
B.It ignores the resource existence entirely.
C.It causes Terraform to ignore all changes to the resource attributes.
D.It causes a syntax error.
AnswerC

This is the intended behavior for the 'all' keyword.

Why this answer

'all' is a special keyword in ignore_changes that instructs Terraform to ignore all attribute changes for that resource.

181
Multi-Selecthard

Which of the following are true regarding the .terraform.lock.hcl file? (Select TWO)

Select 2 answers
A.It is automatically generated by terraform init.
B.It is used to store the state file.
C.It can only be edited manually.
D.It stores secret credentials.
E.It should be committed to version control.
AnswersA, E

Yes, it is generated when providers are initialized.

Why this answer

It stores checksums for providers to ensure consistency and security across different environments.

182
MCQhard

You have two resources, A and B. You want B to be replaced whenever A is updated. How do you configure B?

A.In resource B, set lifecycle { create_before_destroy = [resource_a] }
B.In resource A, set lifecycle { triggers = [resource_b] }
C.In resource B, set lifecycle { replace_triggered_by = [resource_a] }
D.In resource B, set depends_on = [resource_a]
AnswerC

This is the correct usage of the trigger.

Why this answer

Using replace_triggered_by in B's lifecycle block, referencing resource A, forces the replacement of B when A changes.

183
MCQhard

Why would you use a 'locals' block within a module instead of passing everything through variables?

A.To reduce repetition and perform transformations on inputs.
B.To allow the user to override internal values easily.
C.To bypass input validation.
D.To store state data securely.
AnswerA

Locals clean up repetitive code and keep the module interface simple.

Why this answer

'locals' are ideal for transforming inputs, combining data, or creating complex naming conventions that the user shouldn't have to define.

184
MCQhard

You are using a dynamic block to define multiple 'tag' blocks inside an AWS resource. The dynamic block is failing because it expects a set of objects but receives a flat list. Which function best prepares your data?

A.keys()
B.distinct()
C.compact()
D.toset()
AnswerD

toset converts a list to a set, which is the preferred input for for_each to maintain stable resource indices.

Why this answer

The toset() function converts a list of strings or objects into a set, which is required by for_each to avoid index-based dependencies.

185
MCQmedium

You are creating a custom provider. What is the standard language used to write Terraform providers?

A.Python
B.Ruby
C.HCL
D.Go
AnswerD

Terraform providers are built using Go.

Why this answer

Terraform providers are written in Go (Golang) using the Terraform Plugin SDK.

186
MCQmedium

What is the impact of using 'sensitive = true' in a module output?

A.It disables the ability to use that output in other modules.
B.It encrypts the data in the state file.
C.It automatically rotates the sensitive credentials.
D.It prevents the value from being printed in the CLI output.
AnswerD

This is the main purpose of the 'sensitive' flag.

Why this answer

It marks the output as sensitive, preventing it from being printed to the console during 'terraform apply' or 'plan'.

187
Multi-Selecthard

Which TWO of the following are true regarding OPA/Sentinel policies?

Select 2 answers
A.They run after the apply phase
B.They can only be used with AWS
C.They can be set to advisory mode
D.They can be scoped to specific workspaces
E.They replace the need for IAM
AnswersC, D

Advisory mode allows the run to proceed with a warning.

Why this answer

They can be applied at the organization or workspace level and can be set to advisory or mandatory.

188
MCQmedium

When a module is updated, how do you ensure that all environments using this module get the update?

A.The module updates automatically on every 'apply'.
B.Run 'terraform init -upgrade' to fetch the latest version allowed by the constraints.
C.Delete the state file and re-run apply.
D.Restart the Terraform CLI process.
AnswerB

The '-upgrade' flag is required to override the existing locked version.

Why this answer

You must update the version constraint (if pinned) and run 'terraform init -upgrade' to fetch the new version.

189
Multi-Selecthard

What are requirements for a custom provider to be recognized by Terraform? (Select THREE)

Select 3 answers
A.Must be uploaded to the registry.
B.Must be signed by HashiCorp.
C.Must be a compiled binary.
D.Must follow a specific directory naming convention.
E.Must be written in Go.
AnswersC, D, E

Providers must be executable binaries.

Why this answer

Custom providers need a specific binary name, a specific directory structure, and possibly a configuration in .terraformrc or CLI config.

190
MCQeasy

Which organization-level setting in HCP Terraform governs who can create new workspaces?

A.Global settings
B.Team permissions
C.Agent pool settings
D.Workspace settings
AnswerB

Workspace creation is controlled by team roles within the organization.

Why this answer

Permissions for creating workspaces are managed via Organization Team permissions.

191
MCQhard

Why might someone use 'prevent_destroy = true' on a database resource while allowing it on smaller web server instances?

A.To increase the speed of the destroy process.
B.To protect critical data from accidental deletion.
C.To ensure create_before_destroy works.
D.To satisfy the AWS provider requirements.
AnswerB

This is the primary use case for safety.

Why this answer

This is a common best practice to prevent accidental loss of stateful, critical data while allowing ephemeral instances to be managed normally.

192
MCQhard

When implementing OPA policies, what is the 'soft-mandatory' enforcement level?

A.It blocks the run completely
B.It allows the run if overridden
C.It is a deprecated feature
D.It only logs the event
AnswerB

Soft-mandatory provides a warning that can be bypassed.

Why this answer

Soft-mandatory policies can be overridden by users with sufficient permissions after a warning is issued.

193
MCQmedium

You have a list of objects representing AWS tags. You need to transform this list into a map for use with a for_each argument. Which function should you use?

A.tolist()
B.flatten()
C.merge()
D.for expression
AnswerD

The for expression is the standard HCL construct for transforming lists into maps for resource iteration.

Why this answer

The for expression is the primary tool for transforming collections, allowing you to iterate over a list and produce a map.

Page 2

Page 3 of 3

All pages