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