Complete the code to assign the value based on the condition.
variable "environment" { default = "production" } output "instance_type" { value = var.environment == "production" ? [1] : "t2.micro" }
The ternary expression checks if the environment is "production". If true, it assigns "t2.large"; otherwise, "t2.micro".
Complete the code to set the bucket versioning based on the environment.
resource "aws_s3_bucket" "example" { bucket = "my-app-bucket" versioning { enabled = var.environment == "production" ? [1] : false } }
The versioning enabled attribute expects a boolean. If environment is "production", it should be true; otherwise false.
Fix the error in the conditional expression for setting the instance count.
resource "aws_instance" "web" { count = var.environment == "production" ? [1] : 1 ami = "ami-123456" instance_type = "t2.micro" }
The count attribute expects a number, not a string. So use 3 without quotes for production.
Fill both blanks to set the environment tag based on the environment variable.
resource "aws_instance" "app" { ami = "ami-654321" instance_type = "t2.medium" tags = { Environment = var.environment [1] "production" ? [2] : "dev" } }
The tag Environment should be set to "production" if var.environment equals "production", otherwise "dev".
Fill all three blanks to create a conditional expression that sets the instance size and count.
resource "aws_instance" "db" { instance_type = var.environment [1] "production" ? [2] : "t2.small" count = var.environment [3] "production" ? 2 : 1 ami = "ami-789012" }
The instance_type is "m5.large" if environment is "production", else "t2.small". The count is 2 if production, else 1. Both conditions use ==.