Skip to content
This repository was archived by the owner on Jan 31, 2021. It is now read-only.

Commit ce1ace4

Browse files
authored
Add enabled var/option
* Add `enabled` var/option and generate (poorly named) cluster_id if not specified (#3) * Automated updates
1 parent cee6749 commit ce1ace4

File tree

4 files changed

+34
-10
lines changed

4 files changed

+34
-10
lines changed

README.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -80,12 +80,13 @@ Available targets:
8080

8181
| Name | Description | Type | Default | Required |
8282
|------|-------------|:----:|:-----:|:-----:|
83-
| admin_iam_role_arn | IAM Role with admin permissions to map to `admin_k8s_username` | string | - | yes |
83+
| admin_iam_role_arn | IAM Role with admin permissions to map to `admin_k8s_username` | string | `` | no |
8484
| admin_k8s_groups | List of Kubernetes groups to be mapped to `admin_iam_role_arn` | list | `<list>` | no |
8585
| admin_k8s_username | Kubernetes admin username to be mapped to `admin_iam_role_arn` | string | `` | no |
86-
| cluster_id | A unique-per-cluster identifier to prevent replay attacks. Good choices are a random token or a domain name that will be unique to your cluster | string | - | yes |
87-
| kube_config_path | Path to the kube config file. Can be sourced from `KUBE_CONFIG` or `KUBECONFIG` | string | - | yes |
88-
| readonly_iam_role_arn | IAM Role with readonly permissions to map to `readonly_k8s_username` | string | - | yes |
86+
| cluster_id | A unique-per-cluster identifier to prevent replay attacks. Good choices are a random token or a domain name that will be unique to your cluster | string | `random` | no |
87+
| enabled | Set to true to enable the module, otherwise it will not create any resources | string | `false` | no |
88+
| kube_config_path | Path to the kube config file. Can be sourced from `KUBE_CONFIG` or `KUBECONFIG` | string | `` | no |
89+
| readonly_iam_role_arn | IAM Role with readonly permissions to map to `readonly_k8s_username` | string | `` | no |
8990
| readonly_k8s_groups | List of Kubernetes groups to be mapped to `readonly_iam_role_arn` | list | `<list>` | no |
9091
| readonly_k8s_username | Kubernetes readonly username to be mapped to `readonly_iam_role_arn` | string | `` | no |
9192

docs/terraform.md

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,13 @@
22

33
| Name | Description | Type | Default | Required |
44
|------|-------------|:----:|:-----:|:-----:|
5-
| admin_iam_role_arn | IAM Role with admin permissions to map to `admin_k8s_username` | string | - | yes |
5+
| admin_iam_role_arn | IAM Role with admin permissions to map to `admin_k8s_username` | string | `` | no |
66
| admin_k8s_groups | List of Kubernetes groups to be mapped to `admin_iam_role_arn` | list | `<list>` | no |
77
| admin_k8s_username | Kubernetes admin username to be mapped to `admin_iam_role_arn` | string | `` | no |
8-
| cluster_id | A unique-per-cluster identifier to prevent replay attacks. Good choices are a random token or a domain name that will be unique to your cluster | string | - | yes |
9-
| kube_config_path | Path to the kube config file. Can be sourced from `KUBE_CONFIG` or `KUBECONFIG` | string | - | yes |
10-
| readonly_iam_role_arn | IAM Role with readonly permissions to map to `readonly_k8s_username` | string | - | yes |
8+
| cluster_id | A unique-per-cluster identifier to prevent replay attacks. Good choices are a random token or a domain name that will be unique to your cluster | string | `random` | no |
9+
| enabled | Set to true to enable the module, otherwise it will not create any resources | string | `false` | no |
10+
| kube_config_path | Path to the kube config file. Can be sourced from `KUBE_CONFIG` or `KUBECONFIG` | string | `` | no |
11+
| readonly_iam_role_arn | IAM Role with readonly permissions to map to `readonly_k8s_username` | string | `` | no |
1112
| readonly_k8s_groups | List of Kubernetes groups to be mapped to `readonly_iam_role_arn` | list | `<list>` | no |
1213
| readonly_k8s_username | Kubernetes readonly username to be mapped to `readonly_iam_role_arn` | string | `` | no |
1314

main.tf

Lines changed: 14 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,18 @@
1+
resource "random_pet" "cluster" {
2+
count = "${var.enabled == "true" ? 1 : 0}"
3+
length = 4
4+
5+
keepers = {
6+
admin_iam_role_arn = "${var.admin_iam_role_arn}"
7+
readonly_iam_role_arn = "${var.readonly_iam_role_arn}"
8+
}
9+
}
10+
111
data "template_file" "config" {
212
template = "${file("${path.module}/config.tpl")}"
313

414
vars {
5-
cluster_id = "${var.cluster_id}"
15+
cluster_id = "${var.cluster_id == "random" ? element(concat(random_pet.cluster.*.id, list("")), 0) : var.cluster_id}"
616
admin_iam_role_arn = "${var.admin_iam_role_arn}"
717
admin_k8s_username = "${var.admin_k8s_username}"
818
admin_k8s_groups = "${jsonencode(var.admin_k8s_groups)}"
@@ -16,12 +26,14 @@ data "template_file" "config" {
1626
# https://www.terraform.io/docs/providers/kubernetes/index.html
1727
provider "kubernetes" {
1828
config_path = "${var.kube_config_path}"
19-
load_config_file = true
29+
load_config_file = "${var.enabled == "true"}"
2030
}
2131

2232
# https://github.com/kubernetes/kops/blob/master/docs/authentication.md
2333
# https://github.com/kubernetes-sigs/aws-iam-authenticator
2434
resource "kubernetes_config_map" "aws_iam_authenticator" {
35+
count = "${var.enabled == "true" ? 1 : 0}"
36+
2537
metadata {
2638
name = "aws-iam-authenticator"
2739
namespace = "kube-system"

variables.tf

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,25 @@
1+
variable "enabled" {
2+
type = "string"
3+
description = "Set to true to enable the module, otherwise it will not create any resources"
4+
default = "false"
5+
}
6+
17
variable "cluster_id" {
28
type = "string"
39
description = "A unique-per-cluster identifier to prevent replay attacks. Good choices are a random token or a domain name that will be unique to your cluster"
10+
default = "random"
411
}
512

613
variable "kube_config_path" {
714
type = "string"
815
description = "Path to the kube config file. Can be sourced from `KUBE_CONFIG` or `KUBECONFIG`"
16+
default = ""
917
}
1018

1119
variable "admin_iam_role_arn" {
1220
type = "string"
1321
description = "IAM Role with admin permissions to map to `admin_k8s_username`"
22+
default = ""
1423
}
1524

1625
variable "admin_k8s_username" {
@@ -28,6 +37,7 @@ variable "admin_k8s_groups" {
2837
variable "readonly_iam_role_arn" {
2938
type = "string"
3039
description = "IAM Role with readonly permissions to map to `readonly_k8s_username`"
40+
default = ""
3141
}
3242

3343
variable "readonly_k8s_username" {

0 commit comments

Comments
 (0)