generated from oracle/template-repo
-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathiam_dynamic_groups.tf
219 lines (193 loc) · 16.7 KB
/
iam_dynamic_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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
# Copyright (c) 2023 Oracle and/or its affiliates.
# Licensed under the Universal Permissive License v 1.0 as shown at https://oss.oracle.com/licenses/upl.
locals {
#------------------------------------------------------------------------------------------------------
#-- Any of these local variables can be overriden in a _override.tf file
#------------------------------------------------------------------------------------------------------
custom_dynamic_groups_configuration = null
custom_security_fun_dyn_group_name = null
custom_appdev_fun_dyn_group_name = null
custom_appdev_computeagent_dyn_group_name = null
custom_database_kms_dyn_group_name = null
custom_net_fw_app_dyn_group_name = null
custom_dynamic_groups_defined_tags = null
custom_dynamic_groups_freeform_tags = null
}
module "lz_dynamic_groups" {
source = "github.com/oci-landing-zones/terraform-oci-modules-iam//dynamic-groups?ref=v0.2.4"
count = var.identity_domain_option == "Default Domain" ? 1 : 0
providers = { oci = oci.home }
tenancy_ocid = var.tenancy_ocid
dynamic_groups_configuration = var.extend_landing_zone_to_new_region == false && var.identity_domain_option != "Use Custom Identity Domain" ? (local.custom_dynamic_groups_configuration != null ? local.custom_dynamic_groups_configuration : local.dynamic_groups_configuration) : local.empty_dynamic_groups_configuration
}
module "lz_custom_domain_dynamic_groups" {
source = "github.com/oci-landing-zones/terraform-oci-modules-iam//identity-domains?ref=v0.2.4"
count = var.identity_domain_option == "Use Custom Identity Domain" && var.deploy_custom_domain_groups ? 1 : 0
tenancy_ocid = var.tenancy_ocid
identity_domain_dynamic_groups_configuration = var.extend_landing_zone_to_new_region == false && var.identity_domain_option == "Use Custom Identity Domain" ? (local.custom_dynamic_groups_configuration != null ? local.custom_dynamic_groups_configuration : local.custom_domain_dynamic_groups_configuration) : local.empty_dynamic_groups_configuration
}
locals {
#------------------------------------------------------------------------------------------------------
#-- These variables are not meant to be overriden
#------------------------------------------------------------------------------------------------------
#-----------------------------------------------------------
#----- Tags to apply to dynamic groups
#-----------------------------------------------------------
default_dynamic_groups_defined_tags = null
default_dynamic_groups_freeform_tags = local.landing_zone_tags
dynamic_groups_defined_tags = local.custom_dynamic_groups_defined_tags != null ? merge(local.custom_dynamic_groups_defined_tags, local.default_dynamic_groups_defined_tags) : local.default_dynamic_groups_defined_tags
dynamic_groups_freeform_tags = local.custom_dynamic_groups_freeform_tags != null ? merge(local.custom_dynamic_groups_freeform_tags, local.default_dynamic_groups_freeform_tags) : local.default_dynamic_groups_freeform_tags
#--------------------------------------------------------------------
#-- Security functions Dynamic Group
#--------------------------------------------------------------------
security_functions_dynamic_group_key = "SEC-FUN-DYNAMIC-GROUP"
default_security_functions_dynamic_group_name = "sec-fun-dynamic-group"
provided_security_functions_dynamic_group_name = coalesce(local.custom_security_fun_dyn_group_name, "${var.service_label}-${local.default_security_functions_dynamic_group_name}")
security_functions_dynamic_group = length(trimspace(var.existing_security_fun_dyn_group_name)) == 0 ? {
(local.security_functions_dynamic_group_key) = {
name = local.provided_security_functions_dynamic_group_name
description = "Core Landing Zone dynamic group for security functions execution."
matching_rule = "ALL {resource.type = 'fnfunc',resource.compartment.id = '${local.security_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
custom_domain_security_functions_dynamic_group = var.deploy_custom_domain_groups ? {
(local.security_functions_dynamic_group_key) = {
identity_domain_id = trimspace(var.custom_id_domain_ocid)
name = local.provided_security_functions_dynamic_group_name
description = "Core Landing Zone dynamic group for security functions execution."
matching_rule = "ALL {resource.type = 'fnfunc',resource.compartment.id = '${local.security_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
#--------------------------------------------------------------------
#-- AppDev functions Dynamic Group
#--------------------------------------------------------------------
appdev_functions_dynamic_group_key = "APP-FUN-DYNAMIC-GROUP"
default_appdev_functions_dynamic_group_name = "app-fun-dynamic-group"
provided_appdev_functions_dynamic_group_name = coalesce(local.custom_appdev_fun_dyn_group_name, "${var.service_label}-${local.default_appdev_functions_dynamic_group_name}")
appdev_functions_dynamic_group = length(trimspace(var.existing_appdev_fun_dyn_group_name)) == 0 ? {
(local.appdev_functions_dynamic_group_key) = {
name = local.provided_appdev_functions_dynamic_group_name
description = "Core Landing Zone dynamic group for application functions execution."
matching_rule = "ALL {resource.type = 'fnfunc',resource.compartment.id = '${local.app_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
custom_domain_appdev_functions_dynamic_group = var.deploy_custom_domain_groups ? {
(local.appdev_functions_dynamic_group_key) = {
identity_domain_id = trimspace(var.custom_id_domain_ocid)
name = local.provided_appdev_functions_dynamic_group_name
description = "Core Landing Zone dynamic group for application functions execution."
matching_rule = "ALL {resource.type = 'fnfunc',resource.compartment.id = '${local.app_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
#--------------------------------------------------------------------
#-- AppDev compute agent Dynamic Group
#--------------------------------------------------------------------
appdev_computeagent_dynamic_group_key = "APP-COMPUTEAGENT-DYNAMIC-GROUP"
default_appdev_computeagent_dynamic_group_name = "app-computeagent-dynamic-group"
provided_appdev_computeagent_dynamic_group_name = coalesce(local.custom_appdev_computeagent_dyn_group_name, "${var.service_label}-${local.default_appdev_computeagent_dynamic_group_name}")
appdev_computeagent_dynamic_group = length(trimspace(var.existing_compute_agent_dyn_group_name)) == 0 ? {
(local.appdev_computeagent_dynamic_group_key) = {
name = local.provided_appdev_computeagent_dynamic_group_name
description = "Core Landing Zone dynamic group for Compute Agent plugin execution."
matching_rule = "ALL {resource.type = 'managementagent',resource.compartment.id = '${local.app_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
custom_domain_appdev_computeagent_dynamic_group = var.deploy_custom_domain_groups ? {
(local.appdev_computeagent_dynamic_group_key) = {
identity_domain_id = trimspace(var.custom_id_domain_ocid)
name = local.provided_appdev_computeagent_dynamic_group_name
description = "Core Landing Zone dynamic group for Compute Agent plugin execution."
matching_rule = "ALL {resource.type = 'managementagent',resource.compartment.id = '${local.app_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
#--------------------------------------------------------------------
#-- Database KMS Dynamic Group
#--------------------------------------------------------------------
database_kms_dynamic_group_key = "DATABASE-KMS-DYNAMIC-GROUP"
default_database_kms_dynamic_group_name = "database-kms-dynamic-group"
provided_database_kms_dynamic_group_name = coalesce(local.custom_database_kms_dyn_group_name, "${var.service_label}-${local.default_database_kms_dynamic_group_name}")
database_kms_dynamic_group = length(trimspace(var.existing_database_kms_dyn_group_name)) == 0 ? {
(local.database_kms_dynamic_group_key) = {
name = local.provided_database_kms_dynamic_group_name
description = "Core Landing Zone dynamic group for databases accessing Key Management service (aka Vault service)."
matching_rule = "ALL {resource.compartment.id = '${local.database_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
custom_domain_database_kms_dynamic_group = var.deploy_custom_domain_groups ? {
(local.database_kms_dynamic_group_key) = {
identity_domain_id = trimspace(var.custom_id_domain_ocid)
name = local.provided_database_kms_dynamic_group_name
description = "Core Landing Zone dynamic group for databases accessing Key Management service (aka Vault service)."
matching_rule = "ALL {resource.compartment.id = '${local.database_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
#--------------------------------------------------------------------
#-- Network Firewall Appliance Dynamic Group
#--------------------------------------------------------------------
net_fw_app_dynamic_group_key = "NET-FW-APP-DYNAMIC-GROUP"
default_net_fw_app_dynamic_group_name = "net-fw-app-dynamic-group"
provided_net_fw_app_dynamic_group_name = coalesce(local.custom_net_fw_app_dyn_group_name, "${var.service_label}-${local.default_net_fw_app_dynamic_group_name}")
net_fw_app_dynamic_group = length(trimspace(var.existing_net_fw_app_dyn_group_name)) == 0 && local.firewall_options[var.hub_vcn_deploy_net_appliance_option] == "FORTINET" ? {
(local.net_fw_app_dynamic_group_key) = {
name = local.provided_net_fw_app_dynamic_group_name
description = "Core Landing Zone dynamic group for network firewall appliances."
matching_rule = "ALL {resource.compartment.id = '${local.network_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
custom_domain_net_fw_app_dynamic_group = var.deploy_custom_domain_groups && local.firewall_options[var.hub_vcn_deploy_net_appliance_option] == "FORTINET" ? {
(local.net_fw_app_dynamic_group_key) = {
identity_domain_id = trimspace(var.custom_id_domain_ocid)
name = local.provided_net_fw_app_dynamic_group_name
description = "Core Landing Zone dynamic group for network firewall appliances."
matching_rule = "ALL {resource.compartment.id = '${local.network_compartment_id}'}"
defined_tags = local.dynamic_groups_defined_tags
freeform_tags = local.dynamic_groups_freeform_tags
}
} : {}
#------------------------------------------------------------------------
#----- Dynamic groups configuration definition. Input to module.
#------------------------------------------------------------------------
dynamic_groups_configuration = {
dynamic_groups : merge(local.security_functions_dynamic_group, local.appdev_functions_dynamic_group,
local.appdev_computeagent_dynamic_group, local.database_kms_dynamic_group, local.net_fw_app_dynamic_group)
}
custom_domain_dynamic_groups_configuration = {
dynamic_groups : merge(local.custom_domain_security_functions_dynamic_group, local.custom_domain_appdev_functions_dynamic_group,
local.custom_domain_appdev_computeagent_dynamic_group, local.custom_domain_database_kms_dynamic_group, local.custom_domain_net_fw_app_dynamic_group)
}
empty_dynamic_groups_configuration = {
dynamic_groups : {}
}
all_existing_dynamic_groups = { for dg in data.oci_identity_dynamic_groups.all.dynamic_groups : dg.id => { "name" : dg.name } }
#----------------------------------------------------------------------------------------
#----- We cannot reference the module output for obtaining dynamic group names,
#----- because it creates a TF cycle issue with the compartments module that may
#----- reference the dynamic group that references the compartment in the matching
#----- clause that references the dynamic group that references the compartment that ...
#----- Hence the usage of provided_* local variables instead of the dynamic groups
#----- module output for the true case in the assignments below.
#----------------------------------------------------------------------------------------
security_functions_dynamic_group_name = var.identity_domain_option != "Use Custom Identity Domain" ? (length(trimspace(var.existing_security_fun_dyn_group_name)) == 0 ? local.provided_security_functions_dynamic_group_name : (length(regexall("^ocid1.dynamicgroup.oc.*$", var.existing_security_fun_dyn_group_name)) > 0 ? local.all_existing_dynamic_groups[var.existing_security_fun_dyn_group_name].name : var.existing_security_fun_dyn_group_name)) : var.deploy_custom_domain_groups == true ? ("'${local.custom_id_domain_name}'/'${trimspace(local.provided_security_functions_dynamic_group_name)}'") : ("'${local.custom_id_domain_name}'/'${trimspace(var.existing_id_domain_security_fun_dyn_group_name)}'")
appdev_functions_dynamic_group_name = var.identity_domain_option != "Use Custom Identity Domain" ? (length(trimspace(var.existing_appdev_fun_dyn_group_name)) == 0 ? local.provided_appdev_functions_dynamic_group_name : (length(regexall("^ocid1.dynamicgroup.oc.*$", var.existing_appdev_fun_dyn_group_name)) > 0 ? local.all_existing_dynamic_groups[var.existing_appdev_fun_dyn_group_name].name : var.existing_appdev_fun_dyn_group_name)) : var.deploy_custom_domain_groups == true ? ("'${local.custom_id_domain_name}'/'${trimspace(local.provided_appdev_functions_dynamic_group_name)}'") : ("'${local.custom_id_domain_name}'/'${trimspace(var.existing_id_domain_appdev_fun_dyn_group_name)}'")
appdev_computeagent_dynamic_group_name = var.identity_domain_option != "Use Custom Identity Domain" ? (length(trimspace(var.existing_compute_agent_dyn_group_name)) == 0 ? local.provided_appdev_computeagent_dynamic_group_name : (length(regexall("^ocid1.dynamicgroup.oc.*$", var.existing_compute_agent_dyn_group_name)) > 0 ? local.all_existing_dynamic_groups[var.existing_compute_agent_dyn_group_name].name : var.existing_compute_agent_dyn_group_name)) : var.deploy_custom_domain_groups == true ? ("'${local.custom_id_domain_name}'/'${trimspace(local.provided_appdev_computeagent_dynamic_group_name)}'") : ("'${local.custom_id_domain_name}'/'${trimspace(var.existing_id_domain_compute_agent_dyn_group_name)}'")
database_kms_dynamic_group_name = var.identity_domain_option != "Use Custom Identity Domain" ? (length(trimspace(var.existing_database_kms_dyn_group_name)) == 0 ? local.provided_database_kms_dynamic_group_name : (length(regexall("^ocid1.dynamicgroup.oc.*$", var.existing_database_kms_dyn_group_name)) > 0 ? local.all_existing_dynamic_groups[var.existing_database_kms_dyn_group_name].name : var.existing_database_kms_dyn_group_name)) : var.deploy_custom_domain_groups == true ? ("'${local.custom_id_domain_name}'/'${trimspace(local.provided_database_kms_dynamic_group_name)}'") : ("'${local.custom_id_domain_name}'/'${trimspace(var.existing_id_domain_database_kms_dyn_group_name)}'")
net_fw_app_dynamic_group_name = local.firewall_options[var.hub_vcn_deploy_net_appliance_option] == "FORTINET" ? (var.identity_domain_option != "Use Custom Identity Domain" ? (length(trimspace(var.existing_net_fw_app_dyn_group_name)) == 0 ? local.provided_net_fw_app_dynamic_group_name : (length(regexall("^ocid1.dynamicgroup.oc.*$", var.existing_net_fw_app_dyn_group_name)) > 0 ? local.all_existing_dynamic_groups[var.existing_net_fw_app_dyn_group_name].name : var.existing_net_fw_app_dyn_group_name)) : var.deploy_custom_domain_groups == true ? ("'${local.custom_id_domain_name}'/'${trimspace(local.provided_net_fw_app_dynamic_group_name)}'") : ("'${local.custom_id_domain_name}'/'${trimspace(var.existing_id_domain_net_fw_app_dyn_group_name)}'")) : null
}