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
+ }
0 commit comments