Created
August 5, 2020 21:49
-
-
Save TheBinitGhimire/5e6348671c506b9bf949afc5aa80956a to your computer and use it in GitHub Desktop.
Terraform Template to create an EC2 Instance on Default VPC with your name in the "Owner" tag, and Security Group allowing ports 22, 80 and 443 in Inbound Rules (ingress) and all traffic in Outbound Rules (egress)
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Terraform Template to create an EC2 Instance on Default VPC with your name in the "Owner" tag, and Security Group allowing ports 22, 80 and 443 in Inbound Rules (ingress) and all traffic in Outbound Rules (egress) | |
provider "aws" { | |
region = "us-east-1" | |
} | |
data "aws_ami" "ubuntu" { | |
most_recent = true | |
filter { | |
name = "name" | |
values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] | |
} | |
filter { | |
name = "virtualization-type" | |
values = ["hvm"] | |
} | |
owners = ["099720109477"] | |
} | |
resource "aws_security_group" "nicesecuritygroup" { | |
name = "nicesecuritygroup" | |
description = "Allow HTTP, HTTPS and SSH" | |
ingress { | |
description = "HTTP, HTTPS and SSH" | |
from_port = 80 | |
to_port = 80 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
description = "HTTP, HTTPS and SSH" | |
from_port = 22 | |
to_port = 22 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
ingress { | |
description = "HTTP, HTTPS and SSH" | |
from_port = 443 | |
to_port = 443 | |
protocol = "tcp" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
egress { | |
from_port = 0 | |
to_port = 0 | |
protocol = "-1" | |
cidr_blocks = ["0.0.0.0/0"] | |
} | |
tags = { | |
Name = "nicesecuritygroup" | |
} | |
} | |
resource "aws_instance" "web" { | |
ami = data.aws_ami.ubuntu.id | |
instance_type = "t2.micro" | |
security_groups = ["nicesecuritygroup"] | |
tags = { | |
Owner = "Binit" | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment