Skip to content

Commit a997ede

Browse files
authored
Added storage_credential_id attribute to databricks_storage_credential resource (#3636)
This attribute exposes UUID of the storage credential. Fixes #3538
1 parent 867f829 commit a997ede

File tree

3 files changed

+23
-3
lines changed

3 files changed

+23
-3
lines changed

catalog/resource_storage_credential.go

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,10 @@ func removeGcpSaField(originalSchema map[string]*schema.Schema) map[string]*sche
3535

3636
var storageCredentialSchema = common.StructToSchema(StorageCredentialInfo{},
3737
func(m map[string]*schema.Schema) map[string]*schema.Schema {
38+
m["storage_credential_id"] = &schema.Schema{
39+
Type: schema.TypeString,
40+
Computed: true,
41+
}
3842
return adjustDataAccessSchema(m)
3943
})
4044

@@ -122,7 +126,12 @@ func ResourceStorageCredential() common.Resource {
122126
storageCredential.CredentialInfo.AzureServicePrincipal.ClientSecret = scOrig.AzureServicePrincipal.ClientSecret
123127
}
124128
}
125-
return common.StructToData(storageCredential.CredentialInfo, storageCredentialSchema, d)
129+
err = common.StructToData(storageCredential.CredentialInfo, storageCredentialSchema, d)
130+
if err != nil {
131+
return err
132+
}
133+
d.Set("storage_credential_id", storageCredential.CredentialInfo.Id)
134+
return nil
126135
}, func(w *databricks.WorkspaceClient) error {
127136
storageCredential, err := w.StorageCredentials.GetByName(ctx, d.Id())
128137
if err != nil {
@@ -136,7 +145,12 @@ func ResourceStorageCredential() common.Resource {
136145
storageCredential.AzureServicePrincipal.ClientSecret = scOrig.AzureServicePrincipal.ClientSecret
137146
}
138147
}
139-
return common.StructToData(storageCredential, storageCredentialSchema, d)
148+
err = common.StructToData(storageCredential, storageCredentialSchema, d)
149+
if err != nil {
150+
return err
151+
}
152+
d.Set("storage_credential_id", storageCredential.Id)
153+
return nil
140154
})
141155
},
142156
Update: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {

catalog/resource_storage_credential_test.go

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ func TestCreateStorageCredentials(t *testing.T) {
3939
ExternalId: "123",
4040
},
4141
MetastoreId: "d",
42+
Id: "1234-5678",
4243
},
4344
},
4445
},
@@ -55,6 +56,7 @@ func TestCreateStorageCredentials(t *testing.T) {
5556
"aws_iam_role.0.external_id": "123",
5657
"aws_iam_role.0.role_arn": "def",
5758
"name": "a",
59+
"storage_credential_id": "1234-5678",
5860
})
5961
}
6062

@@ -163,6 +165,7 @@ func TestCreateAccountStorageCredentialWithOwner(t *testing.T) {
163165
AwsIamRole: &catalog.AwsIamRoleResponse{
164166
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
165167
},
168+
Id: "1234-5678",
166169
},
167170
},
168171
},
@@ -178,7 +181,9 @@ func TestCreateAccountStorageCredentialWithOwner(t *testing.T) {
178181
}
179182
owner = "administrators"
180183
`,
181-
}.ApplyNoError(t)
184+
}.ApplyAndExpectData(t, map[string]any{
185+
"storage_credential_id": "1234-5678",
186+
})
182187
}
183188

184189
func TestCreateStorageCredentialsReadOnly(t *testing.T) {

docs/resources/storage_credential.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -106,6 +106,7 @@ The following arguments are required:
106106
In addition to all arguments above, the following attributes are exported:
107107

108108
- `id` - ID of this storage credential - same as the `name`.
109+
- `storage_credential_id` - Unique ID of storage credential.
109110

110111
## Import
111112

0 commit comments

Comments
 (0)