Skip to content

Instantly share code, notes, and snippets.

@fukata fukata/main.tf Secret
Last active Feb 26, 2017

Embed
What would you like to do?
terraform for fukata.org
variable "aws_access_key" {}
variable "aws_secret_key" {}
variable "region" {
default = "ap-northeast-1"
}
variable "images" {
default = {
ap-northeast-1 = "ami-c68fc7a1" # Ubuntu Server 16.04 LTS (HVM), SSD Volume Type
}
}
provider "aws" {
access_key = "${var.aws_access_key}"
secret_key = "${var.aws_secret_key}"
region = "${var.region}"
}
resource "aws_vpc" "FukataOrg" {
cidr_block = "10.1.0.0/16"
instance_tenancy = "default"
enable_dns_support = "true"
enable_dns_hostnames = "false"
tags {
Name = "FukataOrg"
}
}
resource "aws_internet_gateway" "FukataOrg" {
vpc_id = "${aws_vpc.FukataOrg.id}"
}
resource "aws_subnet" "public_b" {
vpc_id = "${aws_vpc.FukataOrg.id}"
cidr_block = "10.1.1.0/24"
availability_zone = "ap-northeast-1b"
}
resource "aws_route_table" "public_route" {
vpc_id = "${aws_vpc.FukataOrg.id}"
route {
cidr_block = "0.0.0.0/0"
gateway_id = "${aws_internet_gateway.FukataOrg.id}"
}
}
resource "aws_route_table_association" "puclic_b" {
subnet_id = "${aws_subnet.public_b.id}"
route_table_id = "${aws_route_table.public_route.id}"
}
resource "aws_security_group" "web" {
name = "web"
description = "Allow SSH inbound traffic"
vpc_id = "${aws_vpc.FukataOrg.id}"
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"]
}
egress {
from_port = 0
to_port = 0
protocol = "-1"
cidr_blocks = ["0.0.0.0/0"]
}
}
resource "aws_instance" "FukataOrg" {
ami = "${var.images["ap-northeast-1"]}"
instance_type = "t2.micro"
key_name = "fukata.org"
vpc_security_group_ids = [
"${aws_security_group.web.id}"
]
subnet_id = "${aws_subnet.public_b.id}"
root_block_device = {
volume_type = "gp2"
volume_size = "50"
}
tags {
Name = "FukataOrg"
}
}
resource "aws_eip" "FukataOrg" {
vpc = true
network_interface = "${aws_instance.FukataOrg.network_interface_id}"
}
output "public ip of FukataOrg" {
value = "${aws_eip.FukataOrg.public_ip}"
}
resource "aws_route53_zone" "FukataOrg" {
name = "fukata.org."
}
resource "aws_route53_record" "default" {
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
name = "${aws_route53_zone.FukataOrg.name}"
type = "A"
ttl = "300"
records = ["${aws_eip.FukataOrg.public_ip}"]
}
resource "aws_route53_record" "www" {
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
name = "www.${aws_route53_zone.FukataOrg.name}"
type = "A"
alias {
name = "${aws_route53_record.default.name}"
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
evaluate_target_health = true
}
}
resource "aws_route53_record" "tabearuki" {
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
name = "tabearuki.${aws_route53_zone.FukataOrg.name}"
type = "A"
alias {
name = "${aws_route53_record.default.name}"
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
evaluate_target_health = true
}
}
resource "aws_route53_record" "travel" {
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
name = "travel.${aws_route53_zone.FukataOrg.name}"
type = "A"
alias {
name = "${aws_route53_record.default.name}"
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
evaluate_target_health = true
}
}
resource "aws_route53_record" "camera" {
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
name = "camera.${aws_route53_zone.FukataOrg.name}"
type = "A"
alias {
name = "${aws_route53_record.default.name}"
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
evaluate_target_health = true
}
}
resource "aws_route53_record" "dev" {
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
name = "dev.${aws_route53_zone.FukataOrg.name}"
type = "A"
alias {
name = "${aws_route53_record.default.name}"
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
evaluate_target_health = true
}
}
resource "aws_route53_record" "api" {
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
name = "api.${aws_route53_zone.FukataOrg.name}"
type = "A"
alias {
name = "${aws_route53_record.default.name}"
zone_id = "${aws_route53_zone.FukataOrg.zone_id}"
evaluate_target_health = true
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.