やりかた
provider
にalias
を設定する- 各リソースでproviderを指定する
- providerを2つ以上定義する場合、全リソースにどのproviderを利用するかを書かないといけないっぽい
- CloudFront、TrustedAdvisorなどus-east-1リージョンでしか管理されていないリソースがいくつかあって、それを他リソースと混じったリポジトリで管理していく場合に必要っぽい
ソース
1 2 3 4 5 6 7 8 9 10 11 |
provider "aws" { alias = "us" version = "~> 2.9" region = "us-east-1" } provider "aws" { alias = "japan" version = "~> 2.9" region = "ap-northeast-1" } |
1 2 3 4 5 6 7 8 9 |
resource "aws_vpc" "japan" { provider = aws.japan cidr_block = "172.16.0.0/16" } resource "aws_vpc" "us" { provider = aws.us cidr_block = "192.168.0.0/24" } |
terraform plan
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 |
------------------------------------------------------------------------ An execution plan has been generated and is shown below. Resource actions are indicated with the following symbols: + create Terraform will perform the following actions: # aws_vpc.japan will be created + resource "aws_vpc" "japan" { + arn = (known after apply) + assign_generated_ipv6_cidr_block = false + cidr_block = "172.16.0.0/16" + default_network_acl_id = (known after apply) + default_route_table_id = (known after apply) + default_security_group_id = (known after apply) + dhcp_options_id = (known after apply) + enable_classiclink = (known after apply) + enable_classiclink_dns_support = (known after apply) + enable_dns_hostnames = (known after apply) + enable_dns_support = true + id = (known after apply) + instance_tenancy = "default" + ipv6_association_id = (known after apply) + ipv6_cidr_block = (known after apply) + main_route_table_id = (known after apply) + owner_id = (known after apply) } # aws_vpc.us will be created + resource "aws_vpc" "us" { + arn = (known after apply) + assign_generated_ipv6_cidr_block = false + cidr_block = "192.168.0.0/24" + default_network_acl_id = (known after apply) + default_route_table_id = (known after apply) + default_security_group_id = (known after apply) + dhcp_options_id = (known after apply) + enable_classiclink = (known after apply) + enable_classiclink_dns_support = (known after apply) + enable_dns_hostnames = (known after apply) + enable_dns_support = true + id = (known after apply) + instance_tenancy = "default" + ipv6_association_id = (known after apply) + ipv6_cidr_block = (known after apply) + main_route_table_id = (known after apply) + owner_id = (known after apply) } Plan: 2 to add, 0 to change, 0 to destroy. ------------------------------------------------------------------------ |