Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix create storage credentials with owner for account #3184

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion catalog/resource_storage_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -75,7 +75,7 @@ func ResourceStorageCredential() common.Resource {
_, err = acc.StorageCredentials.Update(ctx, catalog.AccountsUpdateStorageCredential{
CredentialInfo: &update,
MetastoreId: metastoreId,
StorageCredentialName: storageCredential.CredentialInfo.Id,
StorageCredentialName: storageCredential.CredentialInfo.Name,
})
if err != nil {
return err
Expand Down
66 changes: 66 additions & 0 deletions catalog/resource_storage_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,72 @@ func TestCreateStorageCredentialWithOwner(t *testing.T) {
}.ApplyNoError(t)
}

func TestCreateAccountStorageCredentialWithOwner(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "POST",
Resource: "/api/2.0/accounts/account_id/metastores/metastore_id/storage-credentials",
ExpectedRequest: &catalog.AccountsCreateStorageCredential{
MetastoreId: "metastore_id",
CredentialInfo: &catalog.CreateStorageCredential{
Name: "storage_credential_name",
AwsIamRole: &catalog.AwsIamRole{
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
},
},
},
Response: catalog.AccountsStorageCredentialInfo{
CredentialInfo: &catalog.StorageCredentialInfo{
Name: "storage_credential_name",
},
},
},
{
Method: "PUT",
Resource: "/api/2.0/accounts/account_id/metastores/metastore_id/storage-credentials/storage_credential_name",
ExpectedRequest: &catalog.AccountsUpdateStorageCredential{
CredentialInfo: &catalog.UpdateStorageCredential{
Name: "storage_credential_name",
Owner: "administrators",
AwsIamRole: &catalog.AwsIamRole{
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
},
},
},
Response: &catalog.AccountsStorageCredentialInfo{
CredentialInfo: &catalog.StorageCredentialInfo{
Name: "storage_credential_name",
},
},
},
{
Method: "GET",
Resource: "/api/2.0/accounts/account_id/metastores/metastore_id/storage-credentials/storage_credential_name?",
Response: &catalog.AccountsStorageCredentialInfo{
CredentialInfo: &catalog.StorageCredentialInfo{
Name: "storage_credential_name",
AwsIamRole: &catalog.AwsIamRole{
RoleArn: "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF",
},
},
},
},
},
Resource: ResourceStorageCredential(),
AccountID: "account_id",
Create: true,
HCL: `
name = "storage_credential_name"
metastore_id = "metastore_id"
aws_iam_role {
role_arn = "arn:aws:iam::1234567890:role/MyRole-AJJHDSKSDF"
}
owner = "administrators"
`,
}.ApplyNoError(t)
}

func TestCreateStorageCredentialsReadOnly(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
Expand Down
19 changes: 19 additions & 0 deletions internal/acceptance/storage_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,3 +32,22 @@ func TestUcAccStorageCredential(t *testing.T) {
})
}
}

func TestAccStorageCredentialOwner(t *testing.T) {
unityAccountLevel(t, step{
Template: `
resource "databricks_service_principal" "test_acc_storage_credential_owner" {
display_name = "test_acc_storage_credential_owner {var.RANDOM}"
}

resource "databricks_storage_credential" "test_acc_storage_credential_owner" {
name = "test_acc_storage_credential_owner-{var.RANDOM}"
owner = databricks_service_principal.test_acc_storage_credential_owner.application_id
metastore_id = "{env.TEST_METASTORE_ID}"
aws_iam_role {
role_arn = "{env.TEST_METASTORE_DATA_ACCESS_ARN}"
}
}
`,
})
}
Loading