Complete the code to initialize Terraform in the current directory.
terraform [1]The terraform init command initializes the working directory containing Terraform configuration files. This is the first step before applying any changes.
Complete the code to apply Terraform changes automatically without asking for confirmation.
terraform apply [1]The -auto-approve flag applies changes without prompting for confirmation, useful for automation.
Fix the error in the backend configuration block to enable remote state storage.
terraform {
backend "s3" {
bucket = "my-terraform-state"
key = [1]
region = "us-east-1"
}
}The key value must be a string specifying the path to the state file in the S3 bucket, so it needs quotes.
Fill both blanks to create a resource block for an AWS EC2 instance with a specific AMI and instance type.
resource "aws_instance" "example" { ami = [1] instance_type = [2] }
The AMI and instance type values must be strings with quotes. The example uses a valid AMI ID and a common instance type.
Fill all three blanks to define an output that shows the public IP of an AWS instance.
output "instance_ip" { value = [1].[2].[3] }
The output references the resource type, resource name, and the attribute for the public IP address.