|
1 | 1 | // Provider specific configs |
2 | 2 | provider "alicloud" { |
3 | | - version = ">=1.56.0" |
4 | | - region = var.region != "" ? var.region : null |
5 | | - configuration_source = "terraform-alicloud-modules/kubernetes" |
6 | | -} |
7 | | - |
8 | | -// Instance_types data source for instance_type |
9 | | -data "alicloud_instance_types" "default" { |
10 | | - cpu_core_count = var.cpu_core_count |
11 | | - memory_size = var.memory_size |
12 | | -} |
13 | | - |
14 | | -// Zones data source for availability_zone |
15 | | -data "alicloud_zones" "default" { |
16 | | - available_instance_type = data.alicloud_instance_types.default.instance_types[0].id |
17 | | -} |
18 | | - |
19 | | -// If there is not specifying vpc_id, the module will launch a new vpc |
20 | | -resource "alicloud_vpc" "vpc" { |
21 | | - count = var.vpc_id == "" ? 1 : 0 |
22 | | - cidr_block = var.vpc_cidr |
23 | | - name = var.vpc_name == "" ? var.example_name : var.vpc_name |
24 | | -} |
25 | | - |
26 | | -// According to the vswitch cidr blocks to launch several vswitches |
27 | | -resource "alicloud_vswitch" "vswitches" { |
28 | | - count = length(var.vswitch_ids) > 0 ? 0 : length(var.vswitch_cidrs) |
29 | | - vpc_id = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id |
30 | | - cidr_block = var.vswitch_cidrs[count.index] |
31 | | - availability_zone = data.alicloud_zones.default.zones[count.index % length(data.alicloud_zones.default.zones)]["id"] |
32 | | - name = var.vswitch_name_prefix == "" ? format( |
33 | | - "%s-%s", |
34 | | - var.example_name, |
35 | | - format(var.number_format, count.index + 1), |
36 | | - ) : format( |
37 | | - "%s-%s", |
38 | | - var.vswitch_name_prefix, |
39 | | - format(var.number_format, count.index + 1), |
40 | | - ) |
41 | | -} |
42 | | - |
43 | | -resource "alicloud_nat_gateway" "default" { |
44 | | - count = var.new_nat_gateway == "true" ? 1 : 0 |
45 | | - vpc_id = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id |
46 | | - name = var.example_name |
47 | | -} |
48 | | - |
49 | | -resource "alicloud_eip" "default" { |
50 | | - count = var.new_nat_gateway == "true" ? 1 : 0 |
51 | | - bandwidth = 10 |
52 | | -} |
53 | | - |
54 | | -resource "alicloud_eip_association" "default" { |
55 | | - count = var.new_nat_gateway == "true" ? 1 : 0 |
56 | | - allocation_id = alicloud_eip.default[0].id |
57 | | - instance_id = alicloud_nat_gateway.default[0].id |
58 | | -} |
59 | | - |
60 | | -resource "alicloud_snat_entry" "default" { |
61 | | - count = var.new_nat_gateway == "false" ? 0 : length(var.vswitch_ids) > 0 ? length(var.vswitch_ids) : length(var.vswitch_cidrs) |
62 | | - snat_table_id = alicloud_nat_gateway.default[0].snat_table_ids |
63 | | - source_vswitch_id = length(var.vswitch_ids) > 0 ? split(",", join(",", var.vswitch_ids))[count.index % length(split(",", join(",", var.vswitch_ids)))] : length(var.vswitch_cidrs) < 1 ? "" : split(",", join(",", alicloud_vswitch.vswitches.*.id))[count.index % length(split(",", join(",", alicloud_vswitch.vswitches.*.id)))] |
64 | | - snat_ip = alicloud_eip.default[0].ip_address |
| 3 | + version = ">=1.60.0" |
| 4 | + profile = var.profile != "" ? var.profile : null |
| 5 | + shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null |
| 6 | + region = var.region != "" ? var.region : null |
| 7 | + skip_region_validation = var.skip_region_validation |
| 8 | + configuration_source = "terraform-alicloud-modules/kubernetes" |
65 | 9 | } |
66 | 10 |
|
67 | 11 | resource "alicloud_cs_kubernetes" "k8s" { |
68 | | - count = var.k8s_number |
69 | | - name = var.k8s_name_prefix == "" ? format( |
70 | | - "%s-%s", |
71 | | - var.example_name, |
72 | | - format(var.number_format, count.index + 1), |
73 | | - ) : format( |
74 | | - "%s-%s", |
75 | | - var.k8s_name_prefix, |
76 | | - format(var.number_format, count.index + 1), |
77 | | - ) |
78 | | - vswitch_ids = [length(var.vswitch_ids) > 0 ? split(",", join(",", var.vswitch_ids))[count.index%length(split(",", join(",", var.vswitch_ids)))] : length(var.vswitch_cidrs) < 1 ? "" : split(",", join(",", alicloud_vswitch.vswitches.*.id))[count.index%length(split(",", join(",", alicloud_vswitch.vswitches.*.id)))]] |
79 | | - |
80 | | - new_nat_gateway = false |
| 12 | + availability_zone = local.zone_id |
| 13 | + name = var.k8s_name |
| 14 | + vswitch_ids = local.vswitch_ids |
| 15 | + new_nat_gateway = var.new_nat_gateway |
81 | 16 | master_disk_category = var.master_disk_category |
82 | 17 | worker_disk_category = var.worker_disk_category |
83 | 18 | master_disk_size = var.master_disk_size |
84 | | - worker_disk_size = var.master_disk_size |
| 19 | + worker_disk_size = var.worker_disk_size |
85 | 20 | password = var.ecs_password |
86 | 21 | pod_cidr = var.k8s_pod_cidr |
87 | 22 | service_cidr = var.k8s_service_cidr |
88 | 23 | enable_ssh = true |
89 | 24 | install_cloud_monitor = true |
90 | 25 |
|
91 | | - depends_on = [alicloud_snat_entry.default] |
92 | | - master_instance_types = var.master_instance_types |
93 | | - worker_instance_types = var.worker_instance_types |
94 | | - worker_numbers = var.k8s_worker_numbers |
| 26 | + master_instance_types = local.master_instance_types |
| 27 | + worker_instance_types = local.worker_instance_types |
| 28 | + worker_numbers = var.k8s_worker_numbers |
95 | 29 | } |
96 | 30 |
|
0 commit comments