Skip to content

Commit 784ba3e

Browse files
author
瑶喜
committed
add ecs-deploy-deepsite-application solution
1 parent 06d0e3a commit 784ba3e

File tree

4 files changed

+270
-0
lines changed

4 files changed

+270
-0
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于在阿里云上创建一台ECS实例并部署DeepSite应用,涉及到专有网络VPC、虚拟交换机vSwitch、安全组等资源的创建和部署。
5+
<!-- DOCS_DESCRIPTION_CN -->
6+
7+
<!-- DOCS_DESCRIPTION_EN -->
8+
This example is used to create an ECS instance on Alibaba Cloud and deploy DeepSite applications, involving the creation and deployment of proprietary network VPC, virtual switch vSwitch, security group and other resources.
9+
<!-- DOCS_DESCRIPTION_EN -->
10+
11+
<!-- BEGIN_TF_DOCS -->
12+
## Providers
13+
14+
| Name | Version |
15+
|------|---------|
16+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
17+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
18+
19+
## Modules
20+
21+
No modules.
22+
23+
## Resources
24+
25+
| Name | Type |
26+
|------|------|
27+
| [alicloud_ecs_command.install_app](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ecs_command) | resource |
28+
| [alicloud_ecs_invocation.run_install](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ecs_invocation) | resource |
29+
| [alicloud_instance.ecs_instance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/instance) | resource |
30+
| [alicloud_security_group.security_group](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group) | resource |
31+
| [alicloud_security_group_rule.allow_tcp_443](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
32+
| [alicloud_security_group_rule.allow_tcp_80](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
33+
| [alicloud_security_group_rule.allow_tcp_8080](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
34+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
35+
| [alicloud_vswitch.vswitch](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
36+
| [random_id.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) | resource |
37+
| [alicloud_regions.current](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/regions) | data source |
38+
39+
## Inputs
40+
41+
| Name | Description | Type | Default | Required |
42+
|------|-------------|------|---------|:--------:|
43+
| <a name="input_ecs_instance_password"></a> [ecs\_instance\_password](#input\_ecs\_instance\_password) | {<br/> "Label": {<br/> "en": "Instance Password",<br/> "zh-cn": "实例密码"<br/> },<br/> "Description": {<br/> "en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",<br/> "zh-cn": "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()\`~!@#$%^&*\_-+=\|{}[]:;'<>,.?/ 中的特殊符号)"<br/> },<br/> "ConstraintDescription": {<br/> "en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",<br/> "zh-cn": "长度8-30,必须包含三项(大写字母、小写字母、数字、 ()\`~!@#$%^&*\_-+=\|{}[]:;'<>,.?/ 中的特殊符号)"<br/> },<br/> "AssociationProperty": "ALIYUN::ECS::Instance::Password"<br/> } | `string` | n/a | yes |
44+
| <a name="input_instance_type"></a> [instance\_type](#input\_instance\_type) | {<br/> "Label": {<br/> "en": "Instance Type",<br/> "zh-cn": "实例类型"<br/> },<br/> "AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",<br/> "AssociationPropertyMetadata": {<br/> "ZoneId": "${zone\_id}",<br/> "InstanceChargeType": "PostPaid",<br/> "SystemDiskCategory": "cloud\_essd\_entry",<br/> "Constraints": {<br/> "Architecture": ["X86"],<br/> "vCPU": [2],<br/> "Memory": [4]<br/> }<br/> },<br/> "Description": {<br/> "zh-cn": "推荐规格:ecs.e-c1m2.large(2 vCPU 4 GiB)",<br/> "en": "Recommended: ecs.e-c1m2.large (2 vCPU 4 GiB)"<br/> }<br/> } | `string` | `"ecs.e-c1m2.large"` | no |
45+
| <a name="input_zone_id"></a> [zone\_id](#input\_zone\_id) | {<br/> "Label": {<br/> "en": "Availability Zone",<br/> "zh-cn": "可用区"<br/> },<br/> "AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",<br/> "AssociationPropertyMetadata": {<br/> "RegionId": "cn-shanghai",<br/> "AutoSelectFirst": true<br/> }<br/> } | `string` | `"cn-shanghai-b"` | no |
46+
<!-- END_TF_DOCS -->
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
provider "alicloud" {
2+
region = "cn-shanghai"
3+
}
4+
5+
resource "random_id" "suffix" {
6+
byte_length = 8
7+
}
8+
9+
locals {
10+
common_name = "deepsite-ai-${random_id.suffix.hex}"
11+
}
12+
13+
# VPC资源
14+
resource "alicloud_vpc" "vpc" {
15+
cidr_block = "192.168.0.0/16"
16+
vpc_name = "${local.common_name}-vpc"
17+
}
18+
19+
# 交换机资源
20+
resource "alicloud_vswitch" "vswitch" {
21+
vpc_id = alicloud_vpc.vpc.id
22+
cidr_block = "192.168.0.0/24"
23+
zone_id = var.zone_id
24+
vswitch_name = "${local.common_name}-vsw"
25+
}
26+
27+
# 安全组资源
28+
resource "alicloud_security_group" "security_group" {
29+
vpc_id = alicloud_vpc.vpc.id
30+
security_group_name = "${local.common_name}-sg"
31+
}
32+
33+
# 安全组入站规则(允许 TCP 8080 端口 - DeepSite 应用访问端口)
34+
resource "alicloud_security_group_rule" "allow_tcp_8080" {
35+
type = "ingress"
36+
ip_protocol = "tcp"
37+
nic_type = "intranet"
38+
policy = "accept"
39+
port_range = "8080/8080"
40+
priority = 1
41+
security_group_id = alicloud_security_group.security_group.id
42+
cidr_ip = "192.168.0.0/24"
43+
# 如需允许从公网访问ECS,请将cidr_ip修改为0.0.0.0/0
44+
# cidr_ip = "0.0.0.0/0"
45+
}
46+
47+
# 安全组入站规则(允许 TCP 80 端口 - 可选,用于 Nginx 部署生成的网页)
48+
resource "alicloud_security_group_rule" "allow_tcp_80" {
49+
type = "ingress"
50+
ip_protocol = "tcp"
51+
nic_type = "intranet"
52+
policy = "accept"
53+
port_range = "80/80"
54+
priority = 1
55+
security_group_id = alicloud_security_group.security_group.id
56+
cidr_ip = "192.168.0.0/24"
57+
# 如需允许从公网访问ECS,请将cidr_ip修改为0.0.0.0/0
58+
# cidr_ip = "0.0.0.0/0"
59+
}
60+
61+
# 安全组入站规则(允许 TCP 443 端口 - 可选,用于 HTTPS 访问)
62+
resource "alicloud_security_group_rule" "allow_tcp_443" {
63+
type = "ingress"
64+
ip_protocol = "tcp"
65+
nic_type = "intranet"
66+
policy = "accept"
67+
port_range = "443/443"
68+
priority = 1
69+
security_group_id = alicloud_security_group.security_group.id
70+
cidr_ip = "192.168.0.0/24"
71+
# 如需允许从公网访问ECS,请将cidr_ip修改为0.0.0.0/0
72+
# cidr_ip = "0.0.0.0/0"
73+
}
74+
75+
# ECS实例资源
76+
resource "alicloud_instance" "ecs_instance" {
77+
instance_name = "${local.common_name}-ecs"
78+
system_disk_category = "cloud_essd_entry"
79+
image_id = "aliyun_3_x64_20G_alibase_20251030.vhd"
80+
vswitch_id = alicloud_vswitch.vswitch.id
81+
password = var.ecs_instance_password
82+
instance_type = var.instance_type
83+
internet_max_bandwidth_out = 5
84+
security_groups = [alicloud_security_group.security_group.id]
85+
}
86+
87+
# ECS命令资源 - 安装 DeepSite 应用脚本
88+
resource "alicloud_ecs_command" "install_app" {
89+
name = "install-deepsite-app"
90+
command_content = base64encode(<<EOF
91+
#!/bin/bash
92+
# 执行 DeepSite 安装脚本
93+
curl -fsSL https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251217/rilwsn/install.sh|bash
94+
EOF
95+
)
96+
working_dir = "/root"
97+
type = "RunShellScript"
98+
timeout = 3600
99+
}
100+
101+
# 调用命令资源
102+
resource "alicloud_ecs_invocation" "run_install" {
103+
instance_id = [alicloud_instance.ecs_instance.id]
104+
command_id = alicloud_ecs_command.install_app.id
105+
timeouts {
106+
create = "60m"
107+
}
108+
}
109+
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
output "ecs_login_address" {
2+
description = <<EOT
3+
{
4+
"Label": {
5+
"zh-cn": "ECS登录地址",
6+
"en": "ECS Login Address"
7+
},
8+
"zh-cn": "ECS登录地址,可通过此地址远程连接到云服务器。",
9+
"en": "ECS login address for remote connection."
10+
}
11+
EOT
12+
value = "https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs&regionId=${data.alicloud_regions.current.regions.0.id}&instanceId=${alicloud_instance.ecs_instance.id}"
13+
}
14+
15+
output "deepsite_url" {
16+
description = <<EOT
17+
{
18+
"Label": {
19+
"zh-cn": "DeepSite 体验地址",
20+
"en": "DeepSite Experience URL"
21+
},
22+
"zh-cn": "DeepSite 应用访问地址,部署完成后可通过此地址体验 AI 网页生成功能。",
23+
"en": "DeepSite application URL for AI-powered web page generation."
24+
}
25+
EOT
26+
value = "http://${alicloud_instance.ecs_instance.public_ip}:8080"
27+
}
28+
29+
output "ecs_public_ip" {
30+
description = <<EOT
31+
{
32+
"Label": {
33+
"zh-cn": "ECS公网IP",
34+
"en": "ECS Public IP"
35+
},
36+
"zh-cn": "云服务器的公网IP地址。",
37+
"en": "Public IP address of the ECS instance."
38+
}
39+
EOT
40+
value = alicloud_instance.ecs_instance.public_ip
41+
}
42+
43+
// 数据源获取当前地域
44+
data "alicloud_regions" "current" {
45+
current = true
46+
}
47+
Lines changed: 68 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
variable "zone_id" {
2+
type = string
3+
default = "cn-shanghai-b"
4+
description = <<EOT
5+
{
6+
"Label": {
7+
"en": "Availability Zone",
8+
"zh-cn": "可用区"
9+
},
10+
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
11+
"AssociationPropertyMetadata": {
12+
"RegionId": "cn-shanghai",
13+
"AutoSelectFirst": true
14+
}
15+
}
16+
EOT
17+
}
18+
19+
variable "instance_type" {
20+
type = string
21+
default = "ecs.e-c1m2.large"
22+
description = <<EOT
23+
{
24+
"Label": {
25+
"en": "Instance Type",
26+
"zh-cn": "实例类型"
27+
},
28+
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
29+
"AssociationPropertyMetadata": {
30+
"ZoneId": "$${zone_id}",
31+
"InstanceChargeType": "PostPaid",
32+
"SystemDiskCategory": "cloud_essd_entry",
33+
"Constraints": {
34+
"Architecture": ["X86"],
35+
"vCPU": [2],
36+
"Memory": [4]
37+
}
38+
},
39+
"Description": {
40+
"zh-cn": "推荐规格:ecs.e-c1m2.large(2 vCPU 4 GiB)",
41+
"en": "Recommended: ecs.e-c1m2.large (2 vCPU 4 GiB)"
42+
}
43+
}
44+
EOT
45+
}
46+
47+
variable "ecs_instance_password" {
48+
type = string
49+
sensitive = true
50+
description = <<EOT
51+
{
52+
"Label": {
53+
"en": "Instance Password",
54+
"zh-cn": "实例密码"
55+
},
56+
"Description": {
57+
"en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
58+
"zh-cn": "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
59+
},
60+
"ConstraintDescription": {
61+
"en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
62+
"zh-cn": "长度8-30,必须包含三项(大写字母、小写字母、数字、 ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
63+
},
64+
"AssociationProperty": "ALIYUN::ECS::Instance::Password"
65+
}
66+
EOT
67+
}
68+

0 commit comments

Comments
 (0)