Uly.me

cloud engineer

  • Home
  • About
  • Archives
Home/Cloud/Terraform Launch EC2 Instance

August 2, 2019

Terraform Launch EC2 Instance

Here’s the template for launching an EC2 instance via Terraform.

provider "aws" {
  region                  = "us-east-1"
  shared_credentials_file = "/home/username/.aws/credentials"
  profile                 = "default"
}
resource "aws_security_group" "hostname-sg" {
	name = "allow ssh"
	vpc_id = ""
	ingress {
		cidr_blocks = [ "10.0.0.0/8" ]
		from_port = 22
		to_port = 22
		protocol = "tcp"
	}
	egress {
		from_port = 0
		to_port = 0
		protocol = "-1"
		cidr_blocks = [ "0.0.0.0/0" ]
	}
}
resource "aws_instance" "hostname" {
	ami = "ami-xxxxxxxxxx"
	key_name = "your-key"
	instance_type = "t2.large"
	subnet_id = "subnet-xxxxxxxx"
	security_groups	= ["${aws_security_group.hostname-sg.id}"]
	tags {
		Name = "hostname"
		Environment = "development"
	}
}

provider "aws" { region = "us-east-1" shared_credentials_file = "/home/username/.aws/credentials" profile = "default" } resource "aws_security_group" "hostname-sg" { name = "allow ssh" vpc_id = "" ingress { cidr_blocks = [ "10.0.0.0/8" ] from_port = 22 to_port = 22 protocol = "tcp" } egress { from_port = 0 to_port = 0 protocol = "-1" cidr_blocks = [ "0.0.0.0/0" ] } } resource "aws_instance" "hostname" { ami = "ami-xxxxxxxxxx" key_name = "your-key" instance_type = "t2.large" subnet_id = "subnet-xxxxxxxx" security_groups = ["${aws_security_group.hostname-sg.id}"] tags { Name = "hostname" Environment = "development" } }

Filed Under: Cloud Tagged With: aws, ec2, instance, launch, security group, tags, terraform

Content delivered to your email

About Me

I'm Ulysses, a Cloud Engineer at Cardinal Health based in Columbus, Ohio. I’m a certified AWS Solutions Architect. This website is my way of documenting the things I have learned in the Cloud. When off the grid, I enjoy riding my electric skateboard. I have surfed, snowboarded and played the saxophone in the past. I hope you will find this site helpful. It's powered by WordPress and hosted in AWS LightSail.

  • Cloud
  • Linux
  • Git

Copyright © 2012–2021