Skip to content

Commit 0b5023d

Browse files
ssouthcitygerrytan
andauthored
azurerm_databricks_workspace - support for enhanced security compliance features (hashicorp#26606)
* added 'enhanced_security_compliance' block to databricks workspace schema * added customized diff checks to verify databricks workspace 'enhanced_security_compliance' block * added premium sku check for databricks workspace 'enhanced_security_compliance' * added 'enhanced_security_compliance' block to read and create/update methods * documented new 'enhanced_security_compliance' block for 'azurerm_databricks_workspace' resource * Fixed bugs, added acceptance test * Fix schema linting check * Added data source support and corresponding acctest * PR feedbacks improvements #1: - Always set value into state - Simplified expansion logic - Acctests method renaming to conform with standards - Removed unnecessary parameterisation of acctest config method - Docs for datasource * PR feedbacks improvements 2: - Removed stray newline - Use pointer.From to prevent nil deref - Improved validation error msg * PR feedbacks improvements 3: - Replace single-quote with backticks on error messages - Remove RequiredWith from compliance_security_profile_standards - Remove redundant test checks - Improve datasource docs - Add 'defaults to' to resource doc --------- Co-authored-by: Gerry Tan <gerry.tan@microsoft.com>
1 parent c5ca73a commit 0b5023d

File tree

9 files changed

+478
-38
lines changed

9 files changed

+478
-38
lines changed
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
## Example: Databricks Workspace with Enhanced Security and Compliance
2+
3+
This example provisions a Databricks Workspace within Azure with Enhanced Security and Compliance settings enabled.
4+
5+
### Variables
6+
7+
* `prefix` - (Required) The prefix used for all resources in this example.
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
provider "azurerm" {
2+
features {}
3+
}
4+
5+
resource "azurerm_resource_group" "example" {
6+
name = "${var.prefix}-databricks-esc"
7+
location = "West Europe"
8+
}
9+
10+
resource "azurerm_databricks_workspace" "example" {
11+
name = "${var.prefix}-DBW"
12+
resource_group_name = azurerm_resource_group.example.name
13+
location = azurerm_resource_group.example.location
14+
sku = "premium"
15+
managed_resource_group_name = "${var.prefix}-DBW-managed-esc"
16+
17+
enhanced_security_compliance {
18+
automatic_cluster_update_enabled = true
19+
compliance_security_profile_enabled = true
20+
compliance_security_profile_standards = ["HIPAA", "PCI_DSS"]
21+
enhanced_security_monitoring_enabled = true
22+
}
23+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# Copyright (c) HashiCorp, Inc.
2+
# SPDX-License-Identifier: MPL-2.0
3+
4+
variable "prefix" {
5+
description = "The Prefix used for all resources in this example"
6+
}
7+

internal/services/databricks/databricks_workspace_data_source.go

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -99,6 +99,34 @@ func dataSourceDatabricksWorkspace() *pluginsdk.Resource {
9999
},
100100
},
101101

102+
"enhanced_security_compliance": {
103+
Type: pluginsdk.TypeList,
104+
Computed: true,
105+
Elem: &pluginsdk.Resource{
106+
Schema: map[string]*pluginsdk.Schema{
107+
"automatic_cluster_update_enabled": {
108+
Type: pluginsdk.TypeBool,
109+
Computed: true,
110+
},
111+
"compliance_security_profile_enabled": {
112+
Type: pluginsdk.TypeBool,
113+
Computed: true,
114+
},
115+
"compliance_security_profile_standards": {
116+
Type: pluginsdk.TypeSet,
117+
Computed: true,
118+
Elem: &pluginsdk.Schema{
119+
Type: pluginsdk.TypeString,
120+
},
121+
},
122+
"enhanced_security_monitoring_enabled": {
123+
Type: pluginsdk.TypeBool,
124+
Computed: true,
125+
},
126+
},
127+
},
128+
},
129+
102130
"tags": commonschema.Tags(),
103131
},
104132
}
@@ -138,6 +166,9 @@ func dataSourceDatabricksWorkspaceRead(d *pluginsdk.ResourceData, meta interface
138166
}
139167
d.Set("workspace_url", model.Properties.WorkspaceURL)
140168
d.Set("location", model.Location)
169+
if err := d.Set("enhanced_security_compliance", flattenWorkspaceEnhancedSecurity(model.Properties.EnhancedSecurityCompliance)); err != nil {
170+
return fmt.Errorf("setting `enhanced_security_compliance`: %+v", err)
171+
}
141172

