Courseiva

CCNA Resource Lifecycle Management Questions

34 questions · Resource Lifecycle Management topic · All types, answers revealed

1
MCQmedium

What is the primary risk of relying solely on 'create_before_destroy' without considering dependency chains?

A.It can lead to resource contention or naming conflicts.
B.It causes infinite loops in Terraform.
C.It increases the cost of the plan.
D.It creates a security risk.
AnswerA

Naming conflicts are the most common failure mode.

Why this answer

If multiple resources have circular dependencies or if the provider lacks support for concurrent resource existence, the create_before_destroy might fail.

2
Multi-Selecthard

Which TWO factors must be considered when using 'replace_triggered_by' with multiple resources?

Select 2 answers
A.The trigger only works on the 'tags' attribute.
B.The trigger requires 'create_before_destroy' to be false.
C.The trigger cannot cause a circular dependency loop.
D.The referenced resource must be in the same state file.
E.The trigger only works with AWS resources.
AnswersC, D

Circular loops will cause the plan to fail.

Why this answer

You must ensure the resources exist and that you are not creating circular replacement dependencies.

3
Multi-Selectmedium

Which THREE of the following are true regarding 'create_before_destroy'?

Select 3 answers
A.It is intended to minimize downtime during updates.
B.It is defined within the resource lifecycle block.
C.It requires sufficient quota to temporarily have two resources.
D.It automatically resolves all name collision issues.
E.It is only available for AWS providers.
AnswersA, B, C

Correct purpose.

Why this answer

It ensures availability, requires enough capacity for two resources, and can be used on any resource.

4
Multi-Selecthard

Which TWO of the following are valid ways to handle a resource that has become 'tainted'?

Select 2 answers
A.Run 'terraform apply' to recreate it.
B.Run 'terraform untaint <resource_name>' to clear the status.
C.Run 'terraform refresh' to clear the taint.
D.Use 'terraform state rm' to fix the taint.
E.Use 'terraform plan -force-apply'.
AnswersA, B

Standard path.

Why this answer

You can either fix the taint by running a successful apply or manually untaint it using the CLI.

5
MCQhard

You want to remove a resource from Terraform management without destroying the actual AWS resource. Which command accomplishes this?

A.terraform destroy -target
B.terraform untrack
C.terraform apply -ignore
D.terraform state rm
AnswerD

This unmanages the resource from the state file.

Why this answer

terraform state rm removes the resource from the state file, effectively 'unmanaging' it so it will not be destroyed on the next apply.

6
MCQeasy

Which of the following is a valid lifecycle meta-argument in Terraform?

A.delete_on_success
B.wait_for_completion
C.create_before_destroy
D.create_after_update
AnswerC

This is valid.

Why this answer

create_before_destroy is a standard, widely used lifecycle meta-argument.

7
Multi-Selectmedium

Which THREE of the following are valid lifecycle meta-arguments?

Select 3 answers
A.version_pin
B.allow_replace
C.create_before_destroy
D.ignore_changes
E.prevent_destroy
AnswersC, D, E

Valid meta-argument.

Why this answer

create_before_destroy, prevent_destroy, and ignore_changes are the standard lifecycle meta-arguments.

8
MCQmedium

You have defined a resource and set 'prevent_destroy = true'. If you perform a 'terraform destroy', what will happen?

A.Terraform will destroy all resources except the one with the rule.
B.Terraform will ignore the rule and destroy the resource anyway.
C.Terraform will return an error and abort the destroy operation.
D.Terraform will prompt for confirmation twice.
AnswerC

This is the expected behavior for prevent_destroy.

Why this answer

Terraform will return an error stating that the resource cannot be destroyed due to the lifecycle rule, and the operation will be aborted.

9
Multi-Selecthard

Which TWO of the following are limitations of 'ignore_changes'?

Select 2 answers
A.It can be difficult to manage for deeply nested attributes.
B.It cannot ignore changes to the resource type itself.
C.It is only compatible with the AWS provider.
D.It requires all attributes to be ignored.
E.It only works with primitive types.
AnswersA, B

Nested attribute paths can be complex.

Why this answer

It cannot ignore the change of resource type, and it requires careful syntax for complex attributes.

10
MCQhard

You need to ignore changes to a specific index in a list of security group rules. How is this formatted in 'ignore_changes'?

