Skip to content

Commit 2606c76

Browse files
authored
Fix create storage credentials with owner for account (#3184)
* Use storage credential name instead of ID to patch owner * Add create account storage credential basic test * Add acceptance test
1 parent e9a1974 commit 2606c76

File tree

3 files changed

+86
-1
lines changed

3 files changed

+86
-1
lines changed

catalog/resource_storage_credential.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ func ResourceStorageCredential() common.Resource {
7575
_, err = acc.StorageCredentials.Update(ctx, catalog.AccountsUpdateStorageCredential{
7676
CredentialInfo: &update,
7777
MetastoreId: metastoreId,
78-
StorageCredentialName: storageCredential.CredentialInfo.Id,
78+
StorageCredentialName: storageCredential.CredentialInfo.Name,
7979
})
8080
if err != nil {
8181
return err

catalog/resource_storage_credential_test.go

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,72 @@ func TestCreateStorageCredentialWithOwner(t *testing.T) {
115115
}.ApplyNoError(t)
116116
}
117117

118+
func TestCreateAccountStorageCredentialWithOwner(t *testing.T) {
119+
qa.ResourceFixture{
120+
Fixtures: []qa.HTTPFixture{
121+
{
122+
Method: "POST",
123+
Resource: "/api/2.0/accounts/account_id/metastores/metastore_id/storage-credentials",
124+
ExpectedRequest: &catalog.AccountsCreateStorageCredential{
125+
MetastoreId: "metastore_id",
126+
CredentialInfo: &catalog.CreateStorageCredential{
127+
Name: "storage_credential_name",
128+
AwsIamRole: &catalog.AwsIamRole{
129+
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
130+
},
131+
},
132+
},
133+
Response: catalog.AccountsStorageCredentialInfo{
134+
CredentialInfo: &catalog.StorageCredentialInfo{
135+
Name: "storage_credential_name",
136+
},
137+
},
138+
},
139+
{
140+
Method: "PUT",
141+
Resource: "/api/2.0/accounts/account_id/metastores/metastore_id/storage-credentials/storage_credential_name",
142+
ExpectedRequest: &catalog.AccountsUpdateStorageCredential{
143+
CredentialInfo: &catalog.UpdateStorageCredential{
144+
Name: "storage_credential_name",
145+
Owner: "administrators",
146+
AwsIamRole: &catalog.AwsIamRole{
147+
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
148+
},
149+
},
150+
},
151+
Response: &catalog.AccountsStorageCredentialInfo{
152+
CredentialInfo: &catalog.StorageCredentialInfo{
153+
Name: "storage_credential_name",
154+
},
155+
},
156+
},
157+
{
158+
Method: "GET",
159+
Resource: "/api/2.0/accounts/account_id/metastores/metastore_id/storage-credentials/storage_credential_name?",
160+
Response: &catalog.AccountsStorageCredentialInfo{
161+
CredentialInfo: &catalog.StorageCredentialInfo{
162+
Name: "storage_credential_name",
163+
AwsIamRole: &catalog.AwsIamRole{
164+
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
165+
},
166+
},
167+
},
168+
},
169+
},
170+
Resource: ResourceStorageCredential(),
171+
AccountID: "account_id",
172+
Create: true,
173+
HCL: `
174+
name = "storage_credential_name"
175+
metastore_id = "metastore_id"
176+
aws_iam_role {
177+
role_arn = "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF"
178+
}
179+
owner = "administrators"
180+
`,
181+
}.ApplyNoError(t)
182+
}
183+
118184
func TestCreateStorageCredentialsReadOnly(t *testing.T) {
119185
qa.ResourceFixture{
120186
Fixtures: []qa.HTTPFixture{

internal/acceptance/storage_credential_test.go

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,3 +32,22 @@ func TestUcAccStorageCredential(t *testing.T) {
3232
})
3333
}
3434
}
35+
36+
func TestAccStorageCredentialOwner(t *testing.T) {
37+
unityAccountLevel(t, step{
38+
Template: `
39+
resource "databricks_service_principal" "test_acc_storage_credential_owner" {
40+
display_name = "test_acc_storage_credential_owner {var.RANDOM}"
41+
}
42+
43+
resource "databricks_storage_credential" "test_acc_storage_credential_owner" {
44+
name = "test_acc_storage_credential_owner-{var.RANDOM}"
45+
owner = databricks_service_principal.test_acc_storage_credential_owner.application_id
46+
metastore_id = "{env.TEST_METASTORE_ID}"
47+
aws_iam_role {
48+
role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}"
49+
}
50+
}
51+
`,
52+
})
53+
}

0 commit comments

Comments
 (0)