Skip to content

Commit

Permalink
feat: Enable overriding descriptions for individual service accounts (#…
Browse files Browse the repository at this point in the history
…41)

* Add `descriptions` variable allowing indiviual service account description overrides

* Update main.tf

Index doesn't take sets and sets are unordered so swapping to use the original name list. Also changed from `> x - 1` to `>= x` since it seems easier to read.
  • Loading branch information
roscoejp authored Mar 16, 2021
1 parent d5c98f0 commit 9abb768
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -43,7 +43,8 @@ Functional examples are included in the
| Name | Description | Type | Default | Required |
|------|-------------|------|---------|:--------:|
| billing\_account\_id | If assigning billing role, specificy a billing account (default is to assign at the organizational level). | `string` | `""` | no |
| description | Descriptions of the created service accounts (defaults to no description) | `string` | `""` | no |
| description | Default description of the created service accounts (defaults to no description) | `string` | `""` | no |
| descriptions | List of descriptions for the created service accounts (elements default to the value of `description`) | `list(string)` | `[]` | no |
| display\_name | Display names of the created service accounts (defaults to 'Terraform-managed service account') | `string` | `"Terraform-managed service account"` | no |
| generate\_keys | Generate keys for service accounts. | `bool` | `false` | no |
| grant\_billing\_role | Grant billing user role. | `bool` | `false` | no |
Expand Down
2 changes: 1 addition & 1 deletion main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ resource "google_service_account" "service_accounts" {
for_each = local.names
account_id = "${local.prefix}${lower(each.value)}"
display_name = var.display_name
description = var.description
description = index(var.names, each.value) >= length(var.descriptions) ? var.description : element(var.descriptions, index(var.names, each.value))
project = var.project_id
}

Expand Down
8 changes: 7 additions & 1 deletion variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,12 @@ variable "display_name" {

variable "description" {
type = string
description = "Descriptions of the created service accounts (defaults to no description)"
description = "Default description of the created service accounts (defaults to no description)"
default = ""
}

variable "descriptions" {
type = list(string)
description = "List of descriptions for the created service accounts (elements default to the value of `description`)"
default = []
}

0 comments on commit 9abb768

Please sign in to comment.