Skip to content

Commit 997eb00

Browse files
lsy1968shanye997
authored andcommitted
201-use-case-manage-asm-instances
1 parent eb4ed97 commit 997eb00

File tree

3 files changed

+208
-0
lines changed

3 files changed

+208
-0
lines changed
Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,54 @@
1+
## Introduction
2+
3+
<!-- DOCS_DESCRIPTION_CN -->
4+
本示例用于在阿里云上创建ASM实例并为ASM实例添加集群。
5+
本示例来自[管理ASM实例](https://help.aliyun.com/document_detail/428242.html)
6+
<!-- DOCS_DESCRIPTION_CN -->
7+
8+
<!-- DOCS_DESCRIPTION_EN -->
9+
This example is used to manage ASM instances on Alibaba Cloud.
10+
This example is from [Manage ASM Instances](https://help.aliyun.com/document_detail/428242.html).
11+
<!-- DOCS_DESCRIPTION_EN -->
12+
13+
<!-- BEGIN_TF_DOCS -->
14+
## Providers
15+
16+
| Name | Version |
17+
|------|---------|
18+
| <a name="provider_alicloud"></a> [alicloud](#provider\_alicloud) | n/a |
19+
| <a name="provider_random"></a> [random](#provider\_random) | n/a |
20+
21+
## Modules
22+
23+
No modules.
24+
25+
## Resources
26+
27+
| Name | Type |
28+
|------|------|
29+
| [alicloud_cs_serverless_kubernetes.serverless](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/cs_serverless_kubernetes) | resource |
30+
| [alicloud_service_mesh_service_mesh.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/resources/service_mesh_service_mesh) | 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+
| [random_integer.default](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/integer) | resource |
34+
| [alicloud_service_mesh_versions.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/service_mesh_versions) | data source |
35+
| [alicloud_zones.default](https://registry.terraform.io/providers/aliyun/alicloud/latest/docs/data-sources/zones) | data source |
36+
37+
## Inputs
38+
39+
| Name | Description | Type | Default | Required |
40+
|------|-------------|------|---------|:--------:|
41+
| <a name="input_cluster_spec"></a> [cluster\_spec](#input\_cluster\_spec) | n/a | `string` | `"ack.pro.small"` | no |
42+
| <a name="input_kubernetes_version"></a> [kubernetes\_version](#input\_kubernetes\_version) | n/a | `string` | `"1.32.1-aliyun.1"` | no |
43+
| <a name="input_region"></a> [region](#input\_region) | n/a | `string` | `"cn-shanghai"` | no |
44+
| <a name="input_service_cidr"></a> [service\_cidr](#input\_service\_cidr) | n/a | `string` | `"192.16.0.0/19"` | no |
45+
| <a name="input_vpc_cidr_block"></a> [vpc\_cidr\_block](#input\_vpc\_cidr\_block) | n/a | `string` | `"172.16.0.0/22"` | no |
46+
| <a name="input_vsw_cidr_block"></a> [vsw\_cidr\_block](#input\_vsw\_cidr\_block) | n/a | `string` | `"172.16.0.0/24"` | no |
47+
<!-- END_TF_DOCS -->
48+
49+
## Documentation
50+
<!-- docs-link -->
51+
52+
The template is based on Aliyun document: [Manage ASM Instances](https://help.aliyun.com/document_detail/428242.html)
53+
54+
<!-- docs-link -->
Lines changed: 147 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,147 @@
1+
variable "region" {
2+
default = "cn-shanghai"
3+
}
4+
5+
variable "vpc_cidr_block" {
6+
default = "172.16.0.0/22"
7+
}
8+
9+
variable "vsw_cidr_block" {
10+
default = "172.16.0.0/24"
11+
}
12+
13+
variable "service_cidr" {
14+
default = "192.16.0.0/19"
15+
}
16+
17+
variable "kubernetes_version" {
18+
# 替换为您所需创建的集群版本。
19+
default = "1.32.1-aliyun.1"
20+
}
21+
22+
variable "cluster_spec" {
23+
# 替换为您所需创建的集群规格。
24+
default = "ack.pro.small"
25+
}
26+
27+
provider "alicloud" {
28+
region = var.region
29+
}
30+
31+
32+
locals {
33+
# 服务网格的规格,可以选择三种规格:standard: 标准版(免费),enterprise:企业版,ultimate:旗舰版。
34+
mesh_spec = "enterprise"
35+
# 获取服务网格的最新版本
36+
mesh_versions = split(":", data.alicloud_service_mesh_versions.default.ids[0])
37+
count = length(local.mesh_versions)
38+
last_versionversion = local.mesh_versions[local.count - 1]
39+
}
40+
41+
# 查询可以创建交换机的可用区
42+
data "alicloud_zones" "default" {
43+
available_resource_creation = "VSwitch"
44+
}
45+
46+
# 查询可以创建的服务网格版本。
47+
data "alicloud_service_mesh_versions" "default" {
48+
edition = local.mesh_spec == "standard" ? "Default" : "Pro"
49+
}
50+
51+
# 随机数
52+
resource "random_integer" "default" {
53+
min = 10000
54+
max = 99999
55+
}
56+
57+
# 专有网络VPC
58+
resource "alicloud_vpc" "vpc" {
59+
vpc_name = "vpc-test_${random_integer.default.result}"
60+
cidr_block = var.vpc_cidr_block
61+
}
62+
63+
# 交换机
64+
resource "alicloud_vswitch" "vswitch" {
65+
vpc_id = alicloud_vpc.vpc.id
66+
cidr_block = var.vsw_cidr_block
67+
zone_id = data.alicloud_zones.default.zones[0].id
68+
vswitch_name = "vswitch-test-${random_integer.default.result}"
69+
}
70+
71+
# 创建ACK Serverless集群
72+
resource "alicloud_cs_serverless_kubernetes" "serverless" {
73+
name = "ack-tf-test-${random_integer.default.result}"
74+
version = var.kubernetes_version
75+
cluster_spec = var.cluster_spec
76+
vpc_id = alicloud_vpc.vpc.id
77+
vswitch_ids = split(",", join(",", alicloud_vswitch.vswitch.*.id))
78+
new_nat_gateway = true
79+
endpoint_public_access_enabled = true
80+
deletion_protection = false
81+
enable_rrsa = true
82+
time_zone = "Asia/Shanghai"
83+
service_cidr = "10.13.0.0/16"
84+
service_discovery_types = ["CoreDNS"]
85+
tags = {
86+
"cluster" = "ack-serverless"
87+
}
88+
addons {
89+
name = "nginx-ingress-controller"
90+
config = "{\"IngressSlbNetworkType\":\"internet\",\"IngressSlbSpec\":\"slb.s2.small\"}"
91+
}
92+
addons {
93+
name = "metrics-server"
94+
}
95+
addons {
96+
name = "knative"
97+
}
98+
addons {
99+
name = "managed-arms-prometheus"
100+
}
101+
addons {
102+
name = "logtail-ds"
103+
}
104+
}
105+
106+
# 服务网格资源
107+
resource "alicloud_service_mesh_service_mesh" "default" {
108+
service_mesh_name = "vsw-tf-${random_integer.default.result}"
109+
version = local.last_versionversion
110+
cluster_spec = local.mesh_spec
111+
edition = "Default"
112+
# 添加集群
113+
# cluster_ids = [alicloud_cs_serverless_kubernetes.serverless.id]
114+
network {
115+
vpc_id = alicloud_vpc.vpc.id
116+
vswitche_list = [alicloud_vswitch.vswitch.id]
117+
}
118+
load_balancer {
119+
api_server_public_eip = true
120+
pilot_public_eip = false
121+
}
122+
mesh_config {
123+
enable_locality_lb = false
124+
access_log {
125+
enabled = true
126+
}
127+
control_plane_log {
128+
enabled = true
129+
}
130+
tracing = true
131+
pilot {
132+
trace_sampling = 100
133+
http10_enabled = true
134+
}
135+
telemetry = true
136+
kiali {
137+
enabled = true
138+
}
139+
140+
audit {
141+
enabled = true
142+
}
143+
}
144+
lifecycle {
145+
ignore_changes = [edition, mesh_config]
146+
}
147+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
terraform {
2+
required_providers {
3+
alicloud = {
4+
source = "aliyun/alicloud"
5+
}
6+
}
7+
}

0 commit comments

Comments
 (0)