Skip to content

Instantly share code, notes, and snippets.

@ruhenheim
Created June 27, 2019 08:51
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 ruhenheim/1d2f2de3f92462abd8f585c1244a7a60 to your computer and use it in GitHub Desktop.
Save ruhenheim/1d2f2de3f92462abd8f585c1244a7a60 to your computer and use it in GitHub Desktop.
ec2(t3.micro)で外部公開httpサーバだけ立ち上げてみる
provider "aws" {
region = "ap-northeast-1"
}
data "aws_ami" "recent_amazon_linux_2" {
most_recent = true
owners = ["amazon"]
filter {
name = "name"
values = ["amzn2-ami-hvm-2.0.????????-x86_64-gp2"]
}
filter {
name = "state"
values = ["available"]
}
}
resource "aws_security_group" "example_ec2" {
name = "example-ec2"
ingress {
from_port = 80
to_port = 80
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" "example" {
ami = data.aws_ami.recent_amazon_linux_2.image_id
instance_type = "t3.micro"
vpc_security_group_ids = [aws_security_group.example_ec2.id]
user_data = <<EOF
#!/bin/bash
yum install -y httpd
systemctl start httpd.service
EOF
tags = {
Name = "example"
}
}
output "example_instance_id" {
value = aws_instance.example.id
}
output "example_public_dns" {
value = aws_instance.example.public_dns
}
output "example_public_ip" {
value = aws_instance.example.public_ip
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment