-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy pathvpc.tf
78 lines (66 loc) · 2.18 KB
/
vpc.tf
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
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
resource "alicloud_vpc" "vpc" {
vpc_name = "lab-1"
cidr_block = "10.0.0.0/8"
}
data "alicloud_zones" "availability_zones" {
available_resource_creation = "VSwitch"
}
resource "alicloud_vswitch" "public" {
vswitch_name = "public"
cidr_block = "10.0.1.0/24"
vpc_id = alicloud_vpc.vpc.id
zone_id = data.alicloud_zones.availability_zones.zones.0.id
}
resource "alicloud_vswitch" "public-b" {
vswitch_name = "public"
cidr_block = "10.0.3.0/24"
vpc_id = alicloud_vpc.vpc.id
zone_id = data.alicloud_zones.availability_zones.zones.1.id
}
resource "alicloud_vswitch" "private" {
vswitch_name = "private"
cidr_block = "10.0.2.0/24"
vpc_id = alicloud_vpc.vpc.id
zone_id = data.alicloud_zones.availability_zones.zones.0.id
}
resource "alicloud_nat_gateway" "default" {
vpc_id = alicloud_vpc.vpc.id
nat_gateway_name = "http"
payment_type = "PayAsYouGo"
vswitch_id = alicloud_vswitch.public.id
nat_type = "Enhanced"
}
resource "alicloud_eip_address" "nat" {
description = "nat"
address_name = "nat"
netmode = "public"
bandwidth = "100"
payment_type = "PayAsYouGo"
internet_charge_type = "PayByTraffic"
}
resource "alicloud_eip_association" "nat" {
allocation_id = alicloud_eip_address.nat.id
instance_id = alicloud_nat_gateway.default.id
instance_type = "Nat"
}
resource "alicloud_snat_entry" "http_private" {
snat_table_id = alicloud_nat_gateway.default.snat_table_ids
source_vswitch_id = alicloud_vswitch.private.id
snat_ip = alicloud_eip_address.nat.ip_address
}
resource "alicloud_route_table" "private" {
description = "Private"
vpc_id = alicloud_vpc.vpc.id
route_table_name = "private"
associate_type = "VSwitch"
}
resource "alicloud_route_entry" "nat" {
route_table_id = alicloud_route_table.private.id
destination_cidrblock = "0.0.0.0/0"
nexthop_type = "NatGateway"
nexthop_id = alicloud_nat_gateway.default.id
}
resource "alicloud_route_table_attachment" "private" {
vswitch_id = alicloud_vswitch.private.id
route_table_id = alicloud_route_table.private.id
}