https://y-ohgi.com/introduction-terraform/handson/vpc/
https://kacfg.com/terraform-vpc-ec2/
https://registry.terraform.io/providers/hashicorp/aws/3.3.0/docs/resources/vpc
-- 1. macにTerraformインストール
brew tap hashicorp/tap
brew install hashicorp/tap/terraform
brew update
brew upgrade hashicorp/tap/terraform
terraform -help
terraform -version
curl "https://awscli.amazonaws.com/AWSCLIV2.pkg" -o "AWSCLIV2.pkg"
sudo installer -pkg AWSCLIV2.pkg -target /
-- 3. tfファイル作成
vim vpc01.tf
provider "aws" {
region = "ap-northeast-1"
}
resource "aws_vpc" "vpc01" {
cidr_block = "10.0.0.0/16"
enable_dns_support = true
enable_dns_hostnames = true
tags = {
Name = "vpc01"
}
}
resource "aws_subnet" "subnet_public_a" {
vpc_id = aws_vpc.vpc01.id
availability_zone = "ap-northeast-1a"
cidr_block = "10.0.1.0/24"
tags = {
Name = "subnet_public_a"
}
}
resource "aws_internet_gateway" "internet_gateway01" {
vpc_id = aws_vpc.vpc01.id
tags = {
Name = "internet_gateway01"
}
}
resource "aws_route_table" "rt_public_a" {
vpc_id = aws_vpc.vpc01.id
route {
cidr_block = "0.0.0.0/0"
gateway_id = aws_internet_gateway.internet_gateway01.id
}
tags = {
Name = "rt_public_a"
}
}
resource "aws_route_table_association" "rt_public_a_subnet_public_a" {
route_table_id = aws_route_table.rt_public_a.id
subnet_id = aws_subnet.subnet_public_a.id
}
-- 4. terraform 実行
terraform init -upgrade
terraform plan
terraform apply
terraform output
terraform state list
aws ec2 describe-vpcs
aws ec2 describe-subnets
aws ec2 describe-internet-gateways
aws ec2 describe-route-tables
-- 5. クリーンアップ
terraform destroy