A.ignore_changes = [ingress[0].cidr_blocks]
B.ignore_changes = [ingress.0]
C.ignore_changes = { ingress = [0] }
D.ignore_changes = [ingress[0]]
AnswerD

This is the correct syntax for targeting a list element.

Why this answer

You can target specific elements of a collection in the ignore_changes list using index notation.

11
Multi-Selecthard

Which TWO of the following accurately describe the behavior of 'terraform state rm'?

Select 2 answers
A.It stops Terraform from tracking the resource.
B.It leaves the real-world resource running.
C.It requires the 'force' flag for all resources.
D.It is a permanent action that cannot be undone.
E.It destroys the infrastructure in the cloud.
AnswersA, B

This is the purpose.

Why this answer

It removes the item from the state but leaves the actual infrastructure in place.

12
MCQeasy

Which meta-argument is used to prevent a resource from being replaced when its configuration changes?

A.force_keep
B.keep_alive
C.prevent_replace
D.ignore_changes
AnswerD

By ignoring the attribute causing the change, you prevent the replacement cycle.

Why this answer

Actually, there is no meta-argument that prevents replacement if the configuration changes; you would use 'ignore_changes' to prevent the *detection* of the change.

13
MCQmedium

When a resource is marked as 'tainted', what is the expected outcome of the next 'terraform apply'?

A.It is ignored.
B.It is destroyed and recreated.
C.It is removed from the state file.
D.It is updated in place.
AnswerB

This is the definition of tainting.

Why this answer

A tainted resource is destroyed and recreated during the next apply operation.

14
MCQeasy

Which file stores the mapping between your Terraform configuration and the real-world infrastructure?

A.terraform.tfstate
B.terraform.tfvars
C.provider.tf
D.backend.tf
AnswerA

This is the state file.

Why this answer

The state file (terraform.tfstate) is the primary location for this mapping.

15
MCQmedium

If you use 'ignore_changes = [tags]', and you manually change the tags in the AWS Console, what will happen during the next 'terraform plan'?

A.Terraform will plan to revert the tags to the configuration state.
B.Terraform will fail with an attribute mismatch error.
C.Terraform will update the state file to match the console tags.
D.Terraform will ignore the difference and perform no action on the tags.
AnswerD

This is exactly what the ignore_changes argument does.

Why this answer

Terraform will see the difference, but because 'tags' is in the ignore list, it will not propose a plan to revert those changes.

16
MCQmedium

You need to ensure that an AWS Auto Scaling Group maintains capacity during a configuration change that requires a new launch template. Which lifecycle meta-argument should you use?

A.replace_triggered_by
B.ignore_changes
C.create_before_destroy = true
D.prevent_destroy
AnswerC

This enables the desired behavior for zero-downtime updates.

Why this answer

The create_before_destroy meta-argument ensures that the new resource is created before the old one is destroyed, preventing downtime during replacement.

17
MCQmedium

A resource has an attribute 'tags' that is managed by an external script. You want Terraform to ignore any changes made to 'tags' after the initial creation. How should you configure the 'lifecycle' block?

A.ignore_changes = [tags]
B.lifecycle { tags = ignore }
C.prevent_destroy = [tags]
D.ignore_changes = [all]
AnswerA

This correctly targets the tags attribute for exclusion.

Why this answer

The ignore_changes meta-argument allows you to specify a list of attributes that Terraform should skip during the refresh and plan phases.

18
Multi-Selecthard

Which TWO actions can be taken to resolve issues where a resource must be replaced, but 'prevent_destroy' is enabled?

Select 2 answers
A.Use 'terraform apply -auto-approve'.
B.Run 'terraform state rm' to remove the resource from state and re-import.
C.Use 'terraform refresh' to update the constraint.
D.Remove the prevent_destroy block from the configuration.
E.Set the prevent_destroy argument to false in the CLI.
AnswersB, D

This removes the resource and its associated constraints.

Why this answer

You must either remove the meta-argument from the code or use the state management to remove the resource constraint before re-applying.

19
MCQhard

When using 'replace_triggered_by', what happens if the referenced resource is deleted?

A.The resource is destroyed as well.
B.The resource is kept as is.
C.The plan fails because the dependency cannot be evaluated.
D.The trigger is ignored.
AnswerC

Terraform requires the referenced resource to exist.

Why this answer

If the referenced resource is deleted, the expression for replace_triggered_by becomes invalid, and Terraform will return an error during the plan phase.

20
MCQeasy

