generated from qbeyond/terraform-module-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
101 lines (93 loc) · 4.32 KB
/
main.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
data "azurerm_client_config" "current" {}
resource "azuread_group" "custom_groups" {
for_each = var.custom_groups
display_name = each.key
description = "Automatically generated by terraform"
security_enabled = true
assignable_to_role = tobool(each.value.azuread_role_assignable)
}
resource "azurerm_role_assignment" "custom_groups" {
for_each = local.group_role_assignments
scope = each.value.scope
role_definition_name = each.value.role_definition_name
role_definition_id = each.value.role_definition_id
principal_id = azuread_group.custom_groups[each.value.principal].object_id
}
resource "azuread_group" "subscription_owners" {
for_each = var.subscriptions
display_name = "SUB_${each.key}_OWNER"
description = "Automatically generated by terraform. Grants Owner permissions on ${each.key} subscription."
security_enabled = true
assignable_to_role = false
}
resource "azurerm_role_assignment" "subscription_owners" {
for_each = var.subscriptions
scope = "/subscriptions/${each.value}"
role_definition_name = "Owner"
principal_id = azuread_group.subscription_owners[each.key].object_id
}
resource "azuread_group" "subscription_contributors" {
for_each = var.subscriptions
display_name = "SUB_${each.key}_CONTRIBUTOR"
description = "Automatically generated by terraform. Grants Contributor permissions on ${each.key} subscription."
security_enabled = true
assignable_to_role = false
}
resource "azurerm_role_assignment" "subscription_contributors" {
for_each = var.subscriptions
scope = "/subscriptions/${each.value}"
role_definition_name = "Contributor"
principal_id = azuread_group.subscription_contributors[each.key].object_id
}
resource "azuread_group" "subscription_readers" {
for_each = var.subscriptions
display_name = "SUB_${each.key}_READER"
description = "Automatically generated by terraform. Grants Reader permissions on ${each.key} subscription."
security_enabled = true
assignable_to_role = false
}
resource "azurerm_role_assignment" "subscription_readers" {
for_each = var.subscriptions
scope = "/subscriptions/${each.value}"
role_definition_name = "Reader"
principal_id = azuread_group.subscription_readers[each.key].object_id
}
resource "azuread_group" "management_owners" {
for_each = var.management_groups
display_name = "AMG_${each.key}_OWNER"
description = "Automatically generated by terraform. Grants Owner permissions on ${each.value.display_name} management group."
security_enabled = true
assignable_to_role = false
}
resource "azurerm_role_assignment" "management_owners" {
for_each = var.management_groups
scope = "/providers/Microsoft.Management/managementGroups/${each.key}"
role_definition_name = "Owner"
principal_id = azuread_group.management_owners[each.key].object_id
}
resource "azuread_group" "management_contributors" {
for_each = var.management_groups
display_name = "AMG_${each.key}_CONTRIBUTOR"
description = "Automatically generated by terraform. Grants Contributor permissions on ${each.value.display_name} management group."
security_enabled = true
assignable_to_role = false
}
resource "azurerm_role_assignment" "management_contributors" {
for_each = var.management_groups
scope = "/providers/Microsoft.Management/managementGroups/${each.key}"
role_definition_name = "Contributor"
principal_id = azuread_group.management_contributors[each.key].object_id
}
resource "azuread_group" "management_readers" {
for_each = var.management_groups
display_name = "AMG_${each.key}_READER"
description = "Automatically generated by terraform. Grants Reader permissions on ${each.value.display_name} management group."
security_enabled = true
assignable_to_role = false
}
resource "azurerm_role_assignment" "management_readers" {
for_each = var.management_groups
scope = "/providers/Microsoft.Management/managementGroups/${each.key}"
role_definition_name = "Reader"
principal_id = azuread_group.management_readers[each.key].object_id
}