Skip to content

Commit 99dac05

Browse files
kubectl now configurable by the module
1 parent 951f8f3 commit 99dac05

File tree

5 files changed

+47
-20
lines changed

5 files changed

+47
-20
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ project adheres to [Semantic Versioning](http://semver.org/).
1212
- files rendered from dedicated templates to separate out raw code and config from `hcl`
1313
- `workers_ami_id` is now made optional. If not specified, the module will source the latest AWS supported EKS AMI instead.
1414
- added ability to specify extra userdata code to execute after the second to configure and start kube services.
15+
- When `configure_kubectl_session` is set to true the current shell will be configured to talk to the kubernetes cluster using config files output from the module.
1516

1617
## [[v0.1.1](https://github.com/terraform-aws-modules/terraform-aws-eks/compare/v0.1.0...v0.1.1)] - 2018-06-07]
1718

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ module "eks" {
2828
subnets = ["subnet-abcde012", "subnet-bcde012a"]
2929
tags = "${map("Environment", "test")}"
3030
vpc_id = "vpc-abcde012"
31-
workers_ami_id = "ami-123456"
3231
cluster_ingress_cidrs = ["24.18.23.91/32"]
3332
}
3433
```
@@ -92,6 +91,8 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
9291
| cluster_ingress_cidrs | The CIDRs from which we can execute kubectl commands. | list | - | yes |
9392
| cluster_name | Name of the EKS cluster which is also used as a prefix in names of related resources. | string | - | yes |
9493
| cluster_version | Kubernetes version to use for the cluster. | string | `1.10` | no |
94+
| config_output_path | Determines where config files are placed if using configure_kubectl_session and you want config files to land outside the current working directory. | string | `./` | no |
95+
| configure_kubectl_session | Configure the current session's kubectl to use the instantiated cluster. | string | `false` | no |
9596
| subnets | A list of subnets to associate with the cluster's underlying instances. | list | - | yes |
9697
| tags | A map of tags to add to all resources. | string | `<map>` | no |
9798
| vpc_id | VPC id where the cluster and other resources will be deployed. | string | - | yes |

examples/eks_test_fixture/main.tf

Lines changed: 9 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,16 +36,6 @@ resource "random_string" "suffix" {
3636
special = false
3737
}
3838

39-
resource "local_file" "kubeconfig" {
40-
content = "${module.eks.kubeconfig}"
41-
filename = "${path.module}/kubeconfig"
42-
}
43-
44-
resource "local_file" "config-map-aws-auth" {
45-
content = "${module.eks.config_map_aws_auth}"
46-
filename = "${path.module}/config-map-aws-auth.yaml"
47-
}
48-
4939
module "vpc" {
5040
source = "terraform-aws-modules/vpc/aws"
5141
version = "1.14.0"
@@ -60,12 +50,13 @@ module "vpc" {
6050
}
6151

6252
module "eks" {
63-
source = "../.."
64-
cluster_name = "${local.cluster_name}"
65-
subnets = "${module.vpc.public_subnets}"
66-
tags = "${local.tags}"
67-
vpc_id = "${module.vpc.vpc_id}"
68-
cluster_ingress_cidrs = ["${local.workstation_external_cidr}"]
69-
workers_instance_type = "t2.small"
70-
additional_userdata = "echo hello world"
53+
source = "../.."
54+
cluster_name = "${local.cluster_name}"
55+
subnets = "${module.vpc.public_subnets}"
56+
tags = "${local.tags}"
57+
vpc_id = "${module.vpc.vpc_id}"
58+
cluster_ingress_cidrs = ["${local.workstation_external_cidr}"]
59+
workers_instance_type = "t2.small"
60+
additional_userdata = "echo hello world"
61+
configure_kubectl_session = true
7162
}

main.tf

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,6 @@
2929
* subnets = ["subnet-abcde012", "subnet-bcde012a"]
3030
* tags = "${map("Environment", "test")}"
3131
* vpc_id = "vpc-abcde012"
32-
* workers_ami_id = "ami-123456"
3332
* cluster_ingress_cidrs = ["24.18.23.91/32"]
3433
* }
3534
* ```
@@ -88,3 +87,28 @@ To test your kubectl connection manually, see the [eks_test_fixture README](http
8887

8988
provider "null" {}
9089
provider "template" {}
90+
91+
resource "local_file" "kubeconfig" {
92+
content = "${data.template_file.kubeconfig.rendered}"
93+
filename = "${var.config_output_path}/kubeconfig"
94+
count = "${var.configure_kubectl_session ? 1 : 0}"
95+
}
96+
97+
resource "local_file" "config_map_aws_auth" {
98+
content = "${data.template_file.config_map_aws_auth.rendered}"
99+
filename = "${var.config_output_path}/config-map-aws-auth.yaml"
100+
count = "${var.configure_kubectl_session ? 1 : 0}"
101+
}
102+
103+
resource "null_resource" "configure_kubectl" {
104+
provisioner "local-exec" {
105+
command = "kubectl apply -f ${var.config_output_path}/config-map-aws-auth.yaml --kubeconfig ${var.config_output_path}/kubeconfig"
106+
}
107+
108+
triggers {
109+
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
110+
kubeconfig_rendered = "${data.template_file.kubeconfig.rendered}"
111+
}
112+
113+
count = "${var.configure_kubectl_session ? 1 : 0}"
114+
}

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,16 @@ variable "cluster_version" {
1717
default = "1.10"
1818
}
1919

20+
variable "config_output_path" {
21+
description = "Determines where config files are placed if using configure_kubectl_session and you want config files to land outside the current working directory."
22+
default = "./"
23+
}
24+
25+
variable "configure_kubectl_session" {
26+
description = "Configure the current session's kubectl to use the instantiated cluster."
27+
default = false
28+
}
29+
2030
variable "subnets" {
2131
description = "A list of subnets to associate with the cluster's underlying instances."
2232
type = "list"

0 commit comments

Comments
 (0)