Removing region from kubectl config and adding override variable

This commit is contained in:
Max Williams
2018-07-09 10:31:01 +02:00
parent 0ffa4932f6
commit 7e4e93eeec
5 changed files with 15 additions and 6 deletions

View File

@@ -102,6 +102,7 @@ MIT Licensed. See [LICENSE](https://github.com/terraform-aws-modules/terraform-a
| 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 |
| kubeconfig_name | Override the default name used for items kubeconfig. | string | `` | no |
| subnets | A list of subnets to place the EKS cluster and workers within. | list | - | yes |
| tags | A map of tags to add to all resources. | string | `<map>` | no |
| vpc_id | VPC where the cluster and workers will be deployed. | string | - | yes |

View File

@@ -49,6 +49,7 @@ data "template_file" "kubeconfig" {
vars {
cluster_name = "${var.cluster_name}"
kubeconfig_name = "${local.kubeconfig_name}"
endpoint = "${aws_eks_cluster.this.endpoint}"
region = "${data.aws_region.current.name}"
cluster_auth_base64 = "${aws_eks_cluster.this.certificate_authority.0.data}"

View File

@@ -9,6 +9,8 @@ locals {
workstation_external_cidr = "${chomp(data.http.workstation_external_ip.body)}/32"
workstation_cidr = "${coalesce(var.workstation_cidr, local.workstation_external_cidr)}"
kubeconfig_name = "${var.kubeconfig_name == "" ? "eks_${var.cluster_name}" : var.kubeconfig_name}"
# Mapping from the node type that we selected and the max number of pods that it can run
# Taken from https://amazon-eks.s3-us-west-2.amazonaws.com/1.10.3/2018-06-05/amazon-eks-nodegroup.yaml
max_pod_per_node = {

View File

@@ -6,18 +6,18 @@ clusters:
- cluster:
server: ${endpoint}
certificate-authority-data: ${cluster_auth_base64}
name: eks_${region}_${cluster_name}
name: ${kubeconfig_name}
contexts:
- context:
cluster: eks_${region}_${cluster_name}
user: eks_${region}_${cluster_name}
name: eks_${region}_${cluster_name}
cluster: ${kubeconfig_name}
user: ${kubeconfig_name}
name: ${kubeconfig_name}
current-context: eks_${region}_${cluster_name}
current-context: ${kubeconfig_name}
users:
- name: eks_${region}_${cluster_name}
- name: ${kubeconfig_name}
user:
exec:
apiVersion: client.authentication.k8s.io/v1alpha1

View File

@@ -93,3 +93,8 @@ variable "kubeconfig_aws_authenticator_env_variables" {
description = "Environment variables that should be used when executing the authenticator i.e. { AWS_PROFILE = \"eks\"}"
default = {}
}
variable "kubeconfig_name" {
description = "Override the default name used for items kubeconfig"
default = ""
}