Skip to content

Commit 1a1d92d

Browse files
Splitting aws-auth and kubectl related resources as they are not related
1 parent f385415 commit 1a1d92d

File tree

4 files changed

+28
-23
lines changed

4 files changed

+28
-23
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -98,7 +98,8 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
9898
| cluster_security_group_id | If provided, the EKS cluster will be attached to this security group. If not given, a security group will be created with necessary ingres/egress to work with the workers and provide API access to your current IP/32. | string | `` | no |
9999
| cluster_version | Kubernetes version to use for the EKS cluster. | string | `1.10` | no |
100100
| 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 |
101-
| configure_kubectl_session | Configure the current session's kubectl to use the instantiated EKS cluster. | string | `true` | no |
101+
| manage_aws_auth | Whether to write and apply the aws-auth configmap file. | boolean | `true` | no |
102+
| write_kubeconfig | Whether to write a kubeconfig file containing the cluster configuration. | boolean | `true` | no |
102103
| kubeconfig_aws_authenticator_additional_args | Any additional arguments to pass to the authenticator such as the role to assume ["-r", "MyEksRole"] | string | `<list>` | no |
103104
| kubeconfig_aws_authenticator_command | Command to use to to fetch AWS EKS credentials | string | `heptio-authenticator-aws` | no |
104105
| kubeconfig_aws_authenticator_env_variables | Environment variables that should be used when executing the authenticator i.e. { AWS_PROFILE = "eks"} | string | `<map>` | no |

aws_auth.tf

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
resource "local_file" "config_map_aws_auth" {
2+
content = "${data.template_file.config_map_aws_auth.rendered}"
3+
filename = "${var.config_output_path}/config-map-aws-auth.yaml"
4+
count = "${var.manage_aws_auth ? 1 : 0}"
5+
}
6+
7+
resource "null_resource" "configure_kubectl" {
8+
provisioner "local-exec" {
9+
command = "kubectl apply -f ${var.config_output_path}/config-map-aws-auth.yaml --kubeconfig ${var.config_output_path}/kubeconfig"
10+
}
11+
12+
triggers {
13+
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
14+
kubeconfig_rendered = "${data.template_file.kubeconfig.rendered}"
15+
}
16+
17+
count = "${var.manage_aws_auth ? 1 : 0}"
18+
}

kubectl.tf

Lines changed: 1 addition & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,24 +1,5 @@
11
resource "local_file" "kubeconfig" {
22
content = "${data.template_file.kubeconfig.rendered}"
33
filename = "${var.config_output_path}/kubeconfig_${var.cluster_name}"
4-
count = "${var.configure_kubectl_session ? 1 : 0}"
5-
}
6-
7-
resource "local_file" "config_map_aws_auth" {
8-
content = "${data.template_file.config_map_aws_auth.rendered}"
9-
filename = "${var.config_output_path}/config-map-aws-auth_${var.cluster_name}.yaml"
10-
count = "${var.configure_kubectl_session ? 1 : 0}"
11-
}
12-
13-
resource "null_resource" "configure_kubectl" {
14-
provisioner "local-exec" {
15-
command = "kubectl apply -f ${var.config_output_path}/config-map-aws-auth_${var.cluster_name}.yaml --kubeconfig ${var.config_output_path}/kubeconfig_${var.cluster_name}"
16-
}
17-
18-
triggers {
19-
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
20-
kubeconfig_rendered = "${data.template_file.kubeconfig.rendered}"
21-
}
22-
23-
count = "${var.configure_kubectl_session ? 1 : 0}"
4+
count = "${var.write_kubeconfig ? 1 : 0}"
245
}

variables.tf

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,13 @@ variable "config_output_path" {
2222
default = "./"
2323
}
2424

25-
variable "configure_kubectl_session" {
26-
description = "Configure the current session's kubectl to use the instantiated EKS cluster."
25+
variable "write_kubeconfig" {
26+
description = "Whether to write a kubeconfig file containing the cluster configuration"
27+
default = true
28+
}
29+
30+
variable "manage_aws_auth" {
31+
description = "Whether to write and apply the aws-auth configmap file"
2732
default = true
2833
}
2934

0 commit comments

Comments
 (0)