Skip to content

Commit caca762

Browse files
committed
add multi region sample
1 parent 96fb9cf commit caca762

File tree

4 files changed

+152
-0
lines changed

4 files changed

+152
-0
lines changed

multi_region_sample/README.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
# Multi Region Sample
2+
これはTerraformを使って複数のリージョンのリソースを操作したい場合のサンプルです。
3+
module機能を使って、中国・日本・USの3リージョンに対して同一のリソースの操作を行います。

multi_region_sample/global/main.tf

Lines changed: 69 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,69 @@
1+
variable "region" {}
2+
variable "zone" {}
3+
variable "vpc_cidr" {}
4+
variable "vsw_cidr" {}
5+
variable "project_name" {}
6+
variable "publickey" {}
7+
variable "instance_password" {}
8+
9+
resource "alicloud_vpc" "vpc" {
10+
name = "${var.project_name}-vpc"
11+
cidr_block = "${var.vpc_cidr}"
12+
}
13+
14+
resource "alicloud_vswitch" "vsw" {
15+
vpc_id = "${alicloud_vpc.vpc.id}"
16+
cidr_block = "${var.vsw_cidr}"
17+
availability_zone = "${var.zone}"
18+
}
19+
20+
resource "alicloud_security_group" "sg" {
21+
name = "${var.project_name}-sg"
22+
vpc_id = "${alicloud_vpc.vpc.id}"
23+
}
24+
25+
resource "alicloud_security_group_rule" "allow_ssh" {
26+
type = "ingress"
27+
ip_protocol = "tcp"
28+
nic_type = "intranet"
29+
policy = "accept"
30+
port_range = "22/22"
31+
priority = 1
32+
security_group_id = "${alicloud_security_group.sg.id}"
33+
cidr_ip = "0.0.0.0/0"
34+
}
35+
36+
resource "alicloud_security_group_rule" "allow_icmp" {
37+
type = "ingress"
38+
ip_protocol = "icmp"
39+
nic_type = "intranet"
40+
policy = "accept"
41+
port_range = "-1/-1"
42+
priority = 1
43+
security_group_id = "${alicloud_security_group.sg.id}"
44+
cidr_ip = "0.0.0.0/0"
45+
}
46+
47+
resource "alicloud_security_group_rule" "allow_all_from_internal" {
48+
type = "ingress"
49+
ip_protocol = "all"
50+
nic_type = "intranet"
51+
policy = "accept"
52+
port_range = "-1/-1"
53+
priority = 1
54+
security_group_id = "${alicloud_security_group.sg.id}"
55+
cidr_ip = "192.168.0.0/16"
56+
}
57+
58+
resource "alicloud_instance" "instance" {
59+
instance_name = "${var.project_name}-ecs"
60+
availability_zone = "${var.zone}"
61+
image_id = "centos_7_3_64_40G_base_20170322.vhd"
62+
instance_type = "ecs.mn4.large"
63+
system_disk_category = "cloud_efficiency"
64+
security_groups = ["${alicloud_security_group.sg.id}"]
65+
vswitch_id = "${alicloud_vswitch.vsw.id}"
66+
password = "${var.instance_password}"
67+
host_name = "${var.project_name}-${var.region}"
68+
internet_max_bandwidth_out = 100
69+
}

multi_region_sample/terraform.tf

Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
variable "access_key" {}
2+
variable "secret_key" {}
3+
variable "region_jp" {}
4+
variable "zone_jp" {}
5+
variable "region_cn" {}
6+
variable "zone_cn" {}
7+
variable "region_us" {}
8+
variable "zone_us" {}
9+
variable "project_name" {}
10+
variable "publickey" {}
11+
12+
provider "alicloud" {
13+
access_key = "${var.access_key}"
14+
secret_key = "${var.secret_key}"
15+
region = "${var.region_jp}"
16+
alias = "tokyo"
17+
}
18+
19+
provider "alicloud" {
20+
access_key = "${var.access_key}"
21+
secret_key = "${var.secret_key}"
22+
region = "${var.region_cn}"
23+
alias = "shanghai"
24+
}
25+
26+
provider "alicloud" {
27+
access_key = "${var.access_key}"
28+
secret_key = "${var.secret_key}"
29+
region = "${var.region_us}"
30+
alias = "silicon_valley"
31+
}
32+
33+
module "tokyo" {
34+
source = "./global"
35+
region = "${var.region_jp}"
36+
zone = "${var.zone_jp}"
37+
project_name = "${var.project_name}"
38+
publickey = "${var.publickey}"
39+
vpc_cidr = "192.168.1.0/24"
40+
vsw_cidr = "192.168.1.0/28"
41+
providers = {
42+
alicloud = "alicloud.tokyo"
43+
}
44+
}
45+
46+
module "shanghai" {
47+
source = "./global"
48+
region = "${var.region_cn}"
49+
zone = "${var.zone_cn}"
50+
project_name = "${var.project_name}"
51+
publickey = "${var.publickey}"
52+
vpc_cidr = "192.168.2.0/24"
53+
vsw_cidr = "192.168.2.0/28"
54+
providers = {
55+
alicloud = "alicloud.shanghai"
56+
}
57+
}
58+
59+
module "silicon_valley" {
60+
source = "./global"
61+
region = "${var.region_us}"
62+
zone = "${var.zone_us}"
63+
project_name = "${var.project_name}"
64+
publickey = "${var.publickey}"
65+
vpc_cidr = "192.168.3.0/24"
66+
vsw_cidr = "192.168.3.0/28"
67+
providers = {
68+
alicloud = "alicloud.silicon_valley"
69+
}
70+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
access_key = "xxxxxxxxxxxxxxxxxx"
2+
secret_key = "xxxxxxxxxxxxxxxxxx"
3+
region_jp = "ap-northeast-1"
4+
zone_jp = "ap-northeast-1a"
5+
region_cn = "cn-shanghai"
6+
zone_cn = "cn-shanghai-a"
7+
region_us = "us-west-1"
8+
zone_us = "us-west-1a"
9+
project_name = "multi-region-sample"
10+
publickey = "xxxxxxk"

0 commit comments

Comments
 (0)