Skip to content

Commit f652e0c

Browse files
committed
rocketmq-for-multi-agent-communication
1 parent 300e8e2 commit f652e0c

File tree

4 files changed

+153
-0
lines changed

4 files changed

+153
-0
lines changed
Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于实现解决方案[通过RocketMQ实现多智能体异步通信](https://www.aliyun.com/solution/tech-solution-deploy/2990228), 涉及到专有网络(VPC)、交换机(VSwitch)、云服务器(ECS)等资源的创建。
5+
<!-- DOCS_DESCRIPTION_CN -->
6+
7+
<!-- DOCS_DESCRIPTION_EN -->
8+
This example is used to implement solution [rocketmq-for-multi-agent-communication](https://www.aliyun.com/solution/tech-solution-deploy/2990228). It involves the creation, and deployment of resources such as Virtual Private Cloud (VPC), VSwitch, Elastic Compute Service (ECS).
9+
<!-- DOCS_DESCRIPTION_EN -->
10+
11+
12+
<!-- BEGIN_TF_DOCS -->
13+
## Providers
14+
15+
| Name | Version |
16+
|------|---------|
17+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
18+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
19+
20+
## Modules
21+
22+
No modules.
23+
24+
## Resources
25+
26+
| Name | Type |
27+
|------|------|
28+
| [alicloud_instance.ecs_instance](https://registry.terraform.io/providers/hashicorp/alicloud/latest/docs/resources/instance) | resource |
29+
| [alicloud_security_group.security_group](https://registry.terraform.io/providers/hashicorp/alicloud/latest/docs/resources/security_group) | resource |
30+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/hashicorp/alicloud/latest/docs/resources/vpc) | resource |
31+
| [alicloud_vswitch.ecs_vswitch](https://registry.terraform.io/providers/hashicorp/alicloud/latest/docs/resources/vswitch) | resource |
32+
| [random_string.suffix](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | resource |
33+
| [alicloud_images.default](https://registry.terraform.io/providers/hashicorp/alicloud/latest/docs/data-sources/images) | data source |
34+
| [alicloud_regions.current_region_ds](https://registry.terraform.io/providers/hashicorp/alicloud/latest/docs/data-sources/regions) | data source |
35+
| [alicloud_zones.ecs_zones](https://registry.terraform.io/providers/hashicorp/alicloud/latest/docs/data-sources/zones) | data source |
36+
37+
## Inputs
38+
39+
| Name | Description | Type | Default | Required |
40+
|------|-------------|------|---------|:--------:|
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_ecs_instance_type"></a> [ecs\_instance\_type](#input\_ecs\_instance\_type) | ECS实例规格 | `string` | `"ecs.t6-c1m2.large"` | no |
43+
<!-- END_TF_DOCS -->
Lines changed: 77 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,77 @@
1+
# ------------------------------------------------------------------------------
2+
# 核心资源定义 (Main Resource Definitions)
3+
#
4+
# 本文件包含了模块的核心基础设施资源。
5+
# 这里的代码负责根据输入变量来创建和配置所有云资源。
6+
# ------------------------------------------------------------------------------
7+
8+
# 配置阿里云提供商 (Provider)
9+
provider "alicloud" {
10+
region = "cn-chengdu"
11+
}
12+
13+
# 查询当前部署地域
14+
data "alicloud_regions" "current_region_ds" {
15+
current = true
16+
}
17+
18+
# 查询支持指定ECS实例规格和磁盘类型的可用区
19+
data "alicloud_zones" "ecs_zones" {
20+
available_disk_category = "cloud_essd"
21+
available_resource_creation = "VSwitch"
22+
available_instance_type = var.ecs_instance_type
23+
}
24+
25+
# 创建一个随机ID,用于生成唯一的资源名称后缀,避免命名冲突
26+
resource "random_string" "suffix" {
27+
length = 8
28+
lower = true
29+
upper = false
30+
numeric = false
31+
special = false
32+
}
33+
34+
# 定义一个局部变量,将随机ID用作通用名称后缀
35+
locals {
36+
common_name = random_string.suffix.id
37+
region = data.alicloud_regions.current_region_ds.regions.0.id
38+
}
39+
40+
# 创建一个专有网络(VPC),为云资源提供一个隔离的网络环境
41+
resource "alicloud_vpc" "vpc" {
42+
cidr_block = "192.168.0.0/16"
43+
vpc_name = "vpc-${local.common_name}"
44+
}
45+
46+
# 创建一个交换机(VSwitch),用于在VPC内划分一个子网
47+
resource "alicloud_vswitch" "ecs_vswitch" {
48+
vpc_id = alicloud_vpc.vpc.id
49+
cidr_block = "192.168.1.0/24"
50+
zone_id = data.alicloud_zones.ecs_zones.zones[0].id
51+
vswitch_name = "ecs-vswitch-${local.common_name}"
52+
}
53+
54+
# 创建一个安全组,作为虚拟防火墙来控制ECS实例的网络访问
55+
resource "alicloud_security_group" "security_group" {
56+
vpc_id = alicloud_vpc.vpc.id
57+
security_group_name = "sg-${local.common_name}"
58+
}
59+
60+
# 查询可用的阿里云镜像
61+
data "alicloud_images" "default" {
62+
name_regex = "^aliyun_3_x64_20G_alibase_.*"
63+
most_recent = true
64+
owners = "system"
65+
}
66+
67+
# 创建一台ECS实例(云服务器)
68+
resource "alicloud_instance" "ecs_instance" {
69+
instance_name = "ecs-${local.common_name}"
70+
image_id = data.alicloud_images.default.images[0].id
71+
instance_type = var.ecs_instance_type
72+
system_disk_category = "cloud_essd"
73+
security_groups = [alicloud_security_group.security_group.id]
74+
vswitch_id = alicloud_vswitch.ecs_vswitch.id
75+
password = var.ecs_instance_password
76+
internet_max_bandwidth_out = 5
77+
}
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# ------------------------------------------------------------------------------
2+
# 模块输出值 (Module Outputs)
3+
#
4+
# 本文件定义了模块执行成功后返回给调用方的值。
5+
# 这些输出可以被其他 Terraform 配置引用,或在 apply 命令结束后显示给用户。
6+
# ------------------------------------------------------------------------------
7+
8+
output "ecs_login_address" {
9+
description = "部署应用的ECS实例的登录地址。"
10+
value = format("https://ecs-workbench.aliyun.com/?from=ecs&instanceType=ecs&regionId=%s&instanceId=%s&resourceGroupId=", local.region, alicloud_instance.ecs_instance.id)
11+
}
Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
# ------------------------------------------------------------------------------
2+
# 模块输入变量 (Module Input Variables)
3+
#
4+
# 本文件定义了该 Terraform 模块所有可配置的输入变量。
5+
# 每个变量都包含了详细的 'description',以说明其用途、格式和默认值逻辑。
6+
# 请参考这些描述来正确配置模块。
7+
# ------------------------------------------------------------------------------
8+
9+
# 指定创建的ECS云服务器的规格。
10+
variable "ecs_instance_type" {
11+
type = string
12+
default = "ecs.t6-c1m2.large"
13+
description = "ECS实例规格"
14+
}
15+
16+
# 用于登录ECS实例的密码。
17+
variable "ecs_instance_password" {
18+
type = string
19+
sensitive = true
20+
description = "服务器登录密码,长度8-30,必须包含三项(大写字母、小写字母、数字、 ()`~!@#$%^&*_-+=|{}[]:;'<>,.?/ 中的特殊符号)"
21+
# default = ""
22+
}

0 commit comments

Comments
 (0)