Skip to content

Commit 16814ba

Browse files
zql-tqyxiaozhu36
authored andcommitted
Replace deprecation parameter add example.
1 parent d5bb291 commit 16814ba

File tree

7 files changed

+322
-80
lines changed

7 files changed

+322
-80
lines changed

CHANGELOG.md

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
## 1.2.0 (Unreleased)
2+
## 1.2.0 (Jun 16,2020)
3+
4+
IMPROVEMENTS
5+
6+
- Replace deprecation parameter add example. [GH-4]( https://github.com/terraform-alicloud-modules/terraform-alicloud-kubernetes/pull/4)
7+
8+
## 1.1.0 (Sep 24, 2019)
9+
10+
IMPROVEMENTS
11+
12+
- fix kubernetes module. [GH-2]( https://github.com/terraform-alicloud-modules/terraform-alicloud-kubernetes/pull/2)
13+
14+
- imporve(kubernetes): update the module to the format of the new version. [GH-1]( https://github.com/terraform-alicloud-modules/terraform-alicloud-kubernetes/pull/1)

README.md

Lines changed: 96 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,9 @@ These types of the module resource are supported:
1212
- [Nat Gateway](https://www.terraform.io/docs/providers/alicloud/r/nat_gateway.html)
1313
- [Kubernetes](https://www.terraform.io/docs/providers/alicloud/r/cs_kubernetes.html)
1414

15+
Terraform version
16+
-----------------
17+
The Module requires Terraform 0.12 and Terraform Provider AliCloud 1.75.0+.
1518

1619
Usage
1720
-----
@@ -58,13 +61,70 @@ You can specify the following user-defined arguments:
5861
* vswitch_name_prefix: The name prefix of several vswitches
5962
* vswitch_cidrs: List of cidr blocks for several new vswitches
6063

64+
```hcl
65+
variable "profile" {
66+
default = "default"
67+
}
68+
69+
variable "region" {
70+
default = "cn-hangzhou"
71+
}
72+
73+
data "alicloud_vpcs" "default" {
74+
is_default = true
75+
}
76+
77+
module "k8s" {
78+
source = "../"
79+
region = var.region
80+
81+
new_nat_gateway = true
82+
vpc_name = "tf-k8s-vpc"
83+
vpc_cidr = "10.0.0.0/8"
84+
vswitch_name_prefix = "tf-k8s-vsw"
85+
vswitch_cidrs = ["10.1.0.0/16", "10.2.0.0/16", "10.3.0.0/16"]
86+
master_instance_types = ["ecs.n1.medium", "ecs.c5.large", "ecs.n1.medium"]
87+
worker_instance_types = ["ecs.n1.medium"]
88+
k8s_pod_cidr = "192.168.5.0/24"
89+
k8s_service_cidr = "192.168.2.0/24"
90+
k8s_worker_number = 2
91+
}
92+
```
93+
6194
### 2. Using existing vpc and vswitches for the cluster.
6295

6396
You can specify the following user-defined arguments:
6497

6598
* vpc_id: A existing vpc ID
6699
* vswitch_ids: List of IDs for several existing vswitches
67100

101+
```hcl
102+
variable "profile" {
103+
default = "default"
104+
}
105+
106+
variable "region" {
107+
default = "cn-hangzhou"
108+
}
109+
110+
data "alicloud_vpcs" "default" {
111+
is_default = true
112+
}
113+
114+
module "k8s" {
115+
source = "../"
116+
region = var.region
117+
118+
vpc_id = data.alicloud_vpcs.default.vpcs.0.id
119+
vswitch_ids = ["vsw-bp1pog8voc3f42arr****", "vsw-bp1jxetj1386gqssg****", "vsw-bp1s1835sq5tjss9s****"]
120+
master_instance_types = ["ecs.n1.medium", "ecs.c5.large", "ecs.n1.medium"]
121+
worker_instance_types = ["ecs.n1.medium"]
122+
k8s_pod_cidr = "192.168.5.0/24"
123+
k8s_service_cidr = "192.168.2.0/24"
124+
k8s_worker_number = 2
125+
}
126+
```
127+
68128
### 3. Using existing vpc, vswitches and nat gateway for the cluster.
69129

70130
You can specify the following user-defined arguments:
@@ -74,10 +134,43 @@ You can specify the following user-defined arguments:
74134
* new_nat_gateway: Set it to false. But you must ensure you specified vswitches can access internet.
75135
In other words, you must set snat entry for each vswitch before running the example.
76136

137+
```hcl
138+
variable "profile" {
139+
default = "default"
140+
}
77141
78-
Terraform version
79-
-----------------
80-
Terraform version 0.11.0 or newer and Provider version 1.9.0 or newer are required for this example to work.
142+
variable "region" {
143+
default = "cn-hangzhou"
144+
}
145+
146+
data "alicloud_vpcs" "default" {
147+
is_default = true
148+
}
149+
150+
module "k8s" {
151+
source = "../"
152+
region = var.region
153+
154+
new_nat_gateway = false
155+
vpc_id = data.alicloud_vpcs.default.vpcs.0.id
156+
vswitch_ids = ["vsw-bp1pog8voc3f42arr****", "vsw-bp1jxetj1386gqssg****", "vsw-bp1s1835sq5tjss9s****"]
157+
master_instance_types = ["ecs.n1.medium", "ecs.c5.large", "ecs.n1.medium"]
158+
worker_instance_types = ["ecs.n1.medium"]
159+
k8s_pod_cidr = "192.168.5.0/24"
160+
k8s_service_cidr = "192.168.2.0/24"
161+
k8s_worker_number = 2
162+
}
163+
```
164+
165+
## Examples
166+
167+
* [complete example](https://github.com/terraform-alicloud-modules/terraform-alicloud-kubernetes/tree/master/examples/complete)
168+
169+
Submit Issues
170+
-------------
171+
If you have any problems when using this module, please opening a [provider issue](https://github.com/terraform-providers/terraform-provider-alicloud/issues/new) and let us know.
172+
173+
**Note:** There does not recommend to open an issue on this repo.
81174

82175
Authors
83176
-------

examples/complete/README.md

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
Terraform module for creating Kubernetes Cluster on Alibaba Cloud.
2+
terraform-alicloud-kubernetes
3+
=====================================================================
4+
5+
## Usage
6+
7+
To run this example you need to execute:
8+
9+
```bash
10+
$ terraform init
11+
$ terraform plan
12+
$ terraform apply
13+
```
14+
15+
Note that this example will create resources which cost money. Run `terraform destroy` when you don't need these resources.
16+

examples/complete/main.tf

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
variable "profile" {
2+
default = "default"
3+
}
4+
5+
variable "region" {
6+
default = "cn-hangzhou"
7+
}
8+
9+
data "alicloud_vpcs" "default" {
10+
is_default = true
11+
}
12+
13+
module "k8s" {
14+
source = "../.."
15+
region = var.region
16+
17+
new_nat_gateway = false
18+
vpc_id = data.alicloud_vpcs.default.vpcs.0.id
19+
vswitch_ids = ["vsw-bp1pog8voc3f42arr****", "vsw-bp1jxetj1386gqssg****", "vsw-bp1s1835sq5tjss9s****"]
20+
master_instance_types = ["ecs.n1.medium", "ecs.c5.large", "ecs.n1.medium"]
21+
worker_instance_types = ["ecs.n1.medium"]
22+
k8s_pod_cidr = "192.168.5.0/24"
23+
k8s_service_cidr = "192.168.2.0/24"
24+
k8s_worker_number = 2
25+
}

examples/complete/outputs.tf

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Output VPC
2+
output "vpc_id" {
3+
description = "The ID of the VPC."
4+
value = module.k8s.vpc_id
5+
}
6+
7+
output "vswitch_ids" {
8+
description = "List ID of the VSwitches."
9+
value = module.k8s.vswitch_ids
10+
}
11+
12+
output "nat_gateway_id" {
13+
value = module.k8s.nat_gateway_id
14+
}
15+
16+
// Output kubernetes resource
17+
output "cluster_id" {
18+
description = "ID of the kunernetes cluster."
19+
value = module.k8s.cluster_id
20+
}
21+
22+
output "security_group_id" {
23+
description = "ID of the Security Group used to deploy kubernetes cluster."
24+
value = module.k8s.security_group_id
25+
}
26+
27+
output "cluster_nodes" {
28+
description = "List nodes of cluster."
29+
value = module.k8s.cluster_nodes
30+
}
31+

main.tf

Lines changed: 33 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,10 @@
11
// Provider specific configs
22
provider "alicloud" {
3-
version = ">=1.56.0"
4-
region = var.region != "" ? var.region : null
5-
configuration_source = "terraform-alicloud-modules/kubernetes"
3+
profile = var.profile != "" ? var.profile : null
4+
shared_credentials_file = var.shared_credentials_file != "" ? var.shared_credentials_file : null
5+
region = var.region
6+
skip_region_validation = var.skip_region_validation
7+
configuration_source = "terraform-alicloud-modules/kubernetes"
68
}
79

810
// Instance_types data source for instance_type
@@ -41,31 +43,33 @@ resource "alicloud_vswitch" "vswitches" {
4143
}
4244

4345
resource "alicloud_nat_gateway" "default" {
44-
count = var.new_nat_gateway == "true" ? 1 : 0
46+
count = var.new_nat_gateway == true ? 1 : 0
4547
vpc_id = var.vpc_id == "" ? join("", alicloud_vpc.vpc.*.id) : var.vpc_id
4648
name = var.example_name
4749
}
4850

4951
resource "alicloud_eip" "default" {
50-
count = var.new_nat_gateway == "true" ? 1 : 0
52+
count = var.new_nat_gateway == true ? 1 : 0
5153
bandwidth = 10
5254
}
5355

5456
resource "alicloud_eip_association" "default" {
55-
count = var.new_nat_gateway == "true" ? 1 : 0
57+
count = var.new_nat_gateway == true ? 1 : 0
5658
allocation_id = alicloud_eip.default[0].id
5759
instance_id = alicloud_nat_gateway.default[0].id
5860
}
5961

6062
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+
count = var.new_nat_gateway == false ? 0 : length(var.vswitch_ids) > 0 ? length(var.vswitch_ids) : length(var.vswitch_cidrs)
64+
snat_table_id = alicloud_nat_gateway.default[0].snat_table_ids
6365
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
66+
snat_ip = alicloud_eip.default[0].ip_address
67+
depends_on = [alicloud_eip_association.default]
6568
}
6669

6770
resource "alicloud_cs_kubernetes" "k8s" {
6871
count = var.k8s_number
72+
6973
name = var.k8s_name_prefix == "" ? format(
7074
"%s-%s",
7175
var.example_name,
@@ -75,22 +79,26 @@ resource "alicloud_cs_kubernetes" "k8s" {
7579
var.k8s_name_prefix,
7680
format(var.number_format, count.index + 1),
7781
)
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
81-
master_disk_category = var.master_disk_category
82-
worker_disk_category = var.worker_disk_category
83-
master_disk_size = var.master_disk_size
84-
worker_disk_size = var.master_disk_size
85-
password = var.ecs_password
82+
master_vswitch_ids = length(var.vswitch_ids) > 0 ? split(",", join(",", var.vswitch_ids)) : length(var.vswitch_cidrs) < 1 ? [] : split(",", join(",", alicloud_vswitch.vswitches.*.id))
83+
worker_vswitch_ids = length(var.vswitch_ids) > 0 ? split(",", join(",", var.vswitch_ids)) : length(var.vswitch_cidrs) < 1 ? [] : split(",", join(",", alicloud_vswitch.vswitches.*.id))
84+
master_instance_types = var.master_instance_types
85+
worker_instance_types = var.worker_instance_types
86+
worker_number = var.k8s_worker_number
87+
node_cidr_mask = var.node_cidr_mask
88+
enable_ssh = var.enable_ssh
89+
install_cloud_monitor = var.install_cloud_monitor
90+
cpu_policy = var.cpu_policy
91+
proxy_mode = var.proxy_mode
92+
password = var.password
8693
pod_cidr = var.k8s_pod_cidr
8794
service_cidr = var.k8s_service_cidr
88-
enable_ssh = true
89-
install_cloud_monitor = true
90-
95+
version = var.k8s_version
96+
dynamic "addons" {
97+
for_each = var.cluster_addons
98+
content {
99+
name = lookup(addons.value, "name", var.cluster_addons)
100+
config = lookup(addons.value, "config", var.cluster_addons)
101+
}
102+
}
91103
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
95-
}
96-
104+
}

0 commit comments

Comments
 (0)