• Skip to main content

Uly.me

cloud engineer

  • Home
  • About
  • Archives

Terraform Launch EC2 Instance

August 2, 2019

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

Search This Website

Subscribe Via Email

  • Home
  • About
  • Archives

Copyright © 2023