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 update for databricks_storage_credential #1403

Merged
merged 29 commits into from
Jul 7, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
29 commits
Select commit Hold shift + click to select a range
29c2194
flatten the array for storage credentials
nkvuong Jun 27, 2022
3d3beaf
add test for updating azmi
nkvuong Jun 27, 2022
a15576c
fix typo
nkvuong Jun 27, 2022
4438e89
Use `delta_sharing_scope` instead of `delta_sharing_enabled` (#1398)
wchau Jun 28, 2022
4cd1a61
Bump github.com/hashicorp/hcl/v2 from 2.12.0 to 2.13.0 (#1406)
dependabot[bot] Jun 28, 2022
df93006
Bump github.com/golang-jwt/jwt/v4 from 4.4.1 to 4.4.2 (#1407)
dependabot[bot] Jun 28, 2022
54cfbe5
flatten the array for storage credentials
nkvuong Jun 27, 2022
2b5711c
Merge branch 'master' into feature/fix-credential-update
nkvuong Jun 28, 2022
ada729f
Use of go 1.18 instead of 1.16 to support latest hashicorp/hcl/v2
alexott Jun 28, 2022
d6e2ebd
minor fix
nkvuong Jul 4, 2022
de9ff97
Bump github.com/stretchr/testify from 1.7.4 to 1.7.5 (#1408)
dependabot[bot] Jul 1, 2022
04509b2
Better handling of missing objects during import (#1417)
alexott Jul 4, 2022
5291090
Clarify `databricks_cluster `autotermination_minutes` default (#1419)
gpdenny Jul 4, 2022
7df459a
Upgrade UC API from 2.0 to 2.1 (#1418)
nkvuong Jul 4, 2022
fcf4c28
Remove old integration testing infra (#1420)
nfx Jul 4, 2022
ded9b51
Bump google.golang.org/api from 0.85.0 to 0.86.0 (#1423)
dependabot[bot] Jul 5, 2022
6cf4d9b
Add `--junitfile junit.xml` to integration tests (#1425)
nfx Jul 6, 2022
ac9bd8f
clarified `databricks_permissions` doc for service principals (#1426)
nkvuong Jul 6, 2022
9d41cf3
Bump github.com/stretchr/testify from 1.7.5 to 1.8.0 (#1422)
dependabot[bot] Jul 6, 2022
bcf1625
Added `t.Parallel()` to acceptance tests (#1427)
nfx Jul 6, 2022
463688e
Move `databrickslabs` -> `databricks` go namespace (#1429)
nfx Jul 6, 2022
6c07650
fix acceptance test
nfx Jul 6, 2022
1057ec0
Bump Go from 1.16.x to 1.18.x (#1413)
alexott Jul 7, 2022
f7185cb
flatten the array for storage credentials
nkvuong Jun 27, 2022
020d7ad
Use `delta_sharing_scope` instead of `delta_sharing_enabled` (#1398)
wchau Jun 28, 2022
f46b053
Bump github.com/hashicorp/hcl/v2 from 2.12.0 to 2.13.0 (#1406)
dependabot[bot] Jun 28, 2022
3aea3e0
Use of go 1.18 instead of 1.16 to support latest hashicorp/hcl/v2
alexott Jun 28, 2022
ae583f4
Merge branch 'master' into feature/fix-credential-update
nkvuong Jul 7, 2022
c3e931a
upgrade api to 2.1
nkvuong Jul 7, 2022
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 @@ -49,7 +49,7 @@ func ResourceStorageCredential() *schema.Resource {
return m
})
update := updateFunctionFactory("/unity-catalog/storage-credentials", []string{
"owner", "comment", "aws_iam_role", "azure_service_principal"})
"owner", "comment", "aws_iam_role", "azure_service_principal", "azure_managed_identity"})
return common.Resource{
Schema: s,
Create: func(ctx context.Context, d *schema.ResourceData, c *common.DatabricksClient) error {
Expand Down
92 changes: 90 additions & 2 deletions catalog/resource_storage_credential_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,9 +104,9 @@ func TestUpdateStorageCredentials(t *testing.T) {
Method: "PATCH",
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
ExpectedRequest: map[string]interface{}{
"aws_iam_role": []interface{}{map[string]interface{}{
"aws_iam_role": map[string]interface{}{
"role_arn": "CHANGED",
}},
},
},
},
{
Expand Down Expand Up @@ -178,3 +178,91 @@ func TestCreateStorageCredentialWithAzMI(t *testing.T) {
`,
}.ApplyNoError(t)
}

func TestUpdateAzStorageCredentials(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "PATCH",
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
ExpectedRequest: map[string]interface{}{
"azure_service_principal": map[string]interface{}{
"directory_id": "CHANGED",
"application_id": "CHANGED",
"client_secret": "CHANGED",
},
},
},
{
Method: "GET",
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
Response: StorageCredentialInfo{
Name: "a",
Azure: &AzureServicePrincipal{
DirectoryID: "CHANGED",
ApplicationID: "CHANGED",
ClientSecret: "CHANGED",
},
MetastoreID: "d",
},
},
},
Resource: ResourceStorageCredential(),
Update: true,
ID: "a",
InstanceState: map[string]string{
"name": "a",
"comment": "c",
},
HCL: `
name = "a"
azure_service_principal {
directory_id = "CHANGED"
application_id = "CHANGED"
client_secret = "CHANGED"
}
comment = "c"
`,
}.ApplyNoError(t)
}

func TestUpdateAzStorageCredentialMI(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "PATCH",
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
ExpectedRequest: map[string]interface{}{
"azure_managed_identity": map[string]interface{}{
"access_connector_id": "CHANGED",
},
},
},
{
Method: "GET",
Resource: "/api/2.1/unity-catalog/storage-credentials/a",
Response: StorageCredentialInfo{
Name: "a",
AzMI: &AzureManagedIdentity{
AccessConnectorID: "CHANGED",
},
MetastoreID: "d",
},
},
},
Resource: ResourceStorageCredential(),
Update: true,
ID: "a",
InstanceState: map[string]string{
"name": "a",
"comment": "c",
},
HCL: `
name = "a"
azure_managed_identity {
access_connector_id = "CHANGED"
}
comment = "c"
`,
}.ApplyNoError(t)
}
10 changes: 10 additions & 0 deletions catalog/update.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,16 @@ func updateFunctionFactory(pathPrefix string, updatable []string) func(context.C
if !d.HasChange(field) {
continue
}

if contains([]string{
"aws_iam_role",
"azure_service_principal",
"azure_managed_identity",
}, field) {
patch[field] = d.Get(field).([]interface{})[0]
continue
}

if field == "delta_sharing_scope" && old != new && new == "INTERNAL_AND_EXTERNAL" &&
!d.HasChange("delta_sharing_recipient_token_lifetime_in_seconds") {
patch["delta_sharing_recipient_token_lifetime_in_seconds"] =
Expand Down