Where are lifecycle meta-arguments placed within a Terraform configuration?

A.At the root of the configuration file.
B.Inside the resource block, within a 'lifecycle' block.
C.Inside the module block.
D.Inside the provider block.
AnswerB

This is the correct location.

Why this answer

Lifecycle meta-arguments must be placed inside a 'lifecycle' block within the resource block.

21
MCQmedium

You need to ensure that a resource is always recreated if an associated data source value changes. Which meta-argument supports this?

A.create_before_destroy
B.replace_triggered_by
C.lifecycle_hooks
D.prevent_destroy
AnswerB

This is the correct meta-argument for triggering replacement.

Why this answer

The replace_triggered_by meta-argument is specifically designed to force replacement when other resources or data sources change.

22
MCQmedium

What is the purpose of the 'terraform state refresh' command?

A.To delete orphaned resources.
B.To update the state file with current real-world resource attributes.
C.To apply changes to the cloud provider.
D.To upgrade the Terraform version.
AnswerB

This is the purpose of refresh.

Why this answer

This command reconciles the state file with the actual infrastructure in the real world to detect drift.

23
Multi-Selectmedium

Which THREE of the following are consequences of drifting from the Terraform state?

Select 3 answers
A.The plan may show changes even if the config hasn't changed.
B.It can lead to 'Resource Not Found' errors if someone manually deletes an item.
C.It disables the use of lifecycle meta-arguments.
D.Terraform may attempt to revert changes during the next apply.
E.It automatically updates the configuration file.
AnswersA, B, D

This is the hallmark of drift.

Why this answer

Drift causes mismatches, unexpected results, and potential failure during destructive actions.

24
Multi-Selectmedium

Which THREE of the following are true about 'lifecycle' blocks?

Select 3 answers
A.They are defined inside the resource configuration block.
B.Multiple lifecycle arguments can be used in one block.
C.They allow changing the provider version dynamically.
D.They are inherited from the provider block.
E.They are evaluated during the planning phase.
AnswersA, B, E

Correct location.

Why this answer

They are per-resource, support specific arguments, and are defined inside the resource body.

25
Multi-Selectmedium

Which THREE of these are reasons to use the 'ignore_changes' lifecycle meta-argument?

Select 3 answers
A.To ignore tags applied by external cost-allocation tools.
B.To force the creation of a new resource.
C.To stop Terraform from reverting auto-scaling group capacity changes.
D.To prevent Terraform from destroying a database.
E.To ignore changes to an S3 bucket's 'last_modified_date'.
AnswersA, C, E

Valid use case.

Why this answer

These are common scenarios for ignoring drifts or auto-populated fields in Terraform.

26
MCQhard

You are managing a production database instance. You want to ensure that if a developer accidentally removes the resource block from the Terraform configuration, Terraform will refuse to destroy the database. How do you implement this?

A.Set prevent_destroy = true in the lifecycle block.
B.Set create_before_destroy = false.
C.Use the ignore_changes meta-argument for the lifecycle block.
D.Configure a provider-level block to disable deletions.
AnswerA

This is the correct configuration for preventing accidental deletion.

Why this answer

The prevent_destroy lifecycle meta-argument is a safety measure that causes a plan to fail if a resource is marked for deletion.

27
MCQhard

You have an AWS Lambda function that should be replaced whenever the source code S3 object changes. How do you trigger this replacement specifically based on the S3 object key change?

A.Use lifecycle { force_replace = true }
B.Use replace_triggered_by = [aws_s3_object.lambda_code.key]
C.Use create_before_destroy.
D.Use ignore_changes = [source_code_hash]
AnswerB

This correctly references the attribute change to trigger replacement.

Why this answer

The replace_triggered_by meta-argument allows forcing a resource to be replaced when another specified resource or attribute changes.

28
MCQmedium

When using 'create_before_destroy', what is a common side effect that may cause the plan to fail?

A.Resource naming collisions.
B.Terraform will delete the state file.
C.Provider credentials will expire.
D.All other resources will be destroyed.
AnswerA

The new resource cannot be created if the name is already taken by the existing one.

Why this answer

If the resource has a unique name or specific constraints (like an S3 bucket name), creating a new instance before destroying the old one will cause a naming collision.

29
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.

30
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.

31
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.

32
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.

33
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.

34
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.

Ready to test yourself?

Try a timed practice session using only Resource Lifecycle Management questions.