Skip to content

Commit

Permalink
Merge pull request #5 from mineiros-io/sameh-service-account
Browse files Browse the repository at this point in the history
feat: adding iam to the module
  • Loading branch information
mariux authored Oct 19, 2021
2 parents ef9afee + 4f1ad5f commit b8dc2eb
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 0 deletions.
24 changes: 24 additions & 0 deletions iam.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
locals {
iam_map = var.policy_bindings == null ? { for iam in var.iam : iam.role => iam } : tomap({})

policy_bindings = var.policy_bindings != null ? {
iam_policy = {
policy_bindings = var.policy_bindings
}
} : tomap({})
}

module "iam" {
source = "github.com/mineiros-io/terraform-google-service-account-iam.git?ref=v0.0.1"

for_each = var.policy_bindings != null ? local.policy_bindings : local.iam_map

module_enabled = var.module_enabled
module_depends_on = var.module_depends_on

service_account_id = google_service_account.service_account[0].name
role = try(each.value.role, null)
members = try(each.value.members, null)
authoritative = try(each.value.authoritative, true)
policy_bindings = try(each.value.policy_bindings, null)
}
6 changes: 6 additions & 0 deletions outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,12 @@ output "precomputed_email" {

}

# remap iam to reduce one level of access (iam[]. instead of iam[].iam.)
output "iam" {
description = "The iam resource objects that define the access to the secret"
value = { for key, iam in module.iam : key => iam.iam }
}

# ------------------------------------------------------------------------------
# OUTPUT ALL RESOURCES AS FULL OBJECTS
# ------------------------------------------------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,20 @@ variable "organization_access" {
default = {}
}

## IAM

variable "iam" {
description = "(Optional) A list of IAM access."
type = any
default = []
}

variable "policy_bindings" {
description = "(Optional) A list of IAM policy bindings."
type = any
default = null
}

# ------------------------------------------------------------------------------
# MODULE CONFIGURATION PARAMETERS
# These variables are used to configure the module.
Expand Down

0 comments on commit b8dc2eb

Please sign in to comment.