Skip to content

Commit 05d0179

Browse files
authored
Merge pull request #15 from wgpsec/copilot/implement-ecs-scene-volcengine
Add Volcano Engine ECS scenario
2 parents 8efd85f + 069296b commit 05d0179

6 files changed

Lines changed: 229 additions & 0 deletions

File tree

volcengine/ecs/README.md

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
# 场景使用
2+
3+
1. 使用前请按照注意事项里内容进行配置 (若空则无需配置)
4+
2. 使用时命令如下
5+
6+
拉取
7+
```
8+
redc pull volcengine/ecs
9+
```
10+
11+
开启
12+
```
13+
redc run volcengine/ecs
14+
```
15+
16+
查询
17+
```
18+
redc status [uuid]
19+
```
20+
21+
关闭
22+
```
23+
redc stop [uuid]
24+
```
25+
26+
# 注意事项
27+
28+
## 认证配置
29+
需要配置火山引擎的访问凭证,有以下两种方式:
30+
31+
1. **环境变量方式**(推荐)
32+
```bash
33+
export VOLCENGINE_ACCESS_KEY="your-access-key"
34+
export VOLCENGINE_SECRET_KEY="your-secret-key"
35+
```
36+
37+
2. **配置文件方式**
38+
`~/.volcengine/config` 中配置
39+
40+
## 常见问题
41+
若启动场景报错,可能原因:
42+
1. 火山引擎账户余额不足
43+
2. 与火山引擎 API 网络连接超时
44+
3. 火山引擎该区域售罄或下架 instance_type 的配置机型
45+
4. 未配置正确的访问凭证(AK/SK)
46+
47+
## 场景配置说明
48+
- **实例规格**: ecs.e-c1m1.large (2核2G内存)
49+
- **计费方式**: 按量计费(PostPaid)
50+
- **系统盘**: 20GB ESSD_PL0
51+
- **操作系统**: Debian 12
52+
- **登录方式**: 随机生成的SSH密码
53+
- **区域**: 北京(cn-beijing)

volcengine/ecs/case.json

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
{
2+
"name":"ecs",
3+
"user":"copilot",
4+
"version": "1.0.0",
5+
"description":"火山引擎 ECS 场景,使用按量计费部署 Debian 实例"
6+
}

volcengine/ecs/deploy.sh

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
init(){
2+
3+
terraform init
4+
5+
}
6+
7+
start_ecs(){
8+
9+
terraform apply -auto-approve
10+
11+
}
12+
13+
stop_ecs(){
14+
15+
terraform destroy -auto-approve
16+
17+
}
18+
19+
status_ecs(){
20+
21+
terraform output
22+
23+
}
24+
25+
case "$1" in
26+
-init)
27+
init
28+
;;
29+
-start)
30+
start_ecs
31+
;;
32+
-stop)
33+
stop_ecs
34+
;;
35+
-status)
36+
status_ecs
37+
;;
38+
-h)
39+
echo -e "\033[1;34m使用 -init 初始化\033[0m"
40+
echo -e "\033[1;34m使用 -start 启动\033[0m"
41+
echo -e "\033[1;34m使用 -stop 关闭\033[0m"
42+
echo -e "\033[1;34m使用 -status 查询状态\033[0m"
43+
exit 1
44+
;;
45+
esac

volcengine/ecs/main.tf

