Skip to content

Commit

Permalink
Data source: azurerm_keyvault_secret - support not_before_date and ex…
Browse files Browse the repository at this point in the history
…piration_date (#21359)
  • Loading branch information
herquan-docusign authored Apr 13, 2023
1 parent d69a2a8 commit 62bfbaa
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
18 changes: 18 additions & 0 deletions internal/services/keyvault/key_vault_secret_data_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,16 @@ func dataSourceKeyVaultSecret() *pluginsdk.Resource {
Computed: true,
},

"not_before_date": {
Type: pluginsdk.TypeString,
Computed: true,
},

"expiration_date": {
Type: pluginsdk.TypeString,
Computed: true,
},

"version": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -110,6 +120,14 @@ func dataSourceKeyVaultSecretRead(d *pluginsdk.ResourceData, meta interface{}) e
d.Set("value", resp.Value)
d.Set("version", respID.Version)
d.Set("content_type", resp.ContentType)
if attributes := resp.Attributes; attributes != nil {
if notBefore := attributes.NotBefore; notBefore != nil {
d.Set("not_before_date", time.Time(*notBefore).Format(time.RFC3339))
}
if expires := attributes.Expires; expires != nil {
d.Set("expiration_date", time.Time(*expires).Format(time.RFC3339))
}
}
d.Set("versionless_id", respID.VersionlessID())

d.Set("resource_id", parse.NewSecretID(keyVaultId.SubscriptionId, keyVaultId.ResourceGroup, keyVaultId.Name, respID.Name, respID.Version).ID())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ func TestAccDataSourceKeyVaultSecret_complete(t *testing.T) {
check.That(data.ResourceName).Key("tags.%").HasValue("1"),
check.That(data.ResourceName).Key("tags.hello").HasValue("world"),
check.That(data.ResourceName).Key("versionless_id").HasValue(fmt.Sprintf("https://acctestkv-%s.vault.azure.net/secrets/secret-%s", data.RandomString, data.RandomString)),
check.That(data.ResourceName).Key("not_before_date").HasValue("2019-01-01T01:02:03Z"),
check.That(data.ResourceName).Key("expiration_date").HasValue("2020-01-01T01:02:03Z"),
),
},
})
Expand Down
4 changes: 4 additions & 0 deletions website/docs/d/key_vault_secret.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ In addition to the Arguments listed above - the following Attributes are exporte

* `versionless_id` - The Versionless ID of the Key Vault Secret. This can be used to always get latest secret value, and enable fetching automatically rotating secrets.

* `not_before_date` - The earliest date at which the Key Vault Secret can be used.

* `expiration_date` - The date and time at which the Key Vault Secret expires and is no longer valid.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/language/resources/syntax#operation-timeouts) for certain actions:
Expand Down

0 comments on commit 62bfbaa

Please sign in to comment.