Skip to content

Instantly share code, notes, and snippets.

@grdnrio
Created March 23, 2019 21:14
Show Gist options
  • Save grdnrio/dcf539633594891c7959230fe0613eb0 to your computer and use it in GitHub Desktop.
Save grdnrio/dcf539633594891c7959230fe0613eb0 to your computer and use it in GitHub Desktop.
Example hardcoding an existing VPC
# Create a subnet to launch our instances into
resource "aws_subnet" "default" {
vpc_id = "<EXISTING VPC ID HERE>"
cidr_block = "10.0.1.0/24"
map_public_ip_on_launch = true
}
# Our default security group to access
# the instances over SSH and HTTP
resource "aws_security_group" "default" {
name = "terraform_sg_default"
description = "Used in the terraform"
vpc_id = "<EXISTING VPC ID HERE>"
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 80
to_port = 80
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 443
to_port = 443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 8443
to_port = 8443
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 30000
to_port = 35000
protocol = "tcp"
cidr_blocks = ["0.0.0.0/0"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
self = true
}
# outbound internet access
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
output "subnet" {
value = "${aws_subnet.default.id}"
}
output "security_group" {
value = "${aws_security_group.default.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment