-
Notifications
You must be signed in to change notification settings - Fork 15
/
main.tf
67 lines (55 loc) · 1.42 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
data "azurerm_client_config" "main" {}
data "azurerm_subscription" "main" {}
locals {
scopes = (
length(var.scopes) > 0 ?
var.scopes :
[data.azurerm_subscription.main.id]
)
}
resource "random_id" "name" {
count = var.name == "" ? 1 : 0
prefix = "terraform-"
byte_length = 4
}
resource "azuread_application" "main" {
name = (
var.name != "" ?
var.name :
random_id.name[0].hex
)
available_to_other_tenants = false
}
resource "azuread_service_principal" "main" {
application_id = azuread_application.main.application_id
}
resource "random_string" "password" {
count = var.password == "" ? 1 : 0
length = 32
special = true
}
resource "azuread_service_principal_password" "main" {
count = var.password != null ? 1 : 0
service_principal_id = azuread_service_principal.main.id
value = (
var.password != "" ?
var.password :
random_string.password[0].result
)
end_date = var.end_date
end_date_relative = (
var.end_date == null ?
"${(var.years * 24 * 365)}h" :
null
)
}
data "azurerm_role_definition" "main" {
count = var.role != "" ? 1 : 0
name = var.role
}
resource "azurerm_role_assignment" "main" {
count = var.role != "" ? length(local.scopes) : 0
scope = local.scopes[count.index]
role_definition_id = data.azurerm_role_definition.main[0].id
principal_id = azuread_service_principal.main.id
}