Add new variable for flexibility between project id & name (#287)

* add new variable for flexibility between project id & name

* remove random feature & use new variable

* remove project_id variable & use local descriptive name variable

* fix bad project_id output & avoid confusing name

* update readme

* Update main.tf

Co-authored-by: slaheddine_bejaoui.ext <slaheddine_bejaoui.ext@orange.com>
Co-authored-by: Ludovico Magnocavallo <ludo@qix.it>
This commit is contained in:
sly92 2021-07-28 18:08:51 +02:00 committed by GitHub
parent 1c6707b982
commit 804ce9bdc4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 10 additions and 1 deletions

View File

@ -183,6 +183,7 @@ module "project" {
| *billing_account* | Billing account id. | <code title="">string</code> | | <code title="">null</code> |
| *contacts* | List of essential contacts for this resource. Must be in the form EMAIL -> [NOTIFICATION_TYPES]. Valid notification types are ALL, SUSPENSION, SECURITY, TECHNICAL, BILLING, LEGAL, PRODUCT_UPDATES | <code title="map&#40;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |
| *custom_roles* | Map of role name => list of permissions to create in this project. | <code title="map&#40;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |
| *descriptive_name* | Name of the project name. Used for project name instead of `name` variable | <code title="">string</code> | | <code title="">null</code> |
| *group_iam* | Authoritative IAM binding for organization groups, in {GROUP_EMAIL => [ROLES]} format. Group emails need to be static. Can be used in combination with the `iam` variable. | <code title="map&#40;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |
| *iam* | IAM bindings in {ROLE => [MEMBERS]} format. | <code title="map&#40;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |
| *iam_additive* | IAM additive bindings in {ROLE => [MEMBERS]} format. | <code title="map&#40;list&#40;string&#41;&#41;">map(list(string))</code> | | <code title="">{}</code> |

View File

@ -15,6 +15,7 @@
*/
locals {
descriptive_name = var.descriptive_name != null ? var.descriptive_name : "${local.prefix}${var.name}"
group_iam_roles = distinct(flatten(values(var.group_iam)))
group_iam = {
for r in local.group_iam_roles : r => [
@ -75,6 +76,7 @@ locals {
])
}
data "google_project" "project" {
count = var.project_create ? 0 : 1
project_id = "${local.prefix}${var.name}"
@ -85,7 +87,7 @@ resource "google_project" "project" {
org_id = local.parent_type == "organizations" ? local.parent_id : null
folder_id = local.parent_type == "folders" ? local.parent_id : null
project_id = "${local.prefix}${var.name}"
name = "${local.prefix}${var.name}"
name = "${local.descriptive_name}"
billing_account = var.billing_account
auto_create_network = var.auto_create_network
labels = var.labels

View File

@ -215,3 +215,9 @@ variable "service_perimeter_bridges" {
type = list(string)
default = null
}
variable "descriptive_name" {
description = "Name of the project name. Used for project name instead of `name` variable"
type = string
default = null
}