Last active
July 7, 2022 13:55
-
-
Save r8or0pz/f6c7f1005d6b00c80a17f1446ec7592b to your computer and use it in GitHub Desktop.
This file contains hidden or 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
# iam_policy_statements = { | |
# MountTarget = { | |
# effect = "Allow" | |
# principals = [ | |
# { | |
# "type" = "AWS", | |
# "identifiers" = ["*"], | |
# } | |
# ] | |
# actions = [ | |
# "elasticfilesystem:ClientRootAccess", | |
# "elasticfilesystem:ClientWrite", | |
# "elasticfilesystem:ClientMount", | |
# "elasticfilesystem:Describe*", | |
# ], | |
# resources = [ | |
# "arn:aws:elasticfilesystem:us-west-2:897347678622:file-system/fs-*" | |
# ] | |
# conditions = [ | |
# { | |
# "test" = "Bool", | |
# "variable" = "elasticfilesystem:AccessedViaMountTarget", | |
# "values" = [ | |
# "true" | |
# ], | |
# } | |
# ] | |
# } | |
# AccessPoint = { | |
# effect = "Allow" | |
# principals = [ | |
# { | |
# "type" = "AWS", | |
# "identifiers" = [ | |
# "arn:aws:iam::119428626494:root" | |
# ], | |
# } | |
# ] | |
# actions = [ | |
# "elasticfilesystem:ClientWrite", | |
# "elasticfilesystem:ClientMount", | |
# "elasticfilesystem:Describe*", | |
# ], | |
# resources = [ | |
# "arn:aws:elasticfilesystem:us-west-2:*:file-system/fs-*" | |
# ] | |
# conditions = [ | |
# { | |
# "test" = "StringEquals", | |
# "variable" = "elasticfilesystem:AccessPointArn", | |
# "values" = [ | |
# "arn:aws:elasticfilesystem:us-west-2:*:access-point/fsap-*" | |
# ], | |
# } | |
# ] | |
# } | |
# DescribeAccess = { | |
# effect = "Allow" | |
# principals = [ | |
# { | |
# "type" = "AWS", | |
# "identifiers" = [ | |
# "arn:aws:iam::119428626494:root" | |
# ], | |
# } | |
# ] | |
# actions = [ | |
# "elasticfilesystem:Describe*", | |
# ], | |
# resources = [ | |
# "arn:aws:elasticfilesystem:us-west-2:*:file-system/fs-*" | |
# ] | |
# } | |
# } | |
resource "aws_efs_file_system_policy" "policy" { | |
file_system_id = aws_efs_file_system.efs.id | |
count = length(var.iam_policy_statements) > 0 ? 1 : 0 | |
policy = join("", data.aws_iam_policy_document.efs.*.json) | |
} | |
data "aws_iam_policy_document" "efs" { | |
count = length(var.iam_policy_statements) > 0 ? 1 : 0 | |
dynamic "statement" { | |
for_each = try(flatten(var.iam_policy_statements), var.iam_policy_statements) | |
content { | |
sid = lookup(statement.value, "sid", statement.key) | |
effect = lookup(statement.value, "effect", null) | |
actions = lookup(statement.value, "actions", null) | |
resources = lookup(statement.value, "resources", null) | |
dynamic "principals" { | |
for_each = lookup(statement.value, "principals", []) | |
content { | |
type = principals.value.type | |
identifiers = principals.value.identifiers | |
} | |
} | |
dynamic "condition" { | |
for_each = lookup(statement.value, "conditions", []) | |
content { | |
test = condition.value.test | |
variable = condition.value.variable | |
values = condition.value.values | |
} | |
} | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment