Complete the code to add a check block that asserts the instance type is t2.micro.
resource "aws_instance" "example" { instance_type = "t2.micro" [1] { condition = var.instance_type == "t2.micro" error_message = "Instance type must be t2.micro" } }
The correct keyword to define a check block in Terraform is check. This block allows you to assert conditions on resource attributes.
Complete the code to assert that the AMI ID is not empty in the check block.
resource "aws_instance" "example" { ami = var.ami_id instance_type = "t2.micro" check { condition = [1] error_message = "AMI ID must not be empty" } }
The condition should check that var.ami_id is not an empty string using != "".
Fix the error in the check block condition to correctly assert that the count is greater than zero.
resource "aws_instance" "example" { count = var.instance_count instance_type = "t2.micro" check { condition = var.instance_count [1] 0 error_message = "Instance count must be greater than zero" } }
The condition should assert that var.instance_count is greater than zero using the '>' operator.
Fill both blanks to assert that the environment variable is either 'dev' or 'prod'.
variable "environment" { type = string } resource "aws_instance" "example" { instance_type = "t2.micro" check { condition = var.environment [1] ["dev", "prod"] error_message = "Environment must be 'dev' or 'prod'" } }
The correct operator to check if a value is inside a list is in. The blank uses 'in' to form the condition.
Fill all three blanks to assert that the tag 'Name' exists and is not empty.
resource "aws_instance" "example" { tags = { Name = var.instance_name } check { condition = contains(keys(var.tags), [1]) && var.tags[[2]] [3] "" error_message = "Tag 'Name' must exist and not be empty" } }
The condition checks if the key 'Name' exists in the tags and that its value is not empty. So, the key name is 'Name' and the operator is '!='.