initial commit

This commit is contained in:
Max Williams
2018-07-06 16:31:55 +02:00
parent 3c4e28e8a7
commit 58c4a0e30f
7 changed files with 79 additions and 12 deletions

View File

@@ -1,17 +1,60 @@
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}"
count = "${var.configure_kubectl_session ? 1 : 0}"
}
resource "null_resource" "update_config_map_aws_auth" {
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}"
count = "${var.configure_kubectl_session ? 1 : 0}"
}
data "template_file" "config_map_aws_auth" {
template = "${file("${path.module}/templates/config-map-aws-auth.yaml.tpl")}"
vars {
worker_role_arn = "${aws_iam_role.workers.arn}"
map_users = "${join("", data.template_file.map_users.*.rendered)}"
map_roles = "${join("", data.template_file.map_roles.*.rendered)}"
map_accounts = "${join("", data.template_file.map_accounts.*.rendered)}"
}
}
data "template_file" "map_users" {
count = "${length(var.map_users)}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_users.yaml.tpl")}"
vars {
user_arn = "${lookup(var.map_users[count.index], "user_arn")}"
username = "${lookup(var.map_users[count.index], "username")}"
group = "${lookup(var.map_users[count.index], "group")}"
}
}
data "template_file" "map_roles" {
count = "${length(var.map_roles)}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_roles.yaml.tpl")}"
vars {
role_arn = "${lookup(var.map_roles[count.index], "role_arn")}"
username = "${lookup(var.map_roles[count.index], "username")}"
group = "${lookup(var.map_roles[count.index], "group")}"
}
}
data "template_file" "map_accounts" {
count = "${length(var.map_accounts)}"
template = "${file("${path.module}/templates/config-map-aws-auth-map_accounts.yaml.tpl")}"
vars {
account_number = "${element(var.map_accounts, count.index)}"
}
}

View File

@@ -73,14 +73,6 @@ EOF
}
}
data "template_file" "config_map_aws_auth" {
template = "${file("${path.module}/templates/config-map-aws-auth.yaml.tpl")}"
vars {
role_arn = "${aws_iam_role.workers.arn}"
}
}
data "template_file" "userdata" {
template = "${file("${path.module}/templates/userdata.sh.tpl")}"
count = "${length(var.worker_groups)}"

View File

@@ -0,0 +1 @@
- "${account_number}"

View File

@@ -0,0 +1,4 @@
- rolearn: ${role_arn}
username: ${username}
groups:
- ${group}

View File

@@ -0,0 +1,4 @@
- userarn: ${user_arn}
username: ${username}
groups:
- ${group}

View File

@@ -5,8 +5,13 @@ metadata:
namespace: kube-system
data:
mapRoles: |
- rolearn: ${role_arn}
- rolearn: ${worker_role_arn}
username: system:node:{{EC2PrivateDNSName}}
groups:
- system:bootstrappers
- system:nodes
${map_roles}
mapUsers: |
${map_users}
mapAccounts: |
${map_accounts}

View File

@@ -32,6 +32,24 @@ variable "manage_aws_auth" {
default = true
}
variable "map_accounts" {
description = "Additional AWS account numbers to add to the aws-auth configmap"
type = "list"
default = []
}
variable "map_roles" {
description = "Additional IAM roles to add to the aws-auth configmap"
type = "list"
default = []
}
variable "map_users" {
description = "Additional IAM users to add to the aws-auth configmap"
type = "list"
default = []
}
variable "subnets" {
description = "A list of subnets to place the EKS cluster and workers within."
type = "list"