This repository has been archived by the owner on Jun 22, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
/
main.tf
54 lines (46 loc) · 1.79 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
resource "azuread_application" "main" {
name = var.service_principal_name
identifier_uris = ["http://${var.service_principal_name}"]
available_to_other_tenants = false
oauth2_allow_implicit_flow = false
}
resource "azuread_service_principal" "main" {
application_id = azuread_application.main.application_id
}
resource "time_rotating" "main" {
rotation_rfc3339 = var.password_end_date
rotation_years = var.password_rotation_in_years
triggers = {
end_date = var.password_end_date
years = var.password_rotation_in_years
}
}
resource "random_password" "passwd" {
count = var.enable_service_principal_certificate != true ? 1 : 0
length = 32
min_upper = 4
min_lower = 2
min_numeric = 4
keepers = {
service_principal_password = time_rotating.main.id
}
}
resource "azuread_service_principal_password" "main" {
count = var.enable_service_principal_certificate != true ? 1 : 0
service_principal_id = azuread_service_principal.main.id
value = random_password.passwd[count.index].result
end_date = time_rotating.main.rotation_rfc3339
}
resource "azurerm_role_assignment" "main" {
count = length(var.assignments)
scope = var.assignments[count.index].scope
role_definition_name = var.assignments[count.index].role_definition_name
principal_id = azuread_service_principal.main.object_id
}
resource "azuread_service_principal_certificate" "main" {
count = var.enable_service_principal_certificate == true ? 1 : 0
service_principal_id = azuread_service_principal.main.id
type = var.certificate_type
value = file(var.certificate_path)
end_date = time_rotating.main.rotation_rfc3339
}