provider "aws" { region = "ap-northeast-1" } resource "aws_vpc" "demo_vpc_main" { cidr_block = "10.9.0.0/16" enable_dns_support = true enable_dns_hostnames = true tags = { Name = "demo_vpc_main" } } resource "aws_subnet" "demo_subnet_public_1" { vpc_id = aws_vpc.demo_vpc_main.id cidr_block = "10.9.1.0/24" map_public_ip_on_launch = true availability_zone = "ap-northeast-1a" tags = { Name = "demo_subnet_public_1" } } resource "aws_subnet" "demo_subnet_public_2" { vpc_id = aws_vpc.demo_vpc_main.id cidr_block = "10.9.2.0/24" map_public_ip_on_launch = true availability_zone = "ap-northeast-1c" tags = { Name = "demo_subnet_public_2" } } resource "aws_internet_gateway" "demo_igw_main" { vpc_id = aws_vpc.demo_vpc_main.id tags = { Name = "demo_igw_main" } } resource "aws_route_table" "demo_route_table_main" { vpc_id = aws_vpc.demo_vpc_main.id route { cidr_block = "0.0.0.0/0" gateway_id = aws_internet_gateway.demo_igw_main.id } tags = { Name = "demo_route_table_main" } } resource "aws_route_table_association" "demo_assoc_public_1" { subnet_id = aws_subnet.demo_subnet_public_1.id route_table_id = aws_route_table.demo_route_table_main.id } resource "aws_route_table_association" "demo_assoc_public_2" { subnet_id = aws_subnet.demo_subnet_public_2.id route_table_id = aws_route_table.demo_route_table_main.id } resource "aws_security_group" "demo_sg_web" { vpc_id = aws_vpc.demo_vpc_main.id 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"] } tags = { Name = "demo_sg_web" } } resource "aws_instance" "demo_web_1" { ami = "ami-0f75d1a8c9141bd00" instance_type = "t2.micro" subnet_id = aws_subnet.demo_subnet_public_1.id security_groups = [aws_security_group.demo_sg_web.id] user_data = <<-EOF #!/bin/bash yum update -y yum install -y httpd echo "