Reviewed by Aditya Kumar · Last reviewed 2026-03-24
**Example**: resource "aws_instance" "app" { ami = var.ami_id; instance_type = var.instance_type; subnet_id = aws_subnet.main.id; vpc_security_group_ids = [aws_security_group.app.id]; key_name = aws_key_pair.app.key_name; user_data = file("bootstrap.sh"); root_block_device {...
Example: resource "aws_instance" "app" { ami = var.ami_id; instance_type = var.instance_type; subnet_id = aws_subnet.main.id; vpc_security_group_ids = [aws_security_group.app.id]; key_name = aws_key_pair.app.key_name; user_data = file("bootstrap.sh"); root_block_device { volume_size = 50 }; tags = { Name = "app-server" } }. AMI: data "aws_ami" "ubuntu" { most_recent = true; owners = ["099720109477"]; filter { name = "name"; values = ["ubuntu-jammy-*"] } }. Best practice: Variables for ami, instance_type; separate security group; private subnet; detailed monitoring. terraform plan; terraform apply.
Pro-Move: 'We use data source for AMI + variable for instance_type; separate modules for VPC, SG, EC2—promotable across envs.' Red Flag: Hardcoding AMI ID—gets outdated; use data source.
According to DataEngPrep.tech, this is one of the most frequently asked Cloud/Tools interview questions, reported at 1 company. DataEngPrep.tech maintains an editor-reviewed database of 1,863 data engineering interview questions across 7 categories.