Complete the code to specify the resource count.
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" count = [1] }
The count meta-argument controls how many instances of the resource are created. Here, setting count = 1 creates one instance.
Complete the code to use the 'depends_on' meta-argument correctly.
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" depends_on = [[1]] }
The depends_on meta-argument requires a list of resource addresses as strings. So, the correct format is ["aws_security_group.sg"].
Fix the error in the 'lifecycle' meta-argument to prevent resource destruction.
resource "aws_instance" "example" { ami = "ami-123456" instance_type = "t2.micro" lifecycle = { [1] = true } }
The prevent_destroy lifecycle argument set to true stops Terraform from destroying the resource unless manually overridden.
Fill both blanks to create multiple resources with unique names using 'for_each'.
resource "aws_s3_bucket" "example" { for_each = [1] bucket = "my-bucket-$[2]" acl = "private" }
each.value instead of each.key for naming.The for_each meta-argument requires a set or map. Using toset([...]) converts the list to a set. The each.key is used to access the current key for naming.
Fill all three blanks to ignore changes to the 'tags' attribute and create the resource with a count.
resource "aws_instance" "example" { count = [1] ami = "ami-123456" instance_type = "t2.micro" lifecycle = { ignore_changes = [[2]] } tags = { Name = "example-instance" } depends_on = [[3]] }
Setting count = 2 creates two instances. The ignore_changes meta-argument with "tags" tells Terraform to ignore tag changes. The depends_on list must contain resource addresses as strings, here "aws_security_group.sg".