iwaseasahi / christchurches-map-infra

キリスト教会マップのインフラ管理
0 stars 0 forks source link

サブネットを Terraform で管理する #5

Closed iwaseasahi closed 3 years ago

iwaseasahi commented 3 years ago

背景

https://github.com/iwaseasahi/christchurches-map-infra/issues/3

上記 issue で VPC を管理できました。 次にサブネットをやります。

目的

サブネットを Terraform で管理する

完成条件

サブネットを Terraform で管理すること

iwaseasahi commented 3 years ago

https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/subnet

iwaseasahi commented 3 years ago
$  aws ec2 describe-subnets --filters Name=vpc-id,Values=vpc-xxxx
iwaseasahi commented 3 years ago

https://docs.aws.amazon.com/ja_jp/vpc/latest/userguide/VPC_Subnets.html

iwaseasahi commented 3 years ago

サブネット — VPC の IP アドレスの範囲。

https://docs.aws.amazon.com/ja_jp/vpc/latest/userguide/what-is-amazon-vpc.html

iwaseasahi commented 3 years ago

VPC を作成するときに、その VPC に対して、IPv4 アドレスの範囲を Classless Inter-Domain Routing (CIDR) ブロックの形式で指定する必要があります (例: 10.0.0.0/16)。これは VPC のプライマリ CIDR ブロックです。CIDR 表記の詳細については、RFC 4632 を参照してください。

https://docs.aws.amazon.com/ja_jp/vpc/latest/userguide/VPC_Subnets.html

iwaseasahi commented 3 years ago

東京リージョンの availability-zones は 3 つありました。

$ aws ec2 describe-availability-zones --region ap-northeast-1
{
    "AvailabilityZones": [
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "ap-northeast-1",
            "ZoneName": "ap-northeast-1a",
            "ZoneId": "apne1-az4",
            "GroupName": "ap-northeast-1",
            "NetworkBorderGroup": "ap-northeast-1",
            "ZoneType": "availability-zone"
        },
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "ap-northeast-1",
            "ZoneName": "ap-northeast-1c",
            "ZoneId": "apne1-az1",
            "GroupName": "ap-northeast-1",
            "NetworkBorderGroup": "ap-northeast-1",
            "ZoneType": "availability-zone"
        },
        {
            "State": "available",
            "OptInStatus": "opt-in-not-required",
            "Messages": [],
            "RegionName": "ap-northeast-1",
            "ZoneName": "ap-northeast-1d",
            "ZoneId": "apne1-az2",
            "GroupName": "ap-northeast-1",
            "NetworkBorderGroup": "ap-northeast-1",
            "ZoneType": "availability-zone"
        }
    ]
}
iwaseasahi commented 3 years ago
$ terraform import aws_subnet.public_subnet1 subnet-08xxxx
Acquiring state lock. This may take a few moments...

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.

Releasing state lock. This may take a few moments...
iwaseasahi commented 3 years ago
$ $ terraform import aws_subnet.public_subnet2 subnet-0cxxxx
Acquiring state lock. This may take a few moments...

Import successful!

The resources that were imported are shown above. These resources are now in
your Terraform state and will henceforth be managed by Terraform.