Skip to content

Commit

Permalink
feat: add source role arns (#423)
Browse files Browse the repository at this point in the history
* adding source role arns to trust policies
  • Loading branch information
abiju-czi authored Sep 19, 2022
1 parent 793bbcc commit 965da8f
Show file tree
Hide file tree
Showing 6 changed files with 27 additions and 0 deletions.
11 changes: 11 additions & 0 deletions aws-assume-role-policy/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,17 @@ data "aws_iam_policy_document" "assume-role" {
}
}

dynamic "statement" {
for_each = var.source_role_arns
content {
principals {
type = "AWS"
identifiers = [statement.value]
}
actions = ["sts:AssumeRole", "sts:TagSession"]
}
}

dynamic "statement" {
for_each = var.saml_idp_arns

Expand Down
2 changes: 2 additions & 0 deletions aws-assume-role-policy/module_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import (
"fmt"
"testing"

"github.com/chanzuckerberg/go-misc/tftest"
Expand All @@ -24,6 +25,7 @@ func TestAWSAssumeRolePolicy(t *testing.T) {
tftest.IAMRegion,
map[string]interface{}{
"source_account_ids": []string{curAcct},
"source_role_arns": []string{fmt.Sprintf("arn:aws:iam::%s:role/okta-czi-admin", curAcct)},
"saml_idp_arns": []string{"samlARN1", "samlARN2"},
"oidc": oidcCfg,
},
Expand Down
5 changes: 5 additions & 0 deletions aws-assume-role-policy/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,11 @@ variable "source_account_ids" {
description = "The source AWS account IDs to establish a trust relationship. Ignored if empty or not provided."
}

variable "source_role_arns" {
type = list(string)
description = "The source AWS roles to establish a trust relationship. Ignored if empty or not provided."
}

variable "saml_idp_arns" {
type = set(string)
default = []
Expand Down
1 change: 1 addition & 0 deletions aws-iam-role-crossacct/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ module "assume_role_policy" {
source = "../aws-assume-role-policy"
source_account_ids = var.source_account_ids
saml_idp_arns = var.saml_idp_arns
source_role_arns = var.source_role_arns
oidc = var.oidc
env = var.env
owner = var.owner
Expand Down
2 changes: 2 additions & 0 deletions aws-iam-role-crossacct/module_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package test

import (
"fmt"
"testing"

"github.com/chanzuckerberg/go-misc/tftest"
Expand All @@ -20,6 +21,7 @@ func TestAWSIAMRoleCrossAcct(t *testing.T) {
map[string]interface{}{
"role_name": random.UniqueId(),
"source_account_ids": []string{curAcct},
"source_role_arns": []string{fmt.Sprintf("arn:aws:iam::%s:role/okta-czi-admin", curAcct)},
},
)
},
Expand Down
6 changes: 6 additions & 0 deletions aws-iam-role-crossacct/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,12 @@ variable "saml_idp_arns" {
description = "The AWS SAML IDP arns to establish a trust relationship. Ignored if empty or not provided."
}

variable "source_role_arns" {
type = list(string)
description = "The source AWS roles to establish a trust relationship. Ignored if empty or not provided."
default = []
}

variable "oidc" {
type = list(object(
{
Expand Down

0 comments on commit 965da8f

Please sign in to comment.