mirror of
https://github.com/ysoftdevs/terraform-aws-eks.git
synced 2026-03-11 21:11:32 +01:00
initial commit
This commit is contained in:
49
aws_auth.tf
49
aws_auth.tf
@@ -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)}"
|
||||
}
|
||||
}
|
||||
|
||||
8
data.tf
8
data.tf
@@ -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)}"
|
||||
|
||||
1
templates/config-map-aws-auth-map_accounts.yaml.tpl
Normal file
1
templates/config-map-aws-auth-map_accounts.yaml.tpl
Normal file
@@ -0,0 +1 @@
|
||||
- "${account_number}"
|
||||
4
templates/config-map-aws-auth-map_roles.yaml.tpl
Normal file
4
templates/config-map-aws-auth-map_roles.yaml.tpl
Normal file
@@ -0,0 +1,4 @@
|
||||
- rolearn: ${role_arn}
|
||||
username: ${username}
|
||||
groups:
|
||||
- ${group}
|
||||
4
templates/config-map-aws-auth-map_users.yaml.tpl
Normal file
4
templates/config-map-aws-auth-map_users.yaml.tpl
Normal file
@@ -0,0 +1,4 @@
|
||||
- userarn: ${user_arn}
|
||||
username: ${username}
|
||||
groups:
|
||||
- ${group}
|
||||
@@ -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}
|
||||
|
||||
18
variables.tf
18
variables.tf
@@ -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"
|
||||
|
||||
Reference in New Issue
Block a user