Skip to content

Commit e1e265b

Browse files
Nic Graysonmax-rocket-internet
authored andcommitted
allow user to overwrite the kubeconfig default args (#129)
* allow user to overwrite the kubeconfig default args * quote args to auth command
1 parent 31ec0f7 commit e1e265b

File tree

3 files changed

+9
-5
lines changed

3 files changed

+9
-5
lines changed

data.tf

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,13 @@ data "template_file" "kubeconfig" {
4444
template = "${file("${path.module}/templates/kubeconfig.tpl")}"
4545

4646
vars {
47-
cluster_name = "${aws_eks_cluster.this.name}"
4847
kubeconfig_name = "${local.kubeconfig_name}"
4948
endpoint = "${aws_eks_cluster.this.endpoint}"
5049
region = "${data.aws_region.current.name}"
5150
cluster_auth_base64 = "${aws_eks_cluster.this.certificate_authority.0.data}"
5251
aws_authenticator_command = "${var.kubeconfig_aws_authenticator_command}"
53-
aws_authenticator_additional_args = "${length(var.kubeconfig_aws_authenticator_additional_args) > 0 ? " - ${join("\n - ", var.kubeconfig_aws_authenticator_additional_args)}" : "" }"
52+
aws_authenticator_command_args = "${length(var.kubeconfig_aws_authenticator_command_args) > 0 ? " - ${join("\n - ", var.kubeconfig_aws_authenticator_command_args)}" : " - ${join("\n - ", formatlist("\"%s\"", list("token", "-i", aws_eks_cluster.this.name)))}"}"
53+
aws_authenticator_additional_args = "${length(var.kubeconfig_aws_authenticator_additional_args) > 0 ? " - ${join("\n - ", var.kubeconfig_aws_authenticator_additional_args)}" : ""}"
5454
aws_authenticator_env_variables = "${length(var.kubeconfig_aws_authenticator_env_variables) > 0 ? " env:\n${join("\n", data.template_file.aws_authenticator_env_variables.*.rendered)}" : ""}"
5555
}
5656
}

templates/kubeconfig.tpl

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -23,8 +23,6 @@ users:
2323
apiVersion: client.authentication.k8s.io/v1alpha1
2424
command: ${aws_authenticator_command}
2525
args:
26-
- "token"
27-
- "-i"
28-
- "${cluster_name}"
26+
${aws_authenticator_command_args}
2927
${aws_authenticator_additional_args}
3028
${aws_authenticator_env_variables}

variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,12 @@ variable "kubeconfig_aws_authenticator_command" {
102102
default = "aws-iam-authenticator"
103103
}
104104

105+
variable "kubeconfig_aws_authenticator_command_args" {
106+
description = "Default arguments passed to the authenticator command. Defaults to [token -i $cluster_name]."
107+
type = "list"
108+
default = []
109+
}
110+
105111
variable "kubeconfig_aws_authenticator_additional_args" {
106112
description = "Any additional arguments to pass to the authenticator such as the role to assume. e.g. [\"-r\", \"MyEksRole\"]."
107113
type = "list"

0 commit comments

Comments
 (0)