Skip to content

Commit 4177d1e

Browse files
authored
Added databricks_workspace_conf resource (#398)
* Added databricks_workspace_conf resource * add changelog * Enable testing with new state InstanceState: map[string]string{ "custom_config.enableSomething": "true", }, HCL: `custom_config { enableIpAccessLists = "true" }`, * added unit tests for workspace conf Co-authored-by: Serge Smertin <[email protected]>
1 parent 6f29524 commit 4177d1e

12 files changed

+285
-287
lines changed

CHANGELOG.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
## 0.2.8
44

5+
* Added [databricks_workspace_conf](https://github.com/databrickslabs/terraform-provider-databricks/pull/398) resource
56
* Added [databricks_mws_log_delivery](https://github.com/databrickslabs/terraform-provider-databricks/pull/343) resource for billable usage & audit logs consumption.
67
* Added [databricks_node_type](https://github.com/databrickslabs/terraform-provider-databricks/pull/376) data source for simpler selection of node types across AWS & Azure.
78
* Added [Azure Key Vault support](https://github.com/databrickslabs/terraform-provider-databricks/pull/381) for databricks_secret_scope for Azure CLI authenticated users.

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,7 @@ End-to-end workspace creation on [AWS](scripts/awsmt-integration) or [Azure](scr
2222
| [databricks_group_member](docs/resources/group_member.md)
2323
| [databricks_instance_pool](docs/resources/instance_pool.md)
2424
| [databricks_instance_profile](docs/resources/instance_profile.md)
25+
| [databricks_ip_access_list](docs/resources/ip_access_list.md)
2526
| [databricks_job](docs/resources/job.md)
2627
| [databricks_mws_credentials](docs/resources/mws_credentials.md)
2728
| [databricks_mws_customer_managed_keys](docs/resources/mws_customer_managed_keys.md)
@@ -40,6 +41,7 @@ End-to-end workspace creation on [AWS](scripts/awsmt-integration) or [Azure](scr
4041
| [databricks_token](docs/resources/token.md)
4142
| [databricks_user](docs/resources/user.md)
4243
| [databricks_user_instance_profile](docs/resources/user_instance_profile.md)
44+
| [databricks_workspace_conf](docs/resources/workspace_conf.md)
4345
| [Contributing and Development Guidelines](CONTRIBUTING.md)
4446
| [Changelog](CHANGELOG.md)
4547

docs/resources/ip_access_list.md

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
# databricks_ip_access_list Resource
2+
3+
Security-conscious enterprises that use cloud SaaS applications need to restrict access to their own employees. Authentication helps to prove user identity, but that does not enforce network location of the users. Accessing a cloud service from an unsecured network can pose security risks to an enterprise, especially when the user may have authorized access to sensitive or personal data. Enterprise network perimeters apply security policies and limit access to external services (for example, firewalls, proxies, DLP, and logging), so access beyond these controls are assumed to be untrusted. Please see [IP Access List](https://docs.databricks.com/security/network/ip-access-list.html) for full feature documentation.
4+
5+
-> **Note** The total number of IP addresses and CIDR scopes provided across all ACL Lists in a workspace can not exceed 1000. Refer to the docs above for specifics.
6+
7+
## Example Usage
8+
9+
```hcl
10+
resource "databricks_workspace_conf" "this" {
11+
custom_config = {
12+
"enableIpAccessLists": true
13+
}
14+
}
15+
16+
resource "databricks_ip_access_list" "allowed-list" {
17+
label = "allow_in"
18+
list_type = "ALLOW"
19+
ip_addresses = [
20+
"1.2.3.0/24",
21+
"1.2.5.0/24"
22+
]
23+
depends_on = [databricks_workspace_conf.this]
24+
}
25+
```
26+
## Argument Reference
27+
28+
The following arguments are supported:
29+
30+
* `list_type` - Can only be "ALLOW" or "BLOCK"
31+
* `ip_addresses` - This is a field to allow the group to have instance pool create priviliges.
32+
* `label` - (Optional) This is the display name for the given IP ACL List.
33+
* `enabled` - (Optional) Boolean `true` or `false` indicating whether this list should be active. Defaults to `true`
34+
35+
## Attribute Reference
36+
37+
In addition to all arguments above, the following attributes are exported:
38+
39+
* `list_id` - Canonical unique identifier for the IP Access List.
40+
41+
## Import
42+
43+
Importing this resource is not currently supported.

docs/resources/ip_accessl_list.md

Lines changed: 0 additions & 40 deletions
This file was deleted.

docs/resources/workspace_conf.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# databricks_workspace_conf Resource
2+
3+
-> **Note** This resource has evolving API, which may change in future versions of provider.
4+
5+
Manages workspace configuration for expert usage. Currently, more than one instance of resource can exist in Terraform state, though there's no deterministic behavior, when they manage same property. We strongly recommend to use single `databricks_workspace_conf` per workspace.
6+
7+
## Example Usage
8+
9+
Allows specification of custom configuration properties for expert usage:
10+
11+
* `enableIpAccessLists` - enables the use of [databricks_ip_access_list](ip_accessl_list.md) resources
12+
13+
```hcl
14+
resource "databricks_workspace_conf" "this" {
15+
custom_config = {
16+
"enableIpAccessLists": true
17+
}
18+
}
19+
```
20+
21+
## Argument Reference
22+
23+
The following arguments are available:
24+
25+
* `custom_config` - (Required) Key-value map of strings, that represent workspace configuration. Upon resource deletion, properties that start with `enable` or `enforce` will be reset to `false` value, regardless of initial default one.
26+
27+
## Import
28+
29+
This resource cannot support import.

internal/qa/testing.go

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -63,9 +63,10 @@ type HTTPFixture struct {
6363

6464
// ResourceFixture helps testing resources and commands
6565
type ResourceFixture struct {
66-
Fixtures []HTTPFixture
67-
Resource *schema.Resource
68-
State map[string]interface{}
66+
Fixtures []HTTPFixture
67+
Resource *schema.Resource
68+
InstanceState map[string]string
69+
State map[string]interface{}
6970
// HCL might be useful to test nested blocks
7071
HCL string
7172
CommandMock common.CommandMock
@@ -167,7 +168,20 @@ func (f ResourceFixture) Apply(t *testing.T) (*schema.ResourceData, error) {
167168
strings.ReplaceAll(diagsToString(diags), "\"", ""))
168169
}
169170
}
170-
resourceData := schema.TestResourceDataRaw(t, f.Resource.Schema, f.State)
171+
c := terraform.NewResourceConfigRaw(f.State)
172+
sm := schema.InternalMap(f.Resource.Schema)
173+
is := &terraform.InstanceState{
174+
Attributes: f.InstanceState,
175+
}
176+
diff, err := sm.Diff(context.Background(), is, c, nil, nil, true)
177+
if err != nil {
178+
return nil, err
179+
}
180+
resourceData, err := sm.Data(is, diff)
181+
if err != nil {
182+
return nil, err
183+
}
184+
//resourceData := schema.TestResourceDataRaw(t, f.Resource.Schema, f.State)
171185
err = f.Resource.InternalValidate(f.Resource.Schema, !f.NonWritable)
172186
if err != nil {
173187
return nil, err

workspace/acceptance/workspace_conf_test.go

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -10,29 +10,29 @@ import (
1010
"github.com/stretchr/testify/assert"
1111
)
1212

13-
func TestWorkspaceConfFullLifecycle(t *testing.T) {
13+
func TestAccWorkspaceConfFullLifecycle(t *testing.T) {
1414
acceptance.AccTest(t, resource.TestCase{
15-
1615
Steps: []resource.TestStep{
1716
{
1817
Config: `
19-
resource "databricks_workspace_conf" "features" {
20-
enable_ip_access_lists = "true"
21-
}
22-
`,
18+
resource "databricks_workspace_conf" "this" {
19+
custom_config = {
20+
"enableIpAccessLists": true
21+
}
22+
}`,
2323
Check: resource.ComposeTestCheckFunc(
24-
acceptance.ResourceCheck("databricks_workspace_conf.features",
24+
acceptance.ResourceCheck("databricks_workspace_conf.this",
2525
func(client *common.DatabricksClient, id string) error {
26-
workspaceConf, err := workspace.NewWorkspaceConfAPI(client).Read("enableIpAccessLists")
27-
if err != nil {
28-
return err
26+
conf := map[string]interface{}{
27+
"enableIpAccessLists": nil,
2928
}
30-
assert.Len(t, workspaceConf, 1)
31-
assert.Equal(t, workspaceConf["enableIpAccessLists"], "true")
29+
err := workspace.NewWorkspaceConfAPI(client).Read(&conf)
30+
assert.NoError(t, err)
31+
assert.Len(t, conf, 1)
32+
assert.Equal(t, conf["enableIpAccessLists"], "true")
3233
return nil
3334
}),
3435
),
35-
ExpectNonEmptyPlan: true,
3636
},
3737
},
3838
})

workspace/resource_databricks_workspace_conf.go

Lines changed: 0 additions & 83 deletions
This file was deleted.

0 commit comments

Comments
 (0)