-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #12 from kabisa/task/refactor_ci_cd_role
Change role creation for CI CD. Current role has always admin, poweru…
- Loading branch information
Showing
4 changed files
with
103 additions
and
26 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -4,6 +4,53 @@ Creates predefined IAM roles (admin, poweruser and readonly) which can be assume | |
|
||
Trusted resources can be any [IAM ARNs](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_identifiers.html#identifiers-arns) - typically, AWS accounts and users. | ||
|
||
``` | ||
module "iam-roles" { | ||
source = "[email protected]:kabisa/terraform-iam-assumable-roles.git?ref=[version]" | ||
trusted_role_arns = [ | ||
"arn:aws:iam::${local.dovetail-iam}:root", | ||
"arn:aws:iam::${local.kabisa-iam}:root", | ||
] | ||
create_ci_cd_role = true | ||
trusted_roles_ci_cd = [ | ||
"arn:aws:iam::{[account-id]}:role/github_actions_role", | ||
] | ||
ci_cd_role_managed_policies = [ | ||
"arn:aws:iam::aws:policy/AmazonSSMFullAccess", | ||
"arn:aws:iam::aws:policy/AmazonEC2FullAccess" | ||
] | ||
ci_cd_role_inline_policies = { | ||
"example_inline_policy" : data.aws_iam_policy_document.example.json, | ||
"example2" : data.aws_iam_policy_document.example2.json | ||
} | ||
create_admin_role = true | ||
create_poweruser_role = true | ||
create_readonly_role = true | ||
} | ||
data "aws_iam_policy_document" "example" { | ||
statement { | ||
actions = ["ssm:*", "ec2:*"] | ||
effect = "Allow" | ||
resources = ["*"] | ||
} | ||
} | ||
data "aws_iam_policy_document" "example2" { | ||
statement { | ||
actions = ["s3:*"] | ||
effect = "Allow" | ||
resources = ["*"] | ||
} | ||
} | ||
``` | ||
|
||
<!-- BEGINNING OF PRE-COMMIT-TERRAFORM DOCS HOOK --> | ||
|
||
## Inputs | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
resource "aws_iam_role" "ci_cd_iam_role" { | ||
count = var.create_ci_cd_role ? 1 : 0 | ||
|
||
name = "ci_cd_access_role" | ||
assume_role_policy = data.aws_iam_policy_document.ci_cd_policy_document[0].json | ||
managed_policy_arns = var.ci_cd_role_managed_policies | ||
|
||
dynamic "inline_policy" { | ||
for_each = var.ci_cd_role_inline_policies | ||
|
||
content { | ||
name = inline_policy.key | ||
policy = inline_policy.value | ||
} | ||
} | ||
} | ||
|
||
data "aws_iam_policy_document" "ci_cd_policy_document" { | ||
count = var.create_ci_cd_role ? 1 : 0 | ||
|
||
statement { | ||
actions = ["sts:AssumeRole"] | ||
principals { | ||
type = "AWS" | ||
identifiers = var.trusted_roles_ci_cd | ||
} | ||
} | ||
} | ||
|
||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters