provisioning-1/vpc.tf

58 lines
1.3 KiB
Terraform
Raw Normal View History

2025-07-03 17:08:46 +09:00
# ---------------------------
# VPC
# ---------------------------
resource "aws_vpc" "hands_on_vpc" {
cidr_block = "10.0.0.0/16"
enable_dns_hostnames = true # DNSホスト名を有効化
tags = {
# Name = "userXX-hands-on-vpc"
Name =
}
}
# ---------------------------
# Subnet
# ---------------------------
resource "aws_subnet" "hands_on_public_1a_sn" {
vpc_id = aws_vpc.hands_on_vpc.id
cidr_block = "10.0.1.0/24"
availability_zone = "ap-northeast-1a"
tags = {
# Name = "userXX-hands-on-public-1a-sn"
Name =
}
}
# ---------------------------
# Internet Gateway
# ---------------------------
resource "aws_internet_gateway" "hands_on_igw" {
vpc_id = aws_vpc.hands_on_vpc.id
tags = {
# Name = "userXX-hands-on-igw"
Name =
}
}
# ---------------------------
# Route table
# ---------------------------
# Route table作成
resource "aws_route_table" "hands_on_public_rt" {
vpc_id = aws_vpc.hands_on_vpc.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.hands_on_igw.id
}
tags = {
# Name = "userXX-hands-on-public-rt"
Name =
}
}
# SubnetとRoute tableの関連付け
resource "aws_route_table_association" "hands_on_public_rt_associate" {
subnet_id = aws_subnet.hands_on_public_1a_sn.id
route_table_id = aws_route_table.hands_on_public_rt.id
}