142173
return tags.FlattenAndSet(d, model.Tags)
143174
}

internal/services/databricks/databricks_workspace_data_source_test.go

Lines changed: 53 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,27 @@ func TestAccDatabricksWorkspaceDataSource_storageAccountIdentity(t *testing.T) {
4646
})
4747
}
4848

49+
func TestAccDatabricksWorkspaceDataSource_enhancedComplianceSecurity(t *testing.T) {
50+
data := acceptance.BuildTestData(t, "data.azurerm_databricks_workspace", "test")
51+
r := DatabricksWorkspaceDataSource{}
52+
53+
data.DataSourceTest(t, []acceptance.TestStep{
54+
{
55+
Config: r.enhancedSecurityCompliance(data),
56+
Check: acceptance.ComposeTestCheckFunc(
57+
acceptance.TestMatchResourceAttr(data.ResourceName, "workspace_url", regexp.MustCompile("azuredatabricks.net")),
58+
check.That(data.ResourceName).Key("workspace_id").Exists(),
59+
check.That(data.ResourceName).Key("location").Exists(),
60+
check.That(data.ResourceName).Key("enhanced_security_compliance.#").HasValue("1"),
61+
check.That(data.ResourceName).Key("enhanced_security_compliance.0.automatic_cluster_update_enabled").HasValue("true"),
62+
check.That(data.ResourceName).Key("enhanced_security_compliance.0.compliance_security_profile_enabled").HasValue("true"),
63+
check.That(data.ResourceName).Key("enhanced_security_compliance.0.compliance_security_profile_standards.#").HasValue("2"),
64+
check.That(data.ResourceName).Key("enhanced_security_compliance.0.enhanced_security_monitoring_enabled").HasValue("true"),
65+
),
66+
},
67+
})
68+
}
69+
4970
func (DatabricksWorkspaceDataSource) basic(data acceptance.TestData) string {
5071
return fmt.Sprintf(`
5172
provider "azurerm" {
@@ -195,3 +216,35 @@ resource "azurerm_key_vault_access_policy" "databricks" {
195216
}
196217
`, data.RandomInteger, data.Locations.Primary, data.RandomString, getDatabricksPrincipalId(data.Client().SubscriptionID))
197218
}
219+
220+
func (DatabricksWorkspaceDataSource) enhancedSecurityCompliance(data acceptance.TestData) string {
221+
return fmt.Sprintf(`
222+
provider "azurerm" {
223+
features {}
224+
}
225+
226+
resource "azurerm_resource_group" "test" {
227+
name = "acctestRG-databricks-%d"
228+
location = "%s"
229+
}
230+
231+
resource "azurerm_databricks_workspace" "test" {
232+
name = "acctestDBW-%d"
233+
resource_group_name = azurerm_resource_group.test.name
234+
location = azurerm_resource_group.test.location
235+
sku = "premium"
236+
237+
enhanced_security_compliance {
238+
automatic_cluster_update_enabled = true
239+
compliance_security_profile_enabled = true
240+
compliance_security_profile_standards = ["PCI_DSS", "HIPAA"]
241+
enhanced_security_monitoring_enabled = true
242+
}
243+
}
244+
245+
data "azurerm_databricks_workspace" "test" {
246+
name = azurerm_databricks_workspace.test.name
247+
resource_group_name = azurerm_resource_group.test.name
248+
}
249+
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
250+
}

0 commit comments

Comments
 (0)