Skip to content

Instantly share code, notes, and snippets.

@sue445
Last active October 26, 2021 00:13
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 sue445/1f6cc29d3a364bf0b15a74a9e6fcb71e to your computer and use it in GitHub Desktop.
Save sue445/1f6cc29d3a364bf0b15a74a9e6fcb71e to your computer and use it in GitHub Desktop.
ISUCONの素振りの環境構築用Terraform (c.f. https://sue445.hatenablog.com/entry/2021/08/22/213634 )
resource "aws_vpc" "isucon" {
cidr_block = "172.31.0.0/16"
tags = {
Name = "isucon VPC"
}
}
resource "aws_subnet" "isucon_public_a" {
vpc_id = aws_vpc.isucon.id
cidr_block = "172.31.0.0/20"
availability_zone = "ap-northeast-1a"
map_public_ip_on_launch = true
tags = {
Name = "isucon Public a"
}
}
resource "aws_subnet" "isucon_public_c" {
vpc_id = aws_vpc.isucon.id
cidr_block = "172.31.16.0/20"
availability_zone = "ap-northeast-1c"
map_public_ip_on_launch = true
tags = {
Name = "isucon Public c"
}
}
resource "aws_subnet" "isucon_public_d" {
vpc_id = aws_vpc.isucon.id
cidr_block = "172.31.32.0/20"
availability_zone = "ap-northeast-1d"
map_public_ip_on_launch = true
tags = {
Name = "isucon Public d"
}
}
resource "aws_internet_gateway" "isucon_igw" {
vpc_id = aws_vpc.isucon.id
tags = {
Name = "isucon IGW"
}
}
resource "aws_route_table" "isucon_public" {
vpc_id = aws_vpc.isucon.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.isucon_igw.id
}
tags = {
Name = "isucon Public"
}
}
resource "aws_route_table_association" "isucon_public_a" {
subnet_id = aws_subnet.isucon_public_a.id
route_table_id = aws_route_table.isucon_public.id
}
resource "aws_route_table_association" "isucon_public_c" {
subnet_id = aws_subnet.isucon_public_c.id
route_table_id = aws_route_table.isucon_public.id
}
resource "aws_route_table_association" "isucon_public_d" {
subnet_id = aws_subnet.isucon_public_d.id
route_table_id = aws_route_table.isucon_public.id
}
# NOTE. https://ip-ranges.amazonaws.com/ip-ranges.json で公開されているAWSのCIDRをTerraformから取得する
data "aws_ip_ranges" "ec2_instance_connect" {
regions = ["ap-northeast-1"]
services = ["ec2_instance_connect"]
}
resource "aws_security_group" "isucon" {
vpc_id = aws_vpc.isucon.id
name = "isucon"
description = "isucon"
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 = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["172.31.0.0/16"]
}
ingress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = data.aws_ip_ranges.ec2_instance_connect.cidr_blocks
ipv6_cidr_blocks = data.aws_ip_ranges.ec2_instance_connect.ipv6_cidr_blocks
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
tags = {
Name = "isucon"
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment