EC2 with Terraform

Let's create an EC2 instance in Terraform.

File cloudcasts.tf:

1terraform {
2 required_providers {
3 aws = {
4 source = "hashicorp/aws"
5 version = "3.41.0"
6 }
7 }
8 
9 backend "s3" {
10 bucket = "cloudcasts-courses"
11 key = "ec2-basics/terraform.tfstate"
12 profile = "cloudcasts"
13 region = "us-east-2"
14 }
15}
16 
17provider "aws" {
18 profile = "cloudcasts"
19 region = "us-east-2"
20}
21 
22resource "aws_instance" "my_instance" {
23 # A community/official AMI we selected
24 ami = "ami-00399ec92321828f5"
25 instance_type = "t3.small"
26 
27 root_block_device {
28 volume_size = 8
29 volume_type = "gp3"
30 }
31 
32 # One of our public subnets from the default VPC
33 subnet_id = "subnet-69b9ab13"
34 
35 # A security group we created in an earlier video, allow
36 # http, https, and ssh traffic
37 vpc_security_group_ids = ["sg-03a0de283057734fb"]
38 
39 # An ssh key pair we created
40 key_name = "cloudcasts-forge"
41 
42 # Some tags for the instance
43 tags = {
44 Name = "my ec2 instance"
45 Environment = "production"
46 }
47}

Don't miss out

Sign up to learn when new content is released! Courses are in production now.