Skip to content

Commit

Permalink
Add compliance security profile setting
Browse files Browse the repository at this point in the history
  • Loading branch information
harshshah-db committed May 10, 2024
1 parent 31df20c commit 8f607e3
Show file tree
Hide file tree
Showing 3 changed files with 123 additions and 0 deletions.
1 change: 1 addition & 0 deletions settings/all_settings.go
Original file line number Diff line number Diff line change
Expand Up @@ -17,5 +17,6 @@ func AllSettingsResources() map[string]common.Resource {
return map[string]common.Resource{
"default_namespace": makeSettingResource[settings.DefaultNamespaceSetting, *databricks.WorkspaceClient](defaultNamespaceSetting),
"restrict_workspace_admins": makeSettingResource[settings.RestrictWorkspaceAdminsSetting, *databricks.WorkspaceClient](restrictWsAdminsSetting),
"compliance_security_profile_workspace": makeSettingResource[settings.ComplianceSecurityProfileSetting, *databricks.WorkspaceClient](complianceSecurityProfileSetting),
}
}
35 changes: 35 additions & 0 deletions settings/resource_compliance_security_profile_setting.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
package settings

import (
"context"
"strings"

"github.com/databricks/databricks-sdk-go"
"github.com/databricks/databricks-sdk-go/service/settings"
)

// Enhanced Security Monitoring setting
var complianceSecurityProfileFieldMask = strings.Join([]string{
"compliance_security_profile_workspace.is_enabled",
"compliance_security_profile_workspace.compliance_standards",
}, ",")
var complianceSecurityProfileSetting = workspaceSetting[settings.ComplianceSecurityProfileSetting]{
settingStruct: settings.ComplianceSecurityProfileSetting{},
readFunc: func(ctx context.Context, w *databricks.WorkspaceClient, etag string) (*settings.ComplianceSecurityProfileSetting, error) {
return w.Settings.ComplianceSecurityProfile().Get(ctx, settings.GetComplianceSecurityProfileSettingRequest{
Etag: etag,
})
},
updateFunc: func(ctx context.Context, w *databricks.WorkspaceClient, t settings.ComplianceSecurityProfileSetting) (string, error) {
t.SettingName = "default"
res, err := w.Settings.ComplianceSecurityProfile().Update(ctx, settings.UpdateComplianceSecurityProfileSettingRequest{
AllowMissing: true,
Setting: t,
FieldMask: complianceSecurityProfileFieldMask,
})
if err != nil {
return "", err
}
return res.Etag, err
},
}
87 changes: 87 additions & 0 deletions settings/resource_compliance_security_profile_setting_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package settings

import (
"testing"

"github.com/databricks/databricks-sdk-go/apierr"
"github.com/databricks/databricks-sdk-go/experimental/mocks"
"github.com/databricks/databricks-sdk-go/service/settings"
"github.com/databricks/terraform-provider-databricks/qa"
"github.com/stretchr/testify/assert"
"github.com/stretchr/testify/mock"
)

var testComplianceSecurityProfileSetting = AllSettingsResources()["compliance_security_profile_workspace"]

func TestQueryCreateComplianceSecurityProfileSettingWithNoneStandard(t *testing.T) {
d, err := qa.ResourceFixture{
MockWorkspaceClientFunc: func(w *mocks.MockWorkspaceClient) {
e := w.GetMockComplianceSecurityProfileAPI().EXPECT()
e.Update(mock.Anything, settings.UpdateComplianceSecurityProfileSettingRequest{
AllowMissing: true,
FieldMask: complianceSecurityProfileFieldMask,
Setting: settings.ComplianceSecurityProfileSetting{
Etag: "",
ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{
IsEnabled: true,
ComplianceStandards: []settings.ComplianceStandard{"NONE"},
},
SettingName: "default",
},
}).Return(nil, &apierr.APIError{
ErrorCode: "NOT_FOUND",
StatusCode: 404,
Message: "SomeMessage",
Details: []apierr.ErrorDetail{{
Type: "type.googleapis.com/google.rpc.ErrorInfo",
Metadata: map[string]string{
etagAttrName: "etag1",
},
}},
})
e.Update(mock.Anything, settings.UpdateComplianceSecurityProfileSettingRequest{
AllowMissing: true,
FieldMask: complianceSecurityProfileFieldMask,
Setting: settings.ComplianceSecurityProfileSetting{
Etag: "etag1",
ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{
IsEnabled: true,
ComplianceStandards: []settings.ComplianceStandard{"NONE"},
},
SettingName: "default",
},
}).Return(&settings.ComplianceSecurityProfileSetting{
Etag: "etag2",
ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{
IsEnabled: true,
ComplianceStandards: []settings.ComplianceStandard{"NONE"},
},
SettingName: "default",
}, nil)
e.Get(mock.Anything, settings.GetComplianceSecurityProfileSettingRequest{
Etag: "etag2",
}).Return(&settings.ComplianceSecurityProfileSetting{
Etag: "etag2",
ComplianceSecurityProfileWorkspace: settings.ComplianceSecurityProfile{
IsEnabled: true,
ComplianceStandards: []settings.ComplianceStandard{"NONE"},
},
SettingName: "default",
}, nil)
},
Resource: testComplianceSecurityProfileSetting,
Create: true,
HCL: `
compliance_security_profile_workspace {
is_enabled = true
compliance_standards = ["NONE"]
}
`,
}.Apply(t)

assert.NoError(t, err)

assert.Equal(t, defaultSettingId, d.Id())
assert.Equal(t, "etag2", d.Get(etagAttrName).(string))
assert.Equal(t, true, d.Get("compliance_security_profile_workspace.0.is_enabled"))
}

0 comments on commit 8f607e3

Please sign in to comment.