Provisioning an EC2 Instance Inside a VPC

In this section I will provision a new VPC and create an EC2 instance inside it. I will also create a security group to SSH into this EC2 instance.

First let's create a file with the name vars.tf,

variable "AWS_REGION" {
  default = "eu-west-1"
}

variable "PATH_TO_PRIVATE_KEY" {
  default = "mykey"
}

variable "PATH_TO_PUBLIC_KEY" {
  default = "mykey.pub"
}

variable "AMIS" {
  type = map(string)
  default = {
    us-east-1 = "ami-13be557e"
    us-west-2 = "ami-06b94666"
    eu-west-1 = "ami-844e0bf7"
  }
}

Then let's create a file with the name provider.tf,

Next a file with the name key.tf,

Then let's create a file with the name vpc.tf,

Next a file with the name securitygroup.tf,

Finally a file with the name instance.tf,

Last updated

Was this helpful?