Skip to content

Instantly share code, notes, and snippets.

@corrupt952
Created November 21, 2017 16:58
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 corrupt952/6257d2303e71fbd3213ac6a605cc59e6 to your computer and use it in GitHub Desktop.
Save corrupt952/6257d2303e71fbd3213ac6a605cc59e6 to your computer and use it in GitHub Desktop.
# VPC
resource "aws_vpc" "khasegawa" {
cidr_block = "10.0.0.0/16"
instance_tenancy = "default"
# ここが今回の話
enable_dns_support = true
enable_dns_hostnames = true
}
# Gateway
resource "aws_internet_gateway" "khasegawa" {
vpc_id = "${aws_vpc.khasegawa.id}"
}
# Route table
resource "aws_route_table" "khasegawa" {
vpc_id = "${aws_vpc.khasegawa.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.khasegawa.id}"
}
}
# Subnet
resource "aws_subnet" "khasegawa" {
vpc_id = "${aws_vpc.khasegawa.id}"
cidr_block = "10.0.0.0/24"
availability_zone = "ap-northeast-1a"
}
# Route table association
resource "aws_route_table_association" "khasegawa" {
subnet_id = "${aws_subnet.khasegawa.id}"
route_table_id = "${aws_route_table.khasegawa.id}"
}
# Security Group
resource "aws_security_group" "khasegawa" {
name = "khasegawa"
description = "khasegawa"
vpc_id = "${aws_vpc.khasegawa.id}"
# SSH
ingress {
from_port = 22
to_port = 22
protocol = "tcp"
cidr_blocks = [
"${var.ip}/32"
]
}
# 外部への通信
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
# EC2
resource "aws_instance" "khasegawa" {
ami = "${var.ami}"
instance_type = "${var.instance_type}"
disable_api_termination = false
subnet_id = "${aws_subnet.khasegawa.id}"
vpc_security_group_ids = [
"${aws_security_group.khasegawa.id}"
]
}
# EIP
resource "aws_eip" "khasegawa" {
vpc = true
}
# EIP association
resource "aws_eip_association" "khasegawa-eip-association" {
instance_id = "${aws_instance.khasegawa.id}"
allocation_id = "${aws_eip.khasegawa.id}"
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment