Skip to content

Commit 7d513bf

Browse files
authored
Merge pull request #8 from SPHTech-Platform/fix/custom-assumable-role
disable the iam-assuable-role and used resource to create it
2 parents d6add79 + 29b3a2c commit 7d513bf

File tree

4 files changed

+21
-15
lines changed

4 files changed

+21
-15
lines changed

Diff for: README.md

+2-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,6 @@
1616

1717
| Name | Source | Version |
1818
|------|--------|---------|
19-
| <a name="module_aqua_cspm_role"></a> [aqua\_cspm\_role](#module\_aqua\_cspm\_role) | terraform-aws-modules/iam/aws//modules/iam-assumable-role | ~> 5.9.0 |
2019
| <a name="module_kms"></a> [kms](#module\_kms) | terraform-aws-modules/kms/aws | ~> 1.5.0 |
2120
| <a name="module_lambda"></a> [lambda](#module\_lambda) | terraform-aws-modules/lambda/aws | ~> 4.10.1 |
2221
| <a name="module_lambda_role"></a> [lambda\_role](#module\_lambda\_role) | terraform-aws-modules/iam/aws//modules/iam-assumable-role | ~> 5.9.0 |
@@ -27,6 +26,8 @@
2726
|------|------|
2827
| [aws_iam_policy.aqua_cspm_lambda](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
2928
| [aws_iam_policy.aqua_cspm_supplemental](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource |
29+
| [aws_iam_role.aqua_cspm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
30+
| [aws_iam_role_policy_attachment.aqua_cspm](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
3031
| [aws_lambda_invocation.external_id](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_invocation) | resource |
3132
| [aws_lambda_invocation.onboarding](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/lambda_invocation) | resource |
3233
| [aws_secretsmanager_secret.aqua_cspm_secret](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/secretsmanager_secret) | resource |

Diff for: iam.tf

+13-13
Original file line numberDiff line numberDiff line change
@@ -32,23 +32,23 @@ resource "aws_iam_policy" "aqua_cspm_supplemental" {
3232
policy = data.aws_iam_policy_document.aqua_cspm_supplemental.json
3333
}
3434

35-
module "aqua_cspm_role" {
36-
source = "terraform-aws-modules/iam/aws//modules/iam-assumable-role"
37-
version = "~> 5.9.0"
38-
39-
create_role = true
40-
41-
role_name = "${local.name_prefix}-role"
42-
role_description = "Assumable Role of Aqua SaaS"
35+
resource "aws_iam_role" "aqua_cspm" {
36+
name = "${local.name_prefix}-role"
37+
description = "Assumable Role of Aqua SaaS"
4338

44-
custom_role_trust_policy = data.aws_iam_policy_document.aqua_cspm_custom_trust.json
39+
path = "/"
40+
max_session_duration = "3600"
4541

46-
custom_role_policy_arns = [
47-
"arn:aws:iam::aws:policy/SecurityAudit",
48-
aws_iam_policy.aqua_cspm_supplemental.arn,
49-
]
42+
assume_role_policy = data.aws_iam_policy_document.aqua_cspm_custom_trust.json
5043

5144
depends_on = [
5245
aws_lambda_invocation.external_id,
5346
]
5447
}
48+
49+
resource "aws_iam_role_policy_attachment" "aqua_cspm" {
50+
count = length(local.aqua_cspm_role_policy_arns)
51+
52+
policy_arn = element(local.aqua_cspm_role_policy_arns, count.index)
53+
role = aws_iam_role.aqua_cspm.name
54+
}

Diff for: lambda.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -36,7 +36,7 @@ resource "aws_lambda_invocation" "onboarding" {
3636
Secret = aws_secretsmanager_secret.aqua_cspm_secret.id,
3737
ExtId = local.external_id,
3838
Group = var.aqua_group_name,
39-
RoleArn = module.aqua_cspm_role.iam_role_arn,
39+
RoleArn = aws_iam_role.aqua_cspm.arn,
4040
AccId = data.aws_caller_identity.current.account_id
4141
},
4242
LogicalResourceId = "OnboardingInvoke"

Diff for: locals.tf

+5
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,9 @@ locals {
55

66
external_id = jsondecode(aws_lambda_invocation.external_id.result)["data"]
77
public_ip = "3.231.74.65/32"
8+
9+
aqua_cspm_role_policy_arns = [
10+
"arn:aws:iam::aws:policy/SecurityAudit",
11+
aws_iam_policy.aqua_cspm_supplemental.arn,
12+
]
813
}

0 commit comments

Comments
 (0)