0
0
Terraformcloud~10 mins

Meta-arguments overview 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 use the meta-argument that controls resource creation count.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  [1] = 3
}
Drag options to blanks, or click blank then click option'
Afor_each
Bdepends_on
Ccount
Dlifecycle
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'depends_on' instead of 'count' to create multiple resources.
Confusing 'for_each' with 'count' for simple multiple resource creation.
2fill in blank
medium

Complete the code to use the meta-argument that defines dependencies between resources.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  [1] = [aws_security_group.sg]
}
Drag options to blanks, or click blank then click option'
Adepends_on
Bcount
Cfor_each
Dprovider
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count' to manage dependencies instead of 'depends_on'.
Not specifying dependencies causing resource creation errors.
3fill in blank
hard

Fix the error in the code by choosing the correct meta-argument to iterate over a map.

Terraform
resource "aws_s3_bucket" "example" {
  [1] = var.bucket_names
  bucket = [1].value
}
Drag options to blanks, or click blank then click option'
Acount
Bfor_each
Cdepends_on
Dprovider
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count' with maps instead of 'for_each'.
Trying to access '.value' without using 'for_each'.
4fill in blank
hard

Fill both blanks to correctly prevent Terraform from deleting a resource on destroy and to ignore changes to tags.

Terraform
resource "aws_instance" "example" {
  ami           = "ami-123456"
  instance_type = "t2.micro"
  lifecycle {
    [1] = true
    [2] = ["tags"]
  }
}
Drag options to blanks, or click blank then click option'
Aprevent_destroy
Bignore_changes
Ccreate_before_destroy
Dreplace_triggered_by
Attempts:
3 left
💡 Hint
Common Mistakes
Confusing 'create_before_destroy' with 'prevent_destroy'.
Not using 'ignore_changes' causing unwanted updates.
5fill in blank
hard

Fill all three blanks to correctly use meta-arguments to create multiple resources from a map, specify a provider, and define dependencies.

Terraform
resource "aws_instance" "example" {
  [1] = var.instances
  provider    = aws.[2]
  [3] = [aws_security_group.sg]
  ami           = "ami-123456"
  instance_type = "t2.micro"
}
Drag options to blanks, or click blank then click option'
Afor_each
Bus-east-1
Cdepends_on
Dcount
Attempts:
3 left
💡 Hint
Common Mistakes
Using 'count' instead of 'for_each' for maps.
Incorrect provider region name.
Omitting 'depends_on' causing resource creation order issues.