Skip to content

Commit ba2eac6

Browse files
nkvuongalexott
andauthored
[Feature] Add time_rotating argument to databricks_service_principal_secret to enable secret rotation (#4793)
## Changes - Add `time_rotating` argument to `databricks_service_principal_secret` to enable secret rotation Close #4792 ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder --------- Co-authored-by: Alex Ott <[email protected]>
1 parent 1f0e5ac commit ba2eac6

File tree

3 files changed

+23
-1
lines changed

3 files changed

+23
-1
lines changed

NEXT_CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
### Breaking Changes
66

77
### New Features and Improvements
8+
* Added `time_rotating` argument to `databricks_service_principal_secret` to enable secret rotation ([#4789](https://github.com/databricks/terraform-provider-databricks/pull/4789)).
89

910

1011
* Add AWS support for `databricks_mws_ncc_private_endpoint_rule` ([#4804](https://github.com/databricks/terraform-provider-databricks/pull/4804)).

docs/resources/service_principal_secret.md

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,19 +21,35 @@ resource "databricks_service_principal_secret" "terraform_sp" {
2121
}
2222
```
2323

24+
A secret can be automatically rotated by taking a dependency on the `time_rotating` resource:
25+
26+
```hcl
27+
resource "time_rotating" "this" {
28+
rotation_days = 30
29+
}
30+
31+
resource "databricks_service_principal_secret" "terraform_sp" {
32+
service_principal_id = databricks_service_principal.this.id
33+
34+
# Token is valid for 60 days but is rotated after 30 days.
35+
time_rotating = "Terraform (created: ${time_rotating.this.rfc3339})"
36+
}
37+
```
38+
2439
## Argument Reference
2540

2641
The following arguments are available:
2742

2843
* `service_principal_id` (Required, string) - SCIM ID of the [databricks_service_principal](service_principal.md) (not application ID).
2944
* `lifetime` (Optional, string) - The lifetime of the secret in seconds formatted as `NNNNs`. If this parameter is not provided, the secret will have a default lifetime of 730 days (`63072000s`). Expiration of secret will lead to generation of new secret.
45+
* `time_rotating` - (Optional, string) - Changing this argument forces recreation of the secret.
3046

3147
## Attribute Reference
3248

3349
In addition to all arguments above, the following attributes are exported:
3450

3551
* `id` - ID of the secret
36-
* `secret` - Generated secret for the service principal.
52+
* `secret` - **Sensitive** Generated secret for the service principal.
3753
* `create_time` - UTC time when the secret was created.
3854
* `expire_time` - UTC time when the secret will expire. If the field is not present, the secret does not expire.
3955
* `secret_hash` - Secret Hash.

tokens/resource_service_principal_secret.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,11 @@ func createFailedToConvertServicePrincipalIdToNumericError(err error) error {
2626
func ResourceServicePrincipalSecret() common.Resource {
2727
spnSecretSchema := common.StructToSchema(ServicePrincipalSecret{},
2828
func(m map[string]*schema.Schema) map[string]*schema.Schema {
29+
m["time_rotating"] = &schema.Schema{
30+
Type: schema.TypeString,
31+
Optional: true,
32+
ForceNew: true,
33+
}
2934
m["id"].Computed = true
3035
m["create_time"].Computed = true
3136
m["expire_time"].Computed = true

0 commit comments

Comments
 (0)