Terraform defines infrastructure as code through a domain-specific language, letting teams describe AWS resources, store infrastructure in version control, and reproduce deployment setups. With GitHub Copilot, you can generate a starting Terraform file, then inspect and correct it before provisioning an EC2 instance. section 7.2 section 7.0
A useful EC2 configuration should account for:
- The AWS provider and deployment region. section 7.2
- An EC2 instance with an appropriate AMI and instance size. section 7.2
- Bootstrap commands that install and start Docker, optionally launching the application container. section 7.2
- A usable key pair and security-group settings; stricter environments may require a separately designed VPC. section 7.2
A minimal EC2 configuration
A Terraform file can declare the AWS provider in us-west-2 and an aws_instance resource using the t2.micro instance type. A user_data script can update the machine, install Docker, start its service, and run an nginx container. Generated output is a draft: verify omitted requirements such as Docker installation, replace placeholder credentials or key pairs, and check the infrastructure before applying it. section 7.2
Listing 7.2 Example Terraform file, including instance size
# Create a Terraform file that provisions an AWS EC2 instance of type t2.micro, installs the Docker daemon, and returns the instance's hostname.
provider "aws" {
region = "us-west-2"
}
resource "aws_instance" "example" {
ami = "ami-0c55b159cbfafe1f0"
instance_type = "t2.micro"
}
Inspect the compact provider-and-instance listing before expanding it with bootstrap commands, connection settings, lifecycle behavior, and other deployment requirements. section 7.2




