Skip to content

Instantly share code, notes, and snippets.

@windy1
Created January 3, 2020 22:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save windy1/bc7303c397ec8967480af087800eacd6 to your computer and use it in GitHub Desktop.
Save windy1/bc7303c397ec8967480af087800eacd6 to your computer and use it in GitHub Desktop.
provider "aws" {
region = var.region
version = "0.0"
}
resource "aws_instance" "main" {
count = var.instance_count
ami = "ami-04b9e92b5572fa0d1"
instance_type = var.instance_type
subnet_id = aws_subnet.main.id
source_dest_check = var.source_dest_check
vpc_security_group_ids = [aws_security_group.main.id]
key_name = var.key_name
associate_public_ip_address = true
tags = {
Name = "${var.common_identifier}_${count.index + 1}"
}
}
resource "aws_vpc" "main" {
cidr_block = var.vpc_cidr_block
enable_dns_hostnames = true
enable_dns_support = true
tags = {
Name = var.common_identifier
}
}
resource "aws_internet_gateway" "main" {
vpc_id = aws_vpc.main.id
tags = {
Name = var.common_identifier
}
}
resource "aws_route" "igw" {
route_table_id = aws_vpc.main.main_route_table_id
destination_cidr_block = var.igw_route_cidr_block
gateway_id = aws_internet_gateway.main.id
}
resource "aws_security_group" "main" {
name = var.common_identifier
vpc_id = aws_vpc.main.id
ingress {
description = "Allow UDP inbound traffic"
from_port = var.udp_port_lower
to_port = var.udp_port_upper
protocol = "udp"
cidr_blocks = [var.vpc_cidr_block]
}
ingress {
description = "Allow SSH"
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = var.ssh_cidr_blocks
}
egress {
description = "Allow all outbound traffic"
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = var.outbound_cidr_blocks
}
}
resource "aws_subnet" "main" {
vpc_id = aws_vpc.main.id
cidr_block = var.subnet_cidr_block
availability_zone = "us-east-1a"
tags = {
Name = var.common_identifier
}
}
resource "aws_ec2_transit_gateway" "main" {
multicast_support = "enable"
tags = {
Name = var.common_identifier
}
}
resource "aws_ec2_transit_gateway_vpc_attachment" "main" {
subnet_ids = [aws_subnet.main.id]
transit_gateway_id = aws_ec2_transit_gateway.main.id
vpc_id = aws_vpc.main.id
tags = {
Name = var.common_identifier
}
}
resource "aws_ec2_transit_gateway_multicast_domain" "main" {
transit_gateway_id = aws_ec2_transit_gateway.main.id
tags = {
Name = var.common_identifier
}
association {
transit_gateway_attachment_id = aws_ec2_transit_gateway_vpc_attachment.main.id
subnet_ids = [aws_subnet.main.id]
}
members {
group_ip_address = "224.0.4.2"
network_interface_ids = [aws_instance.main[0].primary_network_interface_id]
}
sources {
group_ip_address = "224.0.4.2"
network_interface_ids = [aws_instance.main[0].primary_network_interface_id]
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment