Skip to content

Commit 0d2103d

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

File tree

4 files changed

+263
-0
lines changed

4 files changed

+263
-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_instance_password"></a> [instance\_password](#input\_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-hangzhou",<br/> "AutoSelectFirst": true<br/> }<br/> } | `string` | n/a | yes |
46+
<!-- END_TF_DOCS -->
Lines changed: 103 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,103 @@
1+
provider "alicloud" {
2+
region = "cn-hangzhou"
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 = "0.0.0.0/0"
43+
}
44+
45+
# 安全组入站规则(允许 TCP 80 端口 - 可选,用于 Nginx 部署生成的网页)
46+
resource "alicloud_security_group_rule" "allow_tcp_80" {
47+
type = "ingress"
48+
ip_protocol = "tcp"
49+
nic_type = "intranet"
50+
policy = "accept"
51+
port_range = "80/80"
52+
priority = 1
53+
security_group_id = alicloud_security_group.security_group.id
54+
cidr_ip = "0.0.0.0/0"
55+
}
56+
57+
# 安全组入站规则(允许 TCP 443 端口 - 可选,用于 HTTPS 访问)
58+
resource "alicloud_security_group_rule" "allow_tcp_443" {
59+
type = "ingress"
60+
ip_protocol = "tcp"
61+
nic_type = "intranet"
62+
policy = "accept"
63+
port_range = "443/443"
64+
priority = 1
65+
security_group_id = alicloud_security_group.security_group.id
66+
cidr_ip = "0.0.0.0/0"
67+
}
68+
69+
# ECS实例资源
70+
resource "alicloud_instance" "ecs_instance" {
71+
instance_name = "${local.common_name}-ecs"
72+
system_disk_category = "cloud_essd_entry"
73+
image_id = "aliyun_3_x64_20G_alibase_20251030.vhd"
74+
vswitch_id = alicloud_vswitch.vswitch.id
75+
password = var.instance_password
76+
instance_type = var.instance_type
77+
internet_max_bandwidth_out = 5
78+
security_groups = [alicloud_security_group.security_group.id]
79+
}
80+
81+
# ECS命令资源 - 安装 DeepSite 应用脚本
82+
resource "alicloud_ecs_command" "install_app" {
83+
name = "install-deepsite-app"
84+
command_content = base64encode(<<EOF
85+
#!/bin/bash
86+
# 执行 DeepSite 安装脚本
87+
curl -fsSL https://help-static-aliyun-doc.aliyuncs.com/file-manage-files/zh-CN/20251217/rilwsn/install.sh|bash
88+
EOF
89+
)
90+
working_dir = "/root"
91+
type = "RunShellScript"
92+
timeout = 3600
93+
}
94+
95+
# 调用命令资源
96+
resource "alicloud_ecs_invocation" "run_install" {
97+
instance_id = [alicloud_instance.ecs_instance.id]
98+
command_id = alicloud_ecs_command.install_app.id
99+
timeouts {
100+
create = "60m"
101+
}
102+
}
103+
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: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
variable "zone_id" {
2+
type = string
3+
description = <<EOT
4+
{
5+
"Label": {
6+
"en": "Availability Zone",
7+
"zh-cn": "可用区"
8+
},
9+
"AssociationProperty": "ALIYUN::ECS::Instance::ZoneId",
10+
"AssociationPropertyMetadata": {
11+
"RegionId": "cn-hangzhou",
12+
"AutoSelectFirst": true
13+
}
14+
}
15+
EOT
16+
}
17+
18+
variable "instance_type" {
19+
type = string
20+
default = "ecs.e-c1m2.large"
21+
description = <<EOT
22+
{
23+
"Label": {
24+
"en": "Instance Type",
25+
"zh-cn": "实例类型"
26+
},
27+
"AssociationProperty": "ALIYUN::ECS::Instance::InstanceType",
28+
"AssociationPropertyMetadata": {
29+
"ZoneId": "$${zone_id}",
30+
"InstanceChargeType": "PostPaid",
31+
"SystemDiskCategory": "cloud_essd_entry",
32+
"Constraints": {
33+
"Architecture": ["X86"],
34+
"vCPU": [2],
35+
"Memory": [4]
36+
}
37+
},
38+
"Description": {
39+
"zh-cn": "推荐规格:ecs.e-c1m2.large(2 vCPU 4 GiB)",
40+
"en": "Recommended: ecs.e-c1m2.large (2 vCPU 4 GiB)"
41+
}
42+
}
43+
EOT
44+
}
45+
46+
variable "instance_password" {
47+
type = string
48+
sensitive = true
49+
description = <<EOT
50+
{
51+
"Label": {
52+
"en": "Instance Password",
53+
"zh-cn": "实例密码"
54+
},
55+
"Description": {
56+
"en": "Server login password, Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
57+
"zh-cn": "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
58+
},
59+
"ConstraintDescription": {
60+
"en": "Length 8-30, must contain three(Capital letters, lowercase letters, numbers, ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ Special symbol in)",
61+
"zh-cn": "长度8-30,必须包含三项(大写字母、小写字母、数字、 ()\`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
62+
},
63+
"AssociationProperty": "ALIYUN::ECS::Instance::Password"
64+
}
65+
EOT
66+
}
67+

0 commit comments

Comments
 (0)