0
0
Terraformcloud~10 mins

Ignore_changes lifecycle rule in Terraform - Interactive Code Practice

Choose your learning style9 modes available
Practice - 5 Tasks
Answer the questions below
1fill in blank
easy

Complete the code to ignore changes to the 'tags' attribute in the resource lifecycle.

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

  lifecycle {
    ignore_changes = [[1]]
  }
}
Drag options to blanks, or click blank then click option'
A"tags"
B"ami"
C"instance_type"
D"id"
Attempts:
3 left
💡 Hint
Common Mistakes
Ignoring the wrong attribute like 'ami' or 'instance_type'.
Not using quotes around the attribute name.
2fill in blank
medium

Complete the code to ignore changes to both 'user_data' and 'tags' attributes in the lifecycle block.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  user_data     = "#!/bin/bash"

  lifecycle {
    ignore_changes = [[1]]
  }
}
Drag options to blanks, or click blank then click option'
A["id", "tags"]
B["user_data"]
C["ami", "instance_type"]
D["user_data", "tags"]
Attempts:
3 left
💡 Hint
Common Mistakes
Not using a list for multiple attributes.
Including attributes that should not be ignored.
3fill in blank
hard

Fix the error in the lifecycle block to properly ignore changes to the 'security_groups' attribute.

Terraform
resource "aws_instance" "example" {
  ami             = "ami-123456"
  instance_type   = "t2.micro"
  security_groups = ["sg-12345"]

  lifecycle {
    ignore_changes = [1]
  }
}
Drag options to blanks, or click blank then click option'
A"security_groups"
B["security_groups"]
Csecurity_groups
D[security_groups]
Attempts:
3 left
💡 Hint
Common Mistakes
Using a string without brackets.
Using a variable name without quotes.
Using brackets without quotes.
4fill in blank
hard

Fill both blanks to ignore changes to 'tags' and 'user_data' attributes in the lifecycle block.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  user_data     = "#!/bin/bash"

  lifecycle {
    ignore_changes = [[1], [2]]
  }
}
Drag options to blanks, or click blank then click option'
A"tags"
B"ami"
C"user_data"
D"instance_type"
Attempts:
3 left
💡 Hint
Common Mistakes
Using wrong attribute names like 'ami' or 'instance_type'.
Not quoting the attribute names.
5fill in blank
hard

Fill all three blanks to ignore changes to 'tags', 'user_data', and 'security_groups' attributes in the lifecycle block.

Terraform
resource "aws_instance" "example" {
  ami             = "ami-123456"
  instance_type   = "t2.micro"
  user_data       = "#!/bin/bash"
  security_groups = ["sg-12345"]

  lifecycle {
    ignore_changes = [[1], [2], [3]]
  }
}
Drag options to blanks, or click blank then click option'
A"tags"
B"user_data"
C"security_groups"
D"ami"
Attempts:
3 left
💡 Hint
Common Mistakes
Including attributes that should not be ignored like 'ami'.
Not quoting attribute names.
Missing commas between list items.