From cabf0494256550a502fe82a27dada15eb4c3d1e5 Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 12:39:17 -0700 Subject: [PATCH 1/8] added conditional profile --- modules/cluster/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cluster/main.tf b/modules/cluster/main.tf index e6c6f17..85efe68 100644 --- a/modules/cluster/main.tf +++ b/modules/cluster/main.tf @@ -148,7 +148,7 @@ resource "null_resource" "kubeconfig" { module.eks ] provisioner "local-exec" { - command = "aws eks update-kubeconfig --name ${var.cluster_name} --region=${var.region}" + command = "aws eks update-kubeconfig --name ${var.cluster_name} --region=${var.region} ${var.profile ? --profile=var.profile : ""}" interpreter = var.local-exec-interpreter } } From 92373e0016f7b539a795c46e84107c22bb112975 Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 16:11:26 -0700 Subject: [PATCH 2/8] Add profile variable --- variables.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/variables.tf b/variables.tf index 17e4326..8436d9b 100644 --- a/variables.tf +++ b/variables.tf @@ -13,6 +13,12 @@ variable "cluster_name" { default = "" } +variable "profile" { + description = "The AWS Profile used to provition the EKS Cluster" + type = string + default = "default" +} + variable "cluster_version" { description = "Kubernetes version to use for the EKS cluster." type = string From 08291fb063a9eea09d412f8a8bd2ac00c873eb21 Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 16:15:07 -0700 Subject: [PATCH 3/8] Added profile flag --- modules/cluster/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cluster/main.tf b/modules/cluster/main.tf index 85efe68..9971dcb 100644 --- a/modules/cluster/main.tf +++ b/modules/cluster/main.tf @@ -148,7 +148,7 @@ resource "null_resource" "kubeconfig" { module.eks ] provisioner "local-exec" { - command = "aws eks update-kubeconfig --name ${var.cluster_name} --region=${var.region} ${var.profile ? --profile=var.profile : ""}" + command = "aws eks update-kubeconfig --name ${var.cluster_name} --region=${var.region} --profile=${var.profile}" interpreter = var.local-exec-interpreter } } From 2dcf956ba2c56d3ad03dc8935eed3c900737b847 Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 16:25:21 -0700 Subject: [PATCH 4/8] Spelling is hard --- variables.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/variables.tf b/variables.tf index 8436d9b..7db0dd8 100644 --- a/variables.tf +++ b/variables.tf @@ -14,7 +14,7 @@ variable "cluster_name" { } variable "profile" { - description = "The AWS Profile used to provition the EKS Cluster" + description = "The AWS Profile used to provision the EKS Cluster" type = string default = "default" } From 1785ce1c613dd6a31a788f662619225a64bfb79d Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 16:29:03 -0700 Subject: [PATCH 5/8] removed default to allow ENV override --- variables.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/variables.tf b/variables.tf index 7db0dd8..8804624 100644 --- a/variables.tf +++ b/variables.tf @@ -16,7 +16,6 @@ variable "cluster_name" { variable "profile" { description = "The AWS Profile used to provision the EKS Cluster" type = string - default = "default" } variable "cluster_version" { From a8d9556c6c4aba6cb0250e5a72f390f86b7fcd4e Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 16:36:56 -0700 Subject: [PATCH 6/8] add conditional check --- modules/cluster/main.tf | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/modules/cluster/main.tf b/modules/cluster/main.tf index 9971dcb..54777e9 100644 --- a/modules/cluster/main.tf +++ b/modules/cluster/main.tf @@ -148,7 +148,7 @@ resource "null_resource" "kubeconfig" { module.eks ] provisioner "local-exec" { - command = "aws eks update-kubeconfig --name ${var.cluster_name} --region=${var.region} --profile=${var.profile}" + command = "aws eks update-kubeconfig --name ${var.cluster_name} --region=${var.region} ${var.profile == null ? "" : format("--profile=%s", var.profile)}" interpreter = var.local-exec-interpreter } } From 1c7877b31b68c788cf6c732867f98c30f4fa73bf Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 16:37:28 -0700 Subject: [PATCH 7/8] default to null so we can see if it's been set --- variables.tf | 1 + 1 file changed, 1 insertion(+) diff --git a/variables.tf b/variables.tf index 8804624..4aef171 100644 --- a/variables.tf +++ b/variables.tf @@ -16,6 +16,7 @@ variable "cluster_name" { variable "profile" { description = "The AWS Profile used to provision the EKS Cluster" type = string + default = null } variable "cluster_version" { From e5f3398d60914a6886510053cc92f5fdfbeb2cb2 Mon Sep 17 00:00:00 2001 From: Marc Smith Date: Thu, 16 Sep 2021 16:47:01 -0700 Subject: [PATCH 8/8] Added profile variable to module --- CONTRIBUTING.md | 1 + main.tf | 1 + modules/cluster/variables.tf | 6 ++++++ 3 files changed, 8 insertions(+) diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md index 1acb056..a6b04fa 100644 --- a/CONTRIBUTING.md +++ b/CONTRIBUTING.md @@ -29,6 +29,7 @@ We use GitHub issues to track public bugs. Report a bug by opening a new issue h ## Run make test to test your infrastructure after running Terraform ```shell +$ make lint # runs the linter $ make test # runs terratest tests against your currently connected AWS account. ``` diff --git a/main.tf b/main.tf index 11900db..f39c65c 100644 --- a/main.tf +++ b/main.tf @@ -96,6 +96,7 @@ module "cluster" { tls_cert = var.tls_cert tls_key = var.tls_key local-exec-interpreter = var.local-exec-interpreter + profile = var.profile } // ---------------------------------------------------------------------------- diff --git a/modules/cluster/variables.tf b/modules/cluster/variables.tf index 1909ab0..27ecb39 100644 --- a/modules/cluster/variables.tf +++ b/modules/cluster/variables.tf @@ -13,6 +13,12 @@ variable "cluster_version" { type = string } +variable "profile" { + description = "The AWS Profile used to provision the EKS Cluster" + type = string + default = null +} + # Worker Nodes variable "desired_node_count" { type = number