-
Notifications
You must be signed in to change notification settings - Fork 286
/
Copy pathaliyun-meta.tf
136 lines (124 loc) · 4.64 KB
/
aliyun-meta.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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
#==============================================================#
# File : aliyun-meta.yml
# Desc : 1-node sandbox env for x86_64/aarch64
# Ctime : 2020-05-12
# Mtime : 2024-01-23
# Path : terraform/spec/aliyun-meta.yml
# License : AGPLv3 @ https://pigsty.io/docs/about/license
# Copyright : 2018-2025 Ruohang Feng / Vonng (rh@vonng.com)
#==============================================================#
#===========================================================#
# Architecture, Instance Type, OS Images
#===========================================================#
variable "architecture" {
description = "The architecture type (amd64 or arm64), choose one from them"
type = string
default = "amd64" # comment this to use arm64
#default = "arm64" # uncomment this to use arm64
}
variable "distro" {
description = "The Distribution code"
type = string
default = "d12"
}
locals {
bandwidth = 100 # internet bandwidth in Mbps (100Mbps)
disk_size = 40 # system disk size in GB (40GB)
spot_policy = "SpotWithPriceLimit" # NoSpot, SpotWithPriceLimit, SpotAsPriceGo
spot_price_limit = 5 # only valid when spot_policy is SpotWithPriceLimit
instance_type_map = {
amd64 = "ecs.c8i.xlarge"
arm64 = "ecs.c8y.xlarge"
}
image_regex_map = {
amd64 = {
el7 = "^centos_7_9_x64"
el8 = "^rockylinux_8_10_x64"
el9 = "^rockylinux_9_4_x64"
d11 = "^debian_11_11_x64"
d12 = "^debian_12_7_x64"
u22 = "^ubuntu_20_04_x64"
u22 = "^ubuntu_22_04_x64"
u24 = "^ubuntu_24_04_x64"
an8 = "^anolisos_8_9_x64"
}
arm64 = {
el8 = "^rockylinux_8_10_arm64"
el9 = "^rockylinux_9_4_arm64"
d12 = "^debian_12_7_arm64"
u22 = "^ubuntu_22_04_arm64"
u24 = "^ubuntu_24_04_arm64"
}
}
selected_images = local.image_regex_map[var.architecture]
selected_instype = local.instance_type_map[var.architecture]
}
data "alicloud_images" "pigsty_img" {
owners = "system"
name_regex = local.selected_images[var.distro]
}
#===========================================================#
# Credentials
#===========================================================#
# add your credentials here or pass them via env
# export ALICLOUD_ACCESS_KEY="????????????????????"
# export ALICLOUD_SECRET_KEY="????????????????????"
# e.g : ./aliyun-key.sh
provider "alicloud" {
# access_key = "????????????????????"
# secret_key = "????????????????????"
}
#===========================================================#
# VPC, SWITCH, SECURITY GROUP
#===========================================================#
# use 10.10.10.0/24 cidr block as demo network
resource "alicloud_vpc" "vpc" {
vpc_name = "pigsty-net"
cidr_block = "10.10.10.0/24"
}
# add virtual switch for pigsty demo network
resource "alicloud_vswitch" "vsw" {
vpc_id = "${alicloud_vpc.vpc.id}"
cidr_block = "10.10.10.0/24"
zone_id = "cn-beijing-l"
}
# add default security group and allow all tcp traffic
resource "alicloud_security_group" "default" {
name = "default"
vpc_id = "${alicloud_vpc.vpc.id}"
}
resource "alicloud_security_group_rule" "allow_all_tcp" {
ip_protocol = "tcp"
type = "ingress"
nic_type = "intranet"
policy = "accept"
port_range = "1/65535"
priority = 1
security_group_id = "${alicloud_security_group.default.id}"
cidr_ip = "0.0.0.0/0"
}
#===========================================================#
# The meta node: pg-meta instance
#===========================================================#
resource "alicloud_instance" "pg-meta" {
instance_name = "pg-meta"
host_name = "pg-meta"
private_ip = "10.10.10.10"
instance_type = local.selected_instype
image_id = "${data.alicloud_images.pigsty_img.images.0.id}"
vswitch_id = "${alicloud_vswitch.vsw.id}"
security_groups = ["${alicloud_security_group.default.id}"]
password = "PigstyDemo4"
instance_charge_type = "PostPaid"
internet_charge_type = "PayByTraffic"
spot_strategy = local.spot_policy
spot_price_limit = local.spot_price_limit
internet_max_bandwidth_out = local.bandwidth
system_disk_size = local.disk_size
system_disk_category = "cloud_essd"
system_disk_performance_level = "PL1"
}
# print the meta IP address after provisioning
output "meta_ip" {
value = "${alicloud_instance.pg-meta.public_ip}"
}