diff --git a/examples/camunda-8.6-irsa/db.tf b/examples/camunda-8.6-irsa/db.tf index 6f9d5e0..e675ada 100644 --- a/examples/camunda-8.6-irsa/db.tf +++ b/examples/camunda-8.6-irsa/db.tf @@ -42,11 +42,11 @@ module "postgresql" { instance_class = "db.t3.medium" # IAM IRSA - iam_roles_with_policies = < role } -} - -// IAM Role for Aurora +// IAM Role resource "aws_iam_role" "roles" { - for_each = local.roles_map + for_each = { for idx, role in var.iam_roles_with_policies : role.role_name => role } name = each.key assume_role_policy = each.value.trust_policy } -// IAM Policy for Aurora Access +// IAM Policy for Access resource "aws_iam_policy" "access_policies" { - for_each = local.roles_map + for_each = { for idx, role in var.iam_roles_with_policies : role.role_name => role } name = "${each.key}-access-policy" description = "Access policy for ${each.key}" @@ -23,7 +18,7 @@ resource "aws_iam_policy" "access_policies" { // Attach the policy to the role resource "aws_iam_role_policy_attachment" "attach_policies" { - for_each = local.roles_map + for_each = { for idx, role in var.iam_roles_with_policies : role.role_name => role } role = aws_iam_role.roles[each.key].name policy_arn = aws_iam_policy.access_policies[each.key].arn diff --git a/modules/opensearch/role.tf b/modules/opensearch/role.tf index 6be5377..bd36688 100644 --- a/modules/opensearch/role.tf +++ b/modules/opensearch/role.tf @@ -1,19 +1,14 @@ -// Convert the list to a map by using the role_name as the key -locals { - roles_map = { for role in var.iam_roles_with_policies : role.role_name => role } -} - -// IAM Role for OpenSearch +// IAM Role resource "aws_iam_role" "roles" { - for_each = local.roles_map + for_each = { for idx, role in var.iam_roles_with_policies : role.role_name => role } name = each.key assume_role_policy = each.value.trust_policy } -// IAM Policy for OpenSearch +// IAM Policy for Access resource "aws_iam_policy" "access_policies" { - for_each = local.roles_map + for_each = { for idx, role in var.iam_roles_with_policies : role.role_name => role } name = "${each.key}-access-policy" description = "Access policy for ${each.key}" @@ -23,8 +18,8 @@ resource "aws_iam_policy" "access_policies" { // Attach the policy to the role resource "aws_iam_role_policy_attachment" "attach_policies" { - for_each = local.roles_map + for_each = { for idx, role in var.iam_roles_with_policies : role.role_name => role } role = aws_iam_role.roles[each.key].name policy_arn = aws_iam_policy.access_policies[each.key].arn -} +} \ No newline at end of file diff --git a/test/src/custom_eks_opensearch_test.go b/test/src/custom_eks_opensearch_test.go index 800ab3b..03b285c 100644 --- a/test/src/custom_eks_opensearch_test.go +++ b/test/src/custom_eks_opensearch_test.go @@ -208,11 +208,11 @@ func (suite *CustomEKSOpenSearchTestSuite) TestCustomEKSAndOpenSearch() { ] }`, accountId, oidcProviderID, oidcProviderID, openSearchNamespace, openSearchServiceAccount) - iamRolesWithPolicies := fmt.Sprintf(`[ - "role_name": %s, - "trust_policy": %s, - "access_policy": %s - ]`, openSearchRole, iamRoleTrustPolicy, openSearchAccessPolicy) + iamRolesWithPolicies = map[string]interface{}{ + "role_name": openSearchRole, + "trust_policy": iamRoleTrustPolicy, + "access_policy": openSearchAccessPolicy, + } varsConfigOpenSearch := map[string]interface{}{ "domain_name": opensearchDomainName, diff --git a/test/src/custom_eks_rds_test.go b/test/src/custom_eks_rds_test.go index 85c324f..a334c56 100644 --- a/test/src/custom_eks_rds_test.go +++ b/test/src/custom_eks_rds_test.go @@ -212,12 +212,11 @@ func (suite *CustomEKSRDSTestSuite) TestCustomEKSAndRDS() { ] }`, accountId, oidcProviderID, oidcProviderID, auroraNamespace, auroraServiceAccount) - iamRolesWithPolicies := fmt.Sprintf(`[ - "role_name": %s, - "trust_policy": %s, - "access_policy": %s - ]`, auroraRole, iamRoleTrustPolicy, openSearchAccessPolicy) - + iamRolesWithPolicies = map[string]interface{}{ + "role_name": auroraRole, + "trust_policy": iamRoleTrustPolicy, + "access_policy": auroraAccessPolicy, + } varsConfigAurora := map[string]interface{}{ "username": auroraUsername,