Skip to content

Commit 6017d29

Browse files
authored
secrets/azure: add explicit_max_ttl for azure roles (#2438)
1 parent 200e54c commit 6017d29

4 files changed

Lines changed: 41 additions & 7 deletions

File tree

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
FEATURES:
44

55
* Add support for `recursive` search in `data_vault_namespaces` [#2408](https://github.com/hashicorp/terraform-provider-vault/pull/2408)
6+
* Add support for `explicit_max_ttl` in `vault_azure_secret_backend_role` resources. Requires Vault 1.18+ ([#2438](https://github.com/hashicorp/terraform-provider-vault/pull/2438)).
67

78
BUGS:
89

vault/resource_azure_secret_backend_role.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,11 @@ func azureSecretBackendRoleResource() *schema.Resource {
120120
Optional: true,
121121
Description: "Human-friendly description of the mount for the backend.",
122122
},
123+
consts.FieldExplicitMaxTTL: {
124+
Type: schema.TypeString,
125+
Optional: true,
126+
Description: "Specifies the explicit maximum lifetime of the lease and service principal.",
127+
},
123128
consts.FieldSignInAudience: {
124129
Type: schema.TypeString,
125130
Optional: true,
@@ -183,6 +188,13 @@ func azureSecretBackendRoleUpdateFields(_ context.Context, d *schema.ResourceDat
183188
}
184189
}
185190

191+
useAPIVer118 := provider.IsAPISupported(meta, provider.VaultVersion118)
192+
if useAPIVer118 {
193+
if v, ok := d.GetOk(consts.FieldExplicitMaxTTL); ok && v != "" {
194+
data[consts.FieldExplicitMaxTTL] = v
195+
}
196+
}
197+
186198
useAPIVer116 := provider.IsAPISupported(meta, provider.VaultVersion116)
187199
if useAPIVer116 {
188200
if v, ok := d.GetOk(consts.FieldSignInAudience); ok && v != "" {
@@ -267,6 +279,13 @@ func azureSecretBackendRoleRead(_ context.Context, d *schema.ResourceData, meta
267279
}
268280
}
269281

282+
useAPIVer118 := provider.IsAPISupported(meta, provider.VaultVersion118)
283+
if useAPIVer118 {
284+
if err := d.Set(consts.FieldExplicitMaxTTL, resp.Data[consts.FieldExplicitMaxTTL]); err != nil {
285+
return diag.FromErr(err)
286+
}
287+
}
288+
270289
useAPIVer116 := provider.IsAPISupported(meta, provider.VaultVersion116)
271290
if useAPIVer116 {
272291
if err := d.Set(consts.FieldSignInAudience, resp.Data[consts.FieldSignInAudience]); err != nil {

vault/resource_azure_secret_backend_role_test.go

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ func TestAzureSecretBackendRole_AzureRoles(t *testing.T) {
5454
}
5555

5656
isVaultVersion116 := provider.IsAPISupported(testProvider.Meta(), provider.VaultVersion116)
57-
if !isVaultVersion116 {
57+
if isVaultVersion116 {
5858
azureRoleInitialCheckFuncs = append(azureRoleInitialCheckFuncs,
5959
resource.TestCheckResourceAttr(resourceName+".test_azure_roles", "sign_in_audience", "AzureADMyOrg"),
6060
resource.TestCheckResourceAttr(resourceName+".test_azure_roles", "tags.#", "1"),
@@ -66,6 +66,14 @@ func TestAzureSecretBackendRole_AzureRoles(t *testing.T) {
6666
resource.TestCheckResourceAttr(resourceName+".test_azure_roles", "tags.1", "project:vault_testing"))
6767
}
6868

69+
isVaultVersion118 := provider.IsAPISupported(testProvider.Meta(), provider.VaultVersion118)
70+
if isVaultVersion118 {
71+
azureRoleInitialCheckFuncs = append(azureRoleInitialCheckFuncs,
72+
resource.TestCheckResourceAttr(resourceName+".test_azure_roles", "explicit_max_ttl", "0"))
73+
azureRoleUpdatedCheckFuncs = append(azureRoleUpdatedCheckFuncs,
74+
resource.TestCheckResourceAttr(resourceName+".test_azure_roles", "explicit_max_ttl", "2592000"))
75+
}
76+
6977
resource.Test(t, resource.TestCase{
7078
ProviderFactories: providerFactories,
7179
PreCheck: func() {
@@ -208,7 +216,8 @@ resource "vault_azure_secret_backend_role" "test_azure_roles" {
208216
role = "%[6]s-azure-roles"
209217
ttl = 300
210218
max_ttl = 600
211-
description = "Test for Vault Provider"
219+
explicit_max_ttl = 0
220+
description = "Test for Vault Provider"
212221
sign_in_audience = "AzureADMyOrg"
213222
tags = ["team:engineering"]
214223
@@ -259,6 +268,7 @@ resource "vault_azure_secret_backend_role" "test_azure_roles" {
259268
role = "%[6]s-azure-roles"
260269
ttl = 600
261270
max_ttl = 900
271+
explicit_max_ttl = 2592000
262272
description = "Test for Vault Provider"
263273
sign_in_audience = "AzureADMultipleOrgs"
264274
tags = ["environment:development","project:vault_testing"]
@@ -306,11 +316,14 @@ resource "vault_azure_secret_backend" "azure" {
306316
}
307317
308318
resource "vault_azure_secret_backend_role" "test_azure_roles" {
309-
backend = vault_azure_secret_backend.azure.path
310-
role = "%[6]s-azure-roles"
311-
ttl = 300
312-
max_ttl = 600
313-
description = "Test for Vault Provider"
319+
backend = vault_azure_secret_backend.azure.path
320+
role = "%[6]s-azure-roles"
321+
ttl = 300
322+
max_ttl = 600
323+
explicit_max_ttl = 0
324+
description = "Test for Vault Provider"
325+
sign_in_audience = "AzureADMultipleOrgs"
326+
tags = ["environment:development","project:vault_testing"]
314327
315328
azure_roles {
316329
role_name = "Reader"

website/docs/r/azure_secret_backend_role.html.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -73,6 +73,7 @@ The following arguments are supported:
7373
Accepts time suffixed strings ("1h") or an integer number of seconds. Defaults to the system/engine default TTL time.
7474
* `max_ttl` – (Optional) Specifies the maximum TTL for service principals generated using this role. Accepts time
7575
suffixed strings ("1h") or an integer number of seconds. Defaults to the system/engine max TTL time.
76+
* `explicit_max_ttl` - (Optional) Specifies the explicit maximum lifetime of the lease and service principal generated using this role. If not set or set to 0, will use the system default (10 years). Requires Vault 1.18+.
7677
* `sign_in_audience` - (Optional) Specifies the security principal types that are allowed to sign in to the application.
7778
Valid values are: AzureADMyOrg, AzureADMultipleOrgs, AzureADandPersonalMicrosoftAccount, PersonalMicrosoftAccount. Requires Vault 1.16+.
7879
* `tags` - (Optional) - A list of Azure tags to attach to an application. Requires Vault 1.16+.

0 commit comments

Comments
 (0)