0
0
Terraformcloud~20 mins

Ignore_changes lifecycle rule in Terraform - Practice Problems & Coding Challenges

Choose your learning style9 modes available
Challenge - 5 Problems
🎖️
Ignore_changes Mastery
Get all challenges correct to earn this badge!
Test your skills under time pressure!
service_behavior
intermediate
2:00remaining
Effect of ignore_changes on resource updates

Consider a Terraform resource with the ignore_changes lifecycle rule applied to the tags attribute. What happens when you manually update the tags of this resource outside Terraform and then run terraform apply?

Terraform
resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"

  tags = {
    Environment = "dev"
  }

  lifecycle {
    ignore_changes = ["tags"]
  }
}
ATerraform will throw an error during apply because tags were changed outside Terraform.
BTerraform will detect the manual tag changes and overwrite them with the tags defined in the configuration.
CTerraform will ignore manual changes to tags and keep them as they are without overwriting.
DTerraform will remove the tags attribute completely from the resource.
Attempts:
2 left
💡 Hint

Think about what ignore_changes means for attributes changed outside Terraform.

Configuration
intermediate
2:00remaining
Correct syntax for ignore_changes lifecycle rule

Which of the following Terraform resource lifecycle blocks correctly uses ignore_changes to ignore changes to the metadata and labels attributes?

A
lifecycle {
  ignore_changes = [metadata, labels]
}
B
lifecycle {
  ignore_changes = ("metadata", "labels")
}
C
lifecycle {
  ignore_changes = { metadata, labels }
}
D
lifecycle {
  ignore_changes = ["metadata", "labels"]
}
Attempts:
2 left
💡 Hint

Remember how lists of strings are written in Terraform HCL.

Architecture
advanced
2:30remaining
Using ignore_changes in multi-environment Terraform setup

You manage multiple environments (dev, staging, prod) with Terraform. You want to allow manual changes to the description attribute of a resource in the dev environment only, without Terraform overwriting it on apply. How should you configure ignore_changes to achieve this?

Terraform
variable "environment" {
  type = string
}

resource "aws_s3_bucket" "example" {
  bucket = "my-bucket-${var.environment}"
  description = "Managed by Terraform"

  lifecycle {
    ignore_changes = var.environment == "dev" ? ["description"] : []
  }
}
AUse a conditional expression in <code>ignore_changes</code> to ignore <code>description</code> only when environment is dev.
BSet <code>ignore_changes</code> to always ignore <code>description</code> for all environments.
CRemove <code>ignore_changes</code> and manually revert changes after apply.
DUse separate Terraform workspaces without <code>ignore_changes</code>.
Attempts:
2 left
💡 Hint

Think about how to conditionally apply lifecycle rules based on variables.

security
advanced
2:00remaining
Security risks of using ignore_changes on sensitive attributes

What is a potential security risk when using ignore_changes on sensitive attributes like password or access_key in Terraform resources?

ATerraform will overwrite sensitive attributes with empty values, causing service disruption.
BManual changes to sensitive attributes outside Terraform will persist unnoticed, possibly causing security drift.
CTerraform will expose sensitive attributes in logs when using ignore_changes.
Dignore_changes disables encryption on sensitive attributes.
Attempts:
2 left
💡 Hint

Consider what happens if Terraform ignores changes to secrets made outside its control.

Best Practice
expert
3:00remaining
Best practice for using ignore_changes with nested attributes

You have a resource with a nested attribute settings.network. You want Terraform to ignore changes only to the network nested block but still manage other parts of settings. Which ignore_changes configuration is correct?

Terraform
resource "example_resource" "test" {
  settings = {
    network = {
      cidr_block = "10.0.0.0/16"
      dns = "8.8.8.8"
    }
    logging = true
  }

  lifecycle {
    ignore_changes = ["settings.network"]
  }
}
Aignore_changes = ["settings.network"]
Bignore_changes = ["settings"]
Cignore_changes = ["settings.network.cidr_block", "settings.network.dns"]
Dignore_changes = ["settings.network.*"]
Attempts:
2 left
💡 Hint

Think about how Terraform references nested blocks in ignore_changes.