Skip to content

Commit 57bae96

Browse files
qihou0812shanye997
authored andcommitted
feat: add build-ai-applications-based-on-alibaba-cloud-model-studio solution
- Add Terraform configuration for AI applications based on Alibaba Cloud Model Studio - Include VPC, VSwitch, ECS resources with security group configuration - Add BaiLian API integration for AI model deployment - Provide comprehensive variable definitions and outputs - Optimize variable and output descriptions for better readability
1 parent 04ec6c0 commit 57bae96

File tree

4 files changed

+174
-0
lines changed

4 files changed

+174
-0
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于实现解决方案[高效搭建 AI 智能体与工作流应用](https://www.aliyun.com/solution/tech-solution/build-ai-applications-based-on-alibaba-cloud-model-studio), 涉及到 专有网络(VPC)、交换机(VSwitch)、云服务器(ECS) 等资源的创建。
5+
<!-- DOCS_DESCRIPTION_CN -->
6+
7+
<!-- DOCS_DESCRIPTION_EN -->
8+
This example is used to implement solution [Efficiently build AI agents and workflow applications](https://www.aliyun.com/solution/tech-solution/build-ai-applications-based-on-alibaba-cloud-model-studio), which involves the creation and deployment of resources such as Virtual Private Cloud (VPC), VSwitch, Elastic Compute Service (ECS).
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+
18+
## Modules
19+
20+
No modules.
21+
22+
## Resources
23+
24+
| Name | Type |
25+
|------|------|
26+
| [alicloud_ecs_command.run_script](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ecs_command) | resource |
27+
| [alicloud_ecs_invocation.run_command](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ecs_invocation) | resource |
28+
| [alicloud_instance.ecs_instance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/instance) | resource |
29+
| [alicloud_security_group.security_group](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group) | resource |
30+
| [alicloud_security_group_rule.allow_http](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/security_group_rule) | resource |
31+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
32+
| [alicloud_vswitch.vswitch](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
33+
| [alicloud_regions.current](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/regions) | data source |
34+
35+
## Inputs
36+
37+
| Name | Description | Type | Default | Required |
38+
|------|-------------|------|---------|:--------:|
39+
| <a name="input_bai_lian_api_key"></a> [bai\_lian\_api\_key](#input\_bai\_lian\_api\_key) | 百炼 API-KEY,需开通百炼模型服务再获取 API-KEY,详情请参考:https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key | `string` | n/a | yes |
40+
| <a name="input_common_name"></a> [common\_name](#input\_common\_name) | Common name prefix for resources | `string` | `"BaiLian"` | no |
41+
| <a name="input_ecs_instance_password"></a> [ecs\_instance\_password](#input\_ecs\_instance\_password) | 服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)` | `string` | n/a | yes |
42+
| <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/> "InstanceChargeType": "PostPaid",<br/> "SystemDiskCategory": "cloud\_essd"<br/> }<br/> } | `string` | `"ecs.e-c1m2.large"` | no |
43+
| <a name="input_region"></a> [region](#input\_region) | 地域,例如:cn-hangzhou。所有地域及可用区请参见文档:https://help.aliyun.com/document_detail/40654.html#09f1dc16b0uke | `string` | `"cn-hangzhou"` | no |
44+
| <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/> } | `string` | `"cn-hangzhou-h"` | no |
45+
<!-- END_TF_DOCS -->
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
provider "alicloud" {
2+
region = var.region
3+
}
4+
5+
// VPC Resource
6+
resource "alicloud_vpc" "vpc" {
7+
cidr_block = "192.168.0.0/16"
8+
vpc_name = "${var.common_name}-VPC"
9+
}
10+
11+
// VSwitch Resource
12+
resource "alicloud_vswitch" "vswitch" {
13+
vpc_id = alicloud_vpc.vpc.id
14+
cidr_block = "192.168.0.0/24"
15+
zone_id = var.zone_id
16+
vswitch_name = "${var.common_name}-vsw_001"
17+
}
18+
19+
// Security Group Resource
20+
resource "alicloud_security_group" "security_group" {
21+
vpc_id = alicloud_vpc.vpc.id
22+
security_group_name = "${var.common_name}-SecurityGroup_1"
23+
}
24+
25+
// Security Group Rule for HTTP access
26+
resource "alicloud_security_group_rule" "allow_http" {
27+
type = "ingress"
28+
ip_protocol = "tcp"
29+
nic_type = "intranet"
30+
policy = "accept"
31+
port_range = "80/80"
32+
priority = 1
33+
security_group_id = alicloud_security_group.security_group.id
34+
cidr_ip = "0.0.0.0/0"
35+
}
36+
37+
// ECS Instance Resource
38+
resource "alicloud_instance" "ecs_instance" {
39+
vpc_id = alicloud_vpc.vpc.id
40+
vswitch_id = alicloud_vswitch.vswitch.id
41+
security_groups = [alicloud_security_group.security_group.id]
42+
image_id = "aliyun_3_9_x64_20G_alibase_20231219.vhd"
43+
instance_type = var.instance_type
44+
system_disk_category = "cloud_essd"
45+
system_disk_size = 40
46+
internet_max_bandwidth_out = 5
47+
password = var.ecs_instance_password
48+
}
49+
50+
// Run Command on ECS Instance
51+
resource "alicloud_ecs_command" "run_script" {
52+
name = "setup-bailian-app"
53+
command_content = base64encode(<<SCRIPT
54+
#!/bin/bash
55+
cat << "PROFILE_EOF" >> ~/.bash_profile
56+
export BAILIAN_API_KEY=${var.bai_lian_api_key}
57+
export ROS_DEPLOY=true
58+
PROFILE_EOF
59+
60+
source ~/.bash_profile
61+
62+
curl -fsSL https://static-aliyun-doc.oss-cn-hangzhou.aliyuncs.com/install-script/create-ai-app-via-bailian/install.sh | bash
63+
SCRIPT
64+
)
65+
working_dir = "/root"
66+
type = "RunShellScript"
67+
timeout = 3600
68+
}
69+
70+
resource "alicloud_ecs_invocation" "run_command" {
71+
instance_id = [alicloud_instance.ecs_instance.id]
72+
command_id = alicloud_ecs_command.run_script.id
73+
timeouts {
74+
create = "15m"
75+
}
76+
}
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
output "web_url" {
2+
description = "Web访问地址"
3+
value = "http://${alicloud_instance.ecs_instance.public_ip}"
4+
}
5+
6+
output "ecs_login_address" {
7+
description = "ECS登录地址"
8+
value = "https://ecs-workbench.aliyun.com/?from=EcsConsole&instanceType=ecs&regionId=${data.alicloud_regions.current.regions.0.id}&instanceId=${alicloud_instance.ecs_instance.id}"
9+
}
10+
11+
// Data source to get current region
12+
data "alicloud_regions" "current" {
13+
current = true
14+
}
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
variable "region" {
2+
type = string
3+
default = "cn-hangzhou"
4+
description = "地域,例如:cn-hangzhou。所有地域及可用区请参见文档:https://help.aliyun.com/document_detail/40654.html#09f1dc16b0uke"
5+
}
6+
7+
variable "common_name" {
8+
type = string
9+
default = "BaiLian"
10+
description = "Common name prefix for resources"
11+
}
12+
13+
variable "bai_lian_api_key" {
14+
type = string
15+
description = "百炼 API-KEY,需开通百炼模型服务再获取 API-KEY,详情请参考:https://help.aliyun.com/zh/model-studio/developer-reference/get-api-key"
16+
}
17+
18+
variable "zone_id" {
19+
type = string
20+
default = "cn-hangzhou-h"
21+
description = "可用区ID"
22+
}
23+
24+
variable "instance_type" {
25+
type = string
26+
default = "ecs.e-c1m2.large"
27+
description = "ECS实例规格"
28+
}
29+
30+
variable "ecs_instance_password" {
31+
type = string
32+
sensitive = true
33+
description = "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
34+
35+
validation {
36+
condition = length(var.ecs_instance_password) >= 8 && length(var.ecs_instance_password) <= 30
37+
error_message = "密码长度必须在8-30位之间"
38+
}
39+
}

0 commit comments

Comments
 (0)