Skip to content

Commit

Permalink
feat(aws-auth): aws-auth module for aws iam and kubernetes rbac mappi…
Browse files Browse the repository at this point in the history
…ng (#225)

* feat(aws-auth): aws-auth module for aws iam and kubernetes rbac mapping

* feat(aws-auth): required providers definition

* fix(aws-auth): updata aws-auth module test code
  • Loading branch information
Young-ook authored Dec 30, 2022
1 parent c89e49b commit e02dd2f
Show file tree
Hide file tree
Showing 8 changed files with 130 additions and 0 deletions.
20 changes: 20 additions & 0 deletions modules/aws-auth/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# AWS-AUTH configamp for Amazon IAM and Kubernetes RBAC mapping

```
provider "kubernetes" {
host = module.eks.kubeauth["host"]
token = module.eks.kubeauth["token"]
cluster_ca_certificate = module.eks.kubeauth["ca"]
}
### aws auth
module "aws-auth" {
source = "Young-ook/eks/aws//modules/aws-auth"
aws_auth_roles = [
{
rolearn = "role_arn_you_want_to_add"
groups = ["system:masters"]
},
]
}
```
3 changes: 3 additions & 0 deletions modules/aws-auth/defaults.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
### default variables

locals {}
5 changes: 5 additions & 0 deletions modules/aws-auth/labels.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
locals {
default-tags = merge(
{ "terraform.io" = "managed" },
)
}
26 changes: 26 additions & 0 deletions modules/aws-auth/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
## kubernetes aws-auth configmap

data "kubernetes_config_map" "aws-auth" {
metadata {
name = "aws-auth"
namespace = "kube-system"
}
}

locals {
merged_aws_auth = {
mapRoles = yamlencode(concat(yamldecode(data.kubernetes_config_map.aws-auth.data.mapRoles), var.aws_auth_roles))
mapUsers = yamlencode(var.aws_auth_users)
mapAccounts = yamlencode(var.aws_auth_accounts)
}
}

resource "kubernetes_config_map_v1_data" "aws-auth" {
depends_on = [data.kubernetes_config_map.aws-auth]
force = true
metadata {
name = "aws-auth"
namespace = "kube-system"
}
data = local.merged_aws_auth
}
6 changes: 6 additions & 0 deletions modules/aws-auth/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
### output variables

output "configmap" {
description = "Modified aws-auth configmap data"
value = local.merged_aws_auth
}
41 changes: 41 additions & 0 deletions modules/aws-auth/tests/defaults/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
terraform {
required_providers {
test = {
source = "terraform.io/builtin/test"
}
}
}

provider "kubernetes" {
alias = "aws-auth"
host = module.eks.kubeauth.host
token = module.eks.kubeauth.token
cluster_ca_certificate = module.eks.kubeauth.ca
}

### vpc
module "vpc" {
source = "Young-ook/vpc/aws"
version = "1.0.3"
}

### eks
module "eks" {
source = "Young-ook/eks/aws"
version = "2.0.0"
kubernetes_version = "1.24"
subnets = slice(values(module.vpc.subnets["public"]), 0, 3)
managed_node_groups = [
{
name = "default"
desired_size = 1
instance_type = "t3.medium"
},
]
}

module "main" {
depends_on = [module.eks]
providers = { kubernetes = kubernetes.aws-auth }
source = "../../"
}
19 changes: 19 additions & 0 deletions modules/aws-auth/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
### access control

variable "aws_auth_roles" {
description = "List of role maps to add to the aws-auth configmap"
type = list(any)
default = []
}

variable "aws_auth_users" {
description = "List of user maps to add to the aws-auth configmap"
type = list(any)
default = []
}

variable "aws_auth_accounts" {
description = "List of account maps to add to the aws-auth configmap"
type = list(any)
default = []
}
10 changes: 10 additions & 0 deletions modules/aws-auth/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
### requirements

terraform {
required_providers {
kubernetes = {
source = "hashicorp/kubernetes"
version = ">= 2.0"
}
}
}

0 comments on commit e02dd2f

Please sign in to comment.