-
Notifications
You must be signed in to change notification settings - Fork 29
/
resource_groups.tf
49 lines (41 loc) · 1.6 KB
/
resource_groups.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
##############################################################################
# Create new resource groups and reference existing groups
##############################################################################
data "ibm_resource_group" "resource_groups" {
for_each = {
for group in var.resource_groups :
(group.name) => group if group.create != true
}
name = each.value.use_prefix == true ? "${var.prefix}-${each.key}" : each.key
}
resource "ibm_resource_group" "resource_groups" {
for_each = {
for group in var.resource_groups :
(group.name) => group if group.create == true
}
name = each.value.use_prefix == true ? "${var.prefix}-${each.key}" : each.key
tags = var.tags
}
##############################################################################
##############################################################################
# Create a local map with resource group names as keys and ids as values
# Functionally the same as cos function to do the same
##############################################################################
locals {
resource_groups_info = merge(
{
for group in data.ibm_resource_group.resource_groups :
group.name => group.id
},
{
for group in ibm_resource_group.resource_groups :
group.name => group.id
}
)
# if use_prefix is true, strip off the prefix
resource_groups = {
for group in var.resource_groups :
group.name => local.resource_groups_info[group.use_prefix == true ? "${var.prefix}-${group.name}" : group.name]
}
}
##############################################################################