File tree Expand file tree Collapse file tree 4 files changed +106
-0
lines changed
Expand file tree Collapse file tree 4 files changed +106
-0
lines changed Original file line number Diff line number Diff line change 1+ locals {
2+ roles = [{
3+ rolearn = var.nodes_role
4+ username = " system:node:{{EC2PrivateDNSName}}"
5+ groups = [
6+ " system:bootstrappers" ,
7+ " system:nodes"
8+ ]
9+ }]
10+
11+ master_roles = [
12+ for role_arn in var . master_roles :
13+ {
14+ rolearn = role_arn
15+ username = role_arn
16+ groups = [
17+ " system:masters"
18+ ]
19+ }
20+
21+ ]
22+
23+ users = [
24+ for user_obj in var . master_users :
25+ {
26+ userarn = user_obj.arn
27+ username = user_obj.username
28+ groups = [
29+ " system:masters"
30+ ]
31+ }
32+ ]
33+ }
34+
35+ resource "kubernetes_config_map" "aws_auth" {
36+ metadata {
37+ // The name of the ConfigMap needs to be `aws-auth`, as specified by AWS.
38+ // For more info, please see here: https://docs.aws.amazon.com/eks/latest/userguide/add-user-role.html
39+ name = " aws-auth"
40+ namespace = " kube-system"
41+ labels = merge (
42+ {
43+ " app.kubernetes.io/managed-by" = " Terraform"
44+ " terraform.io/module" = " github.com/koslib/terraform-aws-eks-auth"
45+ }
46+ )
47+ }
48+
49+ data = {
50+ mapRoles = yamlencode (concat (local. roles , local. master_roles ))
51+ mapUsers = yamlencode (local. users )
52+ }
53+
54+ }
Original file line number Diff line number Diff line change 1+ data "aws_eks_cluster" "default" {
2+ name = var. cluster_name
3+ }
4+
5+ data "aws_eks_cluster_auth" "default" {
6+ name = var. cluster_name
7+ }
8+
9+ provider "aws" {
10+ region = var. aws_region
11+ profile = var. aws_profile
12+ }
13+
14+ provider "kubernetes" {
15+ host = data. aws_eks_cluster . default . endpoint
16+ cluster_ca_certificate = base64decode (data. aws_eks_cluster . default . certificate_authority [0 ]. data )
17+ token = data. aws_eks_cluster_auth . default . token
18+ }
Original file line number Diff line number Diff line change 1+ variable "cluster_name" {
2+ type = string
3+ description = " The cluster to apply the auth config on."
4+ }
5+
6+ variable "aws_region" {
7+ type = string
8+ description = " Your cluster's AWS region."
9+ }
10+
11+ variable "aws_profile" {
12+ type = string
13+ default = " default"
14+ description = " In case you use multiple AWS profiles, specify which one to use here. Defaults to `default`."
15+ }
16+
17+ variable "nodes_role" {
18+ type = string
19+ description = " The role that was created while provisioning the cluster and should be used by EC2 instances to interact with the cluster."
20+ }
21+
22+ variable "master_users" {
23+ type = list (object ({
24+ username = string
25+ arn = string
26+ }))
27+ description = " List of user objects that will have master permissions on the cluster. Object consists of username and ARN (strings)."
28+ }
29+
30+ variable "master_roles" {
31+ type = list (string )
32+ default = []
33+ description = " List of IAM role ARNs that will have master permissions on the cluster."
34+ }
You can’t perform that action at this time.
0 commit comments