-
Notifications
You must be signed in to change notification settings - Fork 4
/
main.tf
141 lines (115 loc) · 3.33 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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
terraform {
required_version = ">= 0.12.0"
}
data "azurerm_client_config" "current" {}
resource "azurerm_key_vault" "kv" {
name = var.name
location = var.location
resource_group_name = var.resource_group_name
sku_name = var.sku_name
tenant_id = var.tenant_id
purge_protection_enabled = var.purge_protection_enabled
soft_delete_retention_days = var.soft_delete_retention_days
enabled_for_deployment = var.enabled_for_deployment
enabled_for_disk_encryption = var.enabled_for_disk_encryption
enabled_for_template_deployment = var.enabled_for_template_deployment
enable_rbac_authorization = var.enable_rbac_authorization
access_policy {
tenant_id = data.azurerm_client_config.current.tenant_id
object_id = data.azurerm_client_config.current.object_id
certificate_permissions = [
"Get",
"List",
"Create",
"Import",
"Update",
"Delete",
"Purge"
]
key_permissions = [
"Get",
"List",
"Create",
"Import"
]
secret_permissions = [
"Get",
"List",
"Set",
"Delete",
"Purge"
]
}
dynamic "access_policy" {
for_each = var.access_policy
content {
tenant_id = var.tenant_id
object_id = access_policy.value.object_id
application_id = lookup(access_policy.value, "application_id", null)
certificate_permissions = lookup(access_policy.value, "certificate_permissions", null)
key_permissions = lookup(access_policy.value, "key_permissions", null)
secret_permissions = lookup(access_policy.value, "secret_permissions", null)
storage_permissions = lookup(access_policy.value, "storage_permissions", null)
}
}
dynamic "network_acls" {
for_each = var.network_acls
content {
bypass = network_acls.value.bypass
default_action = network_acls.value.default_action
ip_rules = network_acls.value.ip_rules
virtual_network_subnet_ids = network_acls.value.virtual_network_subnet_ids
}
}
dynamic "contact" {
for_each = var.contact
content {
email = contact.value.email
name = contact.value.name
phone = contact.value.phone
}
}
tags = var.tags
}
resource "azurerm_key_vault_certificate" "example" {
for_each = toset( var.certificates )
name = replace(each.key, ".", "-")
key_vault_id = azurerm_key_vault.kv.id
certificate_policy {
issuer_parameters {
name = "Self"
}
key_properties {
exportable = true
key_size = 2048
key_type = "RSA"
reuse_key = true
}
lifetime_action {
action {
action_type = "AutoRenew"
}
trigger {
days_before_expiry = 30
}
}
secret_properties {
content_type = "application/x-pkcs12"
}
x509_certificate_properties {
# Server Authentication = 1.3.6.1.5.5.7.3.1
# Client Authentication = 1.3.6.1.5.5.7.3.2
extended_key_usage = ["1.3.6.1.5.5.7.3.1"]
key_usage = [
"cRLSign",
"dataEncipherment",
"digitalSignature",
"keyAgreement",
"keyCertSign",
"keyEncipherment",
]
subject = format("CN=%s",each.key)
validity_in_months = 12
}
}
}