-
Notifications
You must be signed in to change notification settings - Fork 133
/
main.tf
101 lines (82 loc) · 2.97 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
// Resource Group
data "azurerm_resource_group" "rg" {
name = var.rg_name
}
// Storage Account
resource "azurerm_storage_account" "log-sa" {
name = join("", [var.logs_sa_name, var.random_string])
resource_group_name = data.azurerm_resource_group.rg.name
location = data.azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
is_hns_enabled = true
identity {
type = "SystemAssigned"
}
tags = {
source = "Databricks"
application = "Overwatch"
description="Overwatch cluster logs storage"
}
}
// Role Assignment
data "azuread_service_principal" "overwatch-spn" {
application_id = var.overwatch_spn_app_id
}
resource "azurerm_role_assignment" "data-contributor-role-log"{
scope = azurerm_storage_account.log-sa.id
role_definition_name = "Storage Blob Data Contributor"
principal_id = data.azuread_service_principal.overwatch-spn.object_id
}
// Eventhubs
resource "azurerm_eventhub_namespace" "ehn" {
name = join("-", [var.ehn_name, var.random_string])
location = data.azurerm_resource_group.rg.location
resource_group_name = data.azurerm_resource_group.rg.name
sku = "Basic"
capacity = 1
tags = {
environment = "Overwatch"
}
}
resource "azurerm_eventhub_namespace_authorization_rule" "ehn-ar" {
name = join("-", [var.ehn_name, "ar", var.random_string])
namespace_name = azurerm_eventhub_namespace.ehn.name
resource_group_name = data.azurerm_resource_group.rg.name
listen = true
send = true
manage = true
}
// AKV
data "azurerm_client_config" "current" {
}
resource "azurerm_key_vault" "kv" {
name = join("-", [var.key_vault_prefix, var.random_string])
location = data.azurerm_resource_group.rg.location
resource_group_name = var.rg_name
tenant_id = data.azurerm_client_config.current.tenant_id
sku_name = "standard"
purge_protection_enabled = false
}
resource "azurerm_key_vault_access_policy" "kv-ap" {
key_vault_id = azurerm_key_vault.kv.id
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id
key_permissions = [
"Get", "List", "Update", "Create", "Import", "Delete", "Recover", "Backup", "Restore", "Purge"
]
secret_permissions = [
"Get", "List", "Set", "Delete", "Recover", "Backup", "Restore", "Purge"
]
certificate_permissions = [
"Get", "List", "Update", "Create", "Import", "Delete", "Recover", "Backup", "Restore", "Purge"
]
depends_on = [azurerm_key_vault.kv]
}
resource "azurerm_key_vault_secret" "spn-key"{
name = "spn-key"
value = var.overwatch_spn_secret
expiration_date = "2030-12-31T23:59:59Z"
key_vault_id = azurerm_key_vault.kv.id
depends_on = [azurerm_key_vault_access_policy.kv-ap]
}