Lines changed: 98 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
provider "random" {}
2+
3+
resource "random_password" "password" {
4+
length = 10
5+
special = true
6+
override_special = "_%@"
7+
min_upper = 1
8+
min_lower = 1
9+
min_numeric = 1
10+
min_special = 1
11+
}
12+
13+
resource "volcengine_ecs_instance" "instance" {
14+
instance_name = "volcengine_bj_ecs"
15+
instance_type = "ecs.e-c1m1.large"
16+
image_id = data.volcengine_images.debian.images[0].image_id
17+
subnet_id = volcengine_subnet.subnet.id
18+
security_group_ids = [volcengine_security_group.group.id]
19+
system_volume_type = "ESSD_PL0"
20+
system_volume_size = 20
21+
instance_charge_type = "PostPaid"
22+
password = random_password.password.result
23+
24+
user_data = base64encode(<<EOF
25+
#!/bin/bash
26+
sudo apt-get update
27+
sudo apt-get install -y ca-certificates
28+
sudo apt-get install -y curl
29+
sudo apt-get -y install wget
30+
sudo apt-get install -y lrzsz
31+
sudo apt-get install -y tmux
32+
sudo apt-get install -y unzip
33+
sudo echo "set-option -g history-limit 20000" >> ~/.tmux.conf
34+
sudo echo "set -g mouse on" >> ~/.tmux.conf
35+
36+
sudo echo "net.core.default_qdisc=fq" >> /etc/sysctl.conf
37+
sudo echo "net.ipv4.tcp_congestion_control=bbr" >> /etc/sysctl.conf
38+
sudo sysctl -p
39+
40+
sudo apt-get install -y python3-pip
41+
sudo pip3 install trzsz --break-system-packages
42+
43+
EOF
44+
)
45+
}
46+
47+
resource "volcengine_eip_address" "eip" {
48+
billing_type = "PostPaidByTraffic"
49+
bandwidth = 100
50+
isp = "BGP"
51+
name = "volcengine_bj_eip"
52+
description = "EIP for ECS instance"
53+
}
54+
55+
resource "volcengine_eip_associate" "eip_attach" {
56+
allocation_id = volcengine_eip_address.eip.id
57+
instance_id = volcengine_ecs_instance.instance.id
58+
instance_type = "EcsInstance"
59+
}
60+
61+
resource "volcengine_security_group" "group" {
62+
security_group_name = "volcengine_security_group"
63+
vpc_id = volcengine_vpc.vpc.id
64+
}
65+
66+
resource "volcengine_security_group_rule" "allow_all_tcp" {
67+
direction = "ingress"
68+
security_group_id = volcengine_security_group.group.id
69+
protocol = "tcp"
70+
port_start = 1
71+
port_end = 65535
72+
cidr_ip = "0.0.0.0/0"
73+
depends_on = [
74+
volcengine_security_group.group
75+
]
76+
}
77+
78+
resource "volcengine_vpc" "vpc" {
79+
vpc_name = "volcengine_vpc"
80+
cidr_block = "172.16.0.0/16"
81+
}
82+
83+
resource "volcengine_subnet" "subnet" {
84+
subnet_name = "volcengine_subnet"
85+
cidr_block = "172.16.0.0/24"
86+
zone_id = data.volcengine_zones.default.zones[0].id
87+
vpc_id = volcengine_vpc.vpc.id
88+
}
89+
90+
data "volcengine_zones" "default" {
91+
}
92+
93+
data "volcengine_images" "debian" {
94+
os_type = "Linux"
95+
visibility = "public"
96+
instance_type_id = "ecs.e-c1m1.large"
97+
name_regex = "Debian 12"
98+
}

volcengine/ecs/outputs.tf

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
output "ecs_ip" {
2+
value = volcengine_eip_address.eip.eip_address
3+
description = "ECS public IP address"
4+
}
5+
6+
output "ecs_password" {
7+
value = nonsensitive(random_password.password.result)
8+
description = "ECS SSH password"
9+
}

volcengine/ecs/versions.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
terraform {
2+
required_providers {
3+
volcengine = {
4+
source = "volcengine/volcengine"
5+
version = "0.0.159"
6+
}
7+
random = {
8+
source = "hashicorp/random"
9+
version = "~> 3.0"
10+
}
11+
}
12+
}
13+
14+
provider "volcengine" {
15+
region = "cn-beijing"
16+
# access_key and secret_key can be provided via environment variables:
17+
# VOLCENGINE_ACCESS_KEY and VOLCENGINE_SECRET_KEY
18+
}

0 commit comments

Comments
 (0)