Complete the code to create multiple instances using count.
resource "aws_instance" "example" { count = [1] ami = "ami-123456" instance_type = "t2.micro" }
The count argument expects a number to specify how many instances to create.
Complete the code to create resources using for_each with a map.
resource "aws_s3_bucket" "example" { for_each = [1] bucket = each.key acl = "private" }
The for_each argument expects a map or set of strings to iterate over keys or values.
Fix the error in the code by choosing the correct for_each value.
resource "aws_security_group_rule" "example" { for_each = [1] type = "ingress" from_port = 80 to_port = 80 protocol = "tcp" cidr_blocks = [each.value] }
for_each requires a map or set of strings to iterate with keys and values.
Fill both blanks to create multiple resources with count and reference the index.
resource "aws_instance" "example" { count = [1] ami = "ami-123456" instance_type = "t2.micro" tags = { Name = "instance-$[2]" } }
Use count to specify number of instances and count.index to reference each instance's index.
Fill all three blanks to create resources using for_each and access keys and values.
resource "aws_s3_bucket" "example" { for_each = [1] bucket = [2] acl = "private" tags = { Environment = [3] } }
Use a map for for_each, then access keys with each.key and values with each.value.