Skip to content

Commit

Permalink
chore: initial
Browse files Browse the repository at this point in the history
  • Loading branch information
peter-svensson committed Nov 10, 2022
1 parent c8af398 commit 4cdae2f
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 2 deletions.
13 changes: 11 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,2 +1,11 @@
# tf-template
Template repository for Terraform modules
# terraform-aws-k8s-addons-aws-sso

Maps IAM Identity Center Permission Sets to Kubernetes cluster roles.

## AWS Setup
The following permission sets are used and needs to be created (when using AWS Control Tower these Permission Sets
are created automatically):
* AWSReadOnlyAccess (simplest is to use the predefined managed policy `ViewOnlyAccess`)
* AWSAdministratorAccess (simplest is to use the predefined managed policy `AdministratorAccess`)

and assign them to the AWS Account.
16 changes: 16 additions & 0 deletions main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
data "aws_iam_roles" "admin" {
name_regex = "AWSReservedSSO_AWSAdministratorAccess_.*"
path_prefix = "/aws-reserved/sso.amazonaws.com/"
}

data "aws_iam_roles" "read_only" {
name_regex = "AWSReservedSSO_AWSReadOnlyAccess_.*"
path_prefix = "/aws-reserved/sso.amazonaws.com/"
}

data "aws_caller_identity" "current" {}

locals {
admin = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${tolist(data.aws_iam_roles.admin.names)[0]}"
read_only = "arn:aws:iam::${data.aws_caller_identity.current.account_id}:role/${tolist(data.aws_iam_roles.read_only.names)[0]}"
}
14 changes: 14 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
output "iam_role_mappings" {
value = {
(local.admin) : "system:masters"
(local.read_only) : "read-only"
}
}

output "addon" {
value = {
name : "rbac-sso"
version : "0.0.1"
content : file("${path.module}/rbac.yaml")
}
}
12 changes: 12 additions & 0 deletions rbac.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
apiVersion: rbac.authorization.k8s.io/v1
kind: ClusterRoleBinding
metadata:
name: read-only
subjects:
- kind: Group
name: read-only
apiGroup: rbac.authorization.k8s.io
roleRef:
kind: ClusterRole
name: view
apiGroup: rbac.authorization.k8s.io

0 comments on commit 4cdae2f

Please sign in to comment.