forked from tasador/terraform-azuread-service-principal
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
53 lines (43 loc) · 1.37 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
data "azurerm_client_config" "main" {}
data "azurerm_role_definition" "main" {
count = var.role != "" ? 1 : 0
name = var.role
}
data "azurerm_subscription" "main" {}
resource "azuread_application" "main" {
name = var.name
identifier_uris = [
format("http://%s", var.name)
]
available_to_other_tenants = false
}
resource "azuread_service_principal" "main" {
application_id = azuread_application.main.application_id
}
resource "time_rotating" "main" {
rotation_rfc3339 = var.end_date
rotation_years = var.years
triggers = {
end_date = var.end_date
years = var.years
}
}
resource "random_password" "main" {
count = var.password == "" ? 1 : 0
length = 32
keepers = {
rfc3339 = time_rotating.main.id
}
}
resource "azuread_service_principal_password" "main" {
count = var.password != null ? 1 : 0
service_principal_id = azuread_service_principal.main.id
value = coalesce(var.password, random_password.main[0].result)
end_date = time_rotating.main.rotation_rfc3339
}
resource "azurerm_role_assignment" "main" {
count = var.role != "" ? length(local.scopes) : 0
scope = local.scopes[count.index]
role_definition_id = format("%s%s", data.azurerm_subscription.main.id, data.azurerm_role_definition.main[0].id)
principal_id = azuread_service_principal.main.id
}