Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add source role arns #423

Merged
merged 2 commits into from
Sep 19, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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