Skip to content

Commit 8c5b50f

Browse files
committed
feat: 解决方案build-enterprise-web-with-mobi tf文件完成
1 parent 7233118 commit 8c5b50f

File tree

5 files changed

+201
-0
lines changed

5 files changed

+201
-0
lines changed
Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
## Introduction
2+
<!-- DOCS_DESCRIPTION_CN -->
3+
本示例用于实现解决方案[低代码高效构建企业门户网站](https://www.aliyun.com/solution/tech-solution/build-a-website), 涉及到专有网络(VPC)、交换机(VSwitch)、云数据库RDS、多端低代码开发平台魔笔、资源编排(ROS)。
4+
<!-- DOCS_DESCRIPTION_CN -->
5+
6+
<!-- DOCS_DESCRIPTION_EN -->
7+
This example demonstrates the implementation of the solution [Low-code Efficient Construction Of Enterprise Portal Websites](https://www.aliyun.com/solution/tech-solution/build-a-website). It involves the creation, configuration, and deployment of resources such as Virtual Private Cloud (Vpc), Virtual Switch (VSwitch), Elastic Compute Service (Ecs), Multi-terminal low-code development platform Mobi, Resource Orchestration Service (ROS).
8+
<!-- DOCS_DESCRIPTION_EN -->
9+
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_db_connection.rds_connection](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_connection) | resource |
28+
| [alicloud_db_database.rds_database](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_database) | resource |
29+
| [alicloud_db_instance.rds_instance](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/db_instance) | resource |
30+
| [alicloud_rds_account.create_db_user](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/rds_account) | resource |
31+
| [alicloud_ros_stack.mobi_stack](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/ros_stack) | resource |
32+
| [alicloud_vpc.vpc](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vpc) | resource |
33+
| [alicloud_vswitch.vswitch_1](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/vswitch) | resource |
34+
| [random_integer.app_name_random](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) | resource |
35+
| [alicloud_db_instance_classes.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/db_instance_classes) | data source |
36+
| [alicloud_db_zones.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/db_zones) | data source |
37+
38+
## Inputs
39+
40+
| Name | Description | Type | Default | Required |
41+
|------|-------------|------|---------|:--------:|
42+
| <a name="input_app_name"></a> [app\_name](#input\_app\_name) | APP名称 | `string` | `"mobi_app"` | no |
43+
| <a name="input_db_name"></a> [db\_name](#input\_db\_name) | 数据库名 | `string` | `"db_name"` | no |
44+
| <a name="input_db_password"></a> [db\_password](#input\_db\_password) | 数据库密码 | `string` | n/a | yes |
45+
| <a name="input_db_user_name"></a> [db\_user\_name](#input\_db\_user\_name) | 数据库用户名 | `string` | `"db_user"` | no |
46+
| <a name="input_region"></a> [region](#input\_region) | 地域 | `string` | `"cn-hangzhou"` | no |
47+
<!-- END_TF_DOCS -->
Lines changed: 118 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,118 @@
1+
# 查询RDS支持的可用区
2+
data "alicloud_db_zones" "default" {
3+
engine = "MySQL"
4+
engine_version = "8.0"
5+
instance_charge_type = "PostPaid"
6+
category = "Basic"
7+
db_instance_storage_type = "cloud_essd"
8+
}
9+
10+
locals {
11+
# 获取最后一个可用区
12+
zone_id = data.alicloud_db_zones.default.ids[length(data.alicloud_db_zones.default.ids) - 1]
13+
}
14+
15+
# 查询实例规格
16+
data "alicloud_db_instance_classes" "default" {
17+
instance_charge_type = "PostPaid"
18+
engine = "MySQL"
19+
engine_version = "8.0"
20+
db_instance_storage_type = "cloud_essd"
21+
category = "Basic"
22+
zone_id = local.zone_id
23+
}
24+
25+
# VPC资源定义
26+
resource "alicloud_vpc" "vpc" {
27+
vpc_name = "${var.app_name}-vpc"
28+
cidr_block = "192.168.0.0/16"
29+
}
30+
31+
# VSwitch资源定义
32+
resource "alicloud_vswitch" "vswitch_1" {
33+
zone_id = local.zone_id
34+
vpc_id = alicloud_vpc.vpc.id
35+
cidr_block = "192.168.1.0/24"
36+
vswitch_name = "${var.app_name}-vsw"
37+
}
38+
39+
# RDS实例定义
40+
resource "alicloud_db_instance" "rds_instance" {
41+
engine = "MySQL"
42+
engine_version = "8.0"
43+
instance_type = data.alicloud_db_instance_classes.default.ids.0
44+
instance_storage = 40
45+
vpc_id = alicloud_vpc.vpc.id
46+
vswitch_id = alicloud_vswitch.vswitch_1.id
47+
security_ips = [alicloud_vpc.vpc.cidr_block, "101.200.211.106"]
48+
}
49+
50+
# RDS数据库定义
51+
resource "alicloud_db_database" "rds_database" {
52+
name = var.db_name
53+
description = "database for mobi app"
54+
instance_id = alicloud_db_instance.rds_instance.id
55+
character_set = "utf8mb4"
56+
}
57+
58+
# RDS账号定义
59+
resource "alicloud_rds_account" "create_db_user" {
60+
db_instance_id = alicloud_db_instance.rds_instance.id
61+
account_name = var.db_user_name
62+
account_password = var.db_password
63+
account_type = "Super"
64+
}
65+
66+
resource "random_integer" "app_name_random" {
67+
min = 10000
68+
max = 99999
69+
}
70+
71+
resource "alicloud_db_connection" "rds_connection" {
72+
depends_on = [alicloud_rds_account.create_db_user]
73+
instance_id = alicloud_db_instance.rds_instance.id
74+
connection_prefix = "mobiapp${random_integer.app_name_random.result}"
75+
}
76+
77+
# ROS Stack定义
78+
resource "alicloud_ros_stack" "mobi_stack" {
79+
depends_on = [alicloud_db_connection.rds_connection]
80+
stack_name = "mobi-app-stack-${random_integer.app_name_random.result}"
81+
template_body = local.mobi_stack_json
82+
}
83+
84+
locals {
85+
mobi_stack_json = <<-JSON
86+
{
87+
"ROSTemplateFormatVersion": "2015-09-01",
88+
"Resources": {
89+
"MobiWorkspaces": {
90+
"Type": "DATASOURCE::MOBI::Workspaces"
91+
},
92+
"Mobi": {
93+
"Type": "ALIYUN::MOBI::App",
94+
"Properties": {
95+
"AppName": "test_${random_integer.app_name_random.result}",
96+
"AppIcon": -1,
97+
"AppWorkspaceId": {
98+
"Fn::Select": [
99+
0,
100+
{
101+
"Fn::GetAtt": [
102+
"MobiWorkspaces",
103+
"WorkspaceIds"
104+
]
105+
}
106+
]
107+
},
108+
"AppType": "Web",
109+
"Template": {
110+
"TemplateId": "e1e78223-38c4-4184-972c-ac0eead93e11",
111+
"ConnectionsContent": "[{\n \"name\": \"企业官网模板_${random_integer.app_name_random.result}\",\n \"connectorType\": {\n \"kind\": \"mysql\",\n \"name\": \"mysql\"\n },\n \"folderId\": \"/\",\n \"resourceRequirementId\": \"7dfe969b-1d54-4cbc-a8fd-209000b30ad0\",\n \"resourceObject\": {\n \"version\": \"1.0\",\n \"id\": \"7dfe969b-1d54-4cbc-a8fd-209000b30ad0\",\n \"name\": \"企业官网模板_20241203160633\",\n \"type\": \"sql\",\n \"subType\": \"mysql\",\n \"connectionTemplates\": {\n \"dev\": {\n \"host\": \"${alicloud_db_connection.rds_connection.connection_string}\",\n \"port\": 3306,\n \"database\": \"${var.db_name}\",\n \"username\": \"${var.db_user_name}\",\n \"password\": \"${var.db_password}\"\n },\n \"product\": {\n \"host\": \"${alicloud_db_connection.rds_connection.connection_string}\",\n \"port\": 3306,\n \"database\": \"${var.db_name}\",\n \"username\": \"${var.db_user_name}\",\n \"password\": \"${var.db_password}\"\n }\n }\n }\n}]"
112+
}
113+
}
114+
}
115+
}
116+
}
117+
JSON
118+
}
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
output "mobi_url" {
2+
description = "魔笔控制台地址"
3+
value = "https://mobinext.console.aliyun.com/"
4+
}
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
provider "alicloud" {
2+
region = var.region
3+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
variable "region" {
2+
description = "地域"
3+
type = string
4+
default = "cn-hangzhou"
5+
}
6+
7+
variable "app_name" {
8+
type = string
9+
description = "APP名称"
10+
default = "mobi_app"
11+
}
12+
13+
variable "db_user_name" {
14+
type = string
15+
description = "数据库用户名"
16+
default = "db_user"
17+
}
18+
19+
variable "db_password" {
20+
type = string
21+
description = "数据库密码"
22+
sensitive = true
23+
}
24+
25+
variable "db_name" {
26+
type = string
27+
description = "数据库名"
28+
default = "db_name"
29+
}

0 commit comments

Comments
 (0)