File tree 5 files changed +33
-7
lines changed
5 files changed +33
-7
lines changed Original file line number Diff line number Diff line change 6
6
* .secrets
7
7
* .pfx
8
8
* .pem
9
- * .tfvars
10
- ! example.tfvars
11
- ** /tenants /*
12
- ! ** /tenants /myorg.onmicrosoft.com.yaml
9
+ ** /env /*
10
+ ! ** /env /example
Original file line number Diff line number Diff line change @@ -34,6 +34,7 @@ module "app" {
34
34
create_app = var. create_app
35
35
contact_email = var. contact_email
36
36
allowed_access_ips = var. vnet . allowed_access_ip_list
37
+ certificate_rotation_period_days = var. certificate_rotation_period_days
37
38
}
38
39
39
40
module "networking" {
Original file line number Diff line number Diff line change @@ -57,9 +57,15 @@ resource "azurerm_key_vault" "vault" {
57
57
}
58
58
}
59
59
60
+ # note this requires terraform to be run regularly
61
+ resource "time_rotating" "cert_rotation" {
62
+ rotation_days = var. certificate_rotation_period_days
63
+ }
64
+
60
65
# Generate the app registration certificate
61
66
resource "azurerm_key_vault_certificate" "cert" {
62
- name = " ${ var . app_name } -app-cert"
67
+ # Name change forces recreating certificate
68
+ name = " ${ var . resource_prefix } -app-cert-${ formatdate (" YYYY-MM-DD" , time_rotating. cert_rotation . rfc3339 )} "
63
69
key_vault_id = azurerm_key_vault. vault . id
64
70
65
71
certificate_policy {
@@ -80,7 +86,7 @@ resource "azurerm_key_vault_certificate" "cert" {
80
86
}
81
87
82
88
trigger {
83
- days_before_expiry = 30
89
+ days_before_expiry = max ( 3 , ceil (var . certificate_rotation_period_days / 6 ))
84
90
}
85
91
}
86
92
@@ -98,7 +104,8 @@ resource "azurerm_key_vault_certificate" "cert" {
98
104
]
99
105
100
106
subject = " CN=${ var . app_name } "
101
- validity_in_months = 24
107
+ # min 1 month; approx. twice length of rotation period
108
+ validity_in_months = max (1 , ceil (var. certificate_rotation_period_days * 2 / 30 ))
102
109
}
103
110
}
104
111
}
Original file line number Diff line number Diff line change @@ -23,6 +23,16 @@ variable "contact_email" {
23
23
type = string
24
24
}
25
25
26
+ variable "certificate_rotation_period_days" {
27
+ type = number
28
+ description = " How many days between when the certificate key should be rotated. Note: rotation requires running terraform"
29
+ default = 30
30
+ validation {
31
+ condition = var. certificate_rotation_period_days <= 60 && var. certificate_rotation_period_days >= 3
32
+ error_message = " Rotation period must be between 3 and 60 days"
33
+ }
34
+ }
35
+
26
36
variable "image_path" {
27
37
type = string
28
38
description = " Path to image used for app logo. Displayed in Azure console on installed tenants. Only needed when create_app=true"
Original file line number Diff line number Diff line change @@ -27,6 +27,16 @@ variable "contact_email" {
27
27
type = string
28
28
}
29
29
30
+ variable "certificate_rotation_period_days" {
31
+ type = number
32
+ description = " How many days between when the certificate key should be rotated. Note: rotation requires running terraform"
33
+ default = 30
34
+ validation {
35
+ condition = var. certificate_rotation_period_days <= 60 && var. certificate_rotation_period_days >= 3
36
+ error_message = " Rotation period must be between 3 and 60 days"
37
+ }
38
+ }
39
+
30
40
variable "resource_group_name" {
31
41
type = string
32
42
description = " Resource group to create and build resources in"
You can’t perform that action at this time.
0 commit comments