Skip to content

Commit

Permalink
Splitting aws-auth and kubectl related resources as they are not related
Browse files Browse the repository at this point in the history
  • Loading branch information
max-rocket-internet committed Jul 9, 2018
1 parent f385415 commit 1a1d92d
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 23 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -98,7 +98,8 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
| 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 |
| cluster_version | Kubernetes version to use for the EKS cluster. | string | `1.10` | no |
| 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 |
| configure_kubectl_session | Configure the current session's kubectl to use the instantiated EKS cluster. | string | `true` | no |
| manage_aws_auth | Whether to write and apply the aws-auth configmap file. | boolean | `true` | no |
| write_kubeconfig | Whether to write a kubeconfig file containing the cluster configuration. | boolean | `true` | no |
| kubeconfig_aws_authenticator_additional_args | Any additional arguments to pass to the authenticator such as the role to assume ["-r", "MyEksRole"] | string | `<list>` | no |
| kubeconfig_aws_authenticator_command | Command to use to to fetch AWS EKS credentials | string | `heptio-authenticator-aws` | no |
| kubeconfig_aws_authenticator_env_variables | Environment variables that should be used when executing the authenticator i.e. { AWS_PROFILE = "eks"} | string | `<map>` | no |
Expand Down
18 changes: 18 additions & 0 deletions aws_auth.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
resource "local_file" "config_map_aws_auth" {
content = "${data.template_file.config_map_aws_auth.rendered}"
filename = "${var.config_output_path}/config-map-aws-auth.yaml"
count = "${var.manage_aws_auth ? 1 : 0}"
}

resource "null_resource" "configure_kubectl" {
provisioner "local-exec" {
command = "kubectl apply -f ${var.config_output_path}/config-map-aws-auth.yaml --kubeconfig ${var.config_output_path}/kubeconfig"
}

triggers {
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
kubeconfig_rendered = "${data.template_file.kubeconfig.rendered}"
}

count = "${var.manage_aws_auth ? 1 : 0}"
}
21 changes: 1 addition & 20 deletions kubectl.tf
Original file line number Diff line number Diff line change
@@ -1,24 +1,5 @@
resource "local_file" "kubeconfig" {
content = "${data.template_file.kubeconfig.rendered}"
filename = "${var.config_output_path}/kubeconfig_${var.cluster_name}"
count = "${var.configure_kubectl_session ? 1 : 0}"
}

resource "local_file" "config_map_aws_auth" {
content = "${data.template_file.config_map_aws_auth.rendered}"
filename = "${var.config_output_path}/config-map-aws-auth_${var.cluster_name}.yaml"
count = "${var.configure_kubectl_session ? 1 : 0}"
}

resource "null_resource" "configure_kubectl" {
provisioner "local-exec" {
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}"
}

triggers {
config_map_rendered = "${data.template_file.config_map_aws_auth.rendered}"
kubeconfig_rendered = "${data.template_file.kubeconfig.rendered}"
}

count = "${var.configure_kubectl_session ? 1 : 0}"
count = "${var.write_kubeconfig ? 1 : 0}"
}
9 changes: 7 additions & 2 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,13 @@ variable "config_output_path" {
default = "./"
}

variable "configure_kubectl_session" {
description = "Configure the current session's kubectl to use the instantiated EKS cluster."
variable "write_kubeconfig" {
description = "Whether to write a kubeconfig file containing the cluster configuration"
default = true
}

variable "manage_aws_auth" {
description = "Whether to write and apply the aws-auth configmap file"
default = true
}

Expand Down

0 comments on commit 1a1d92d

Please sign in to comment.