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

[Feature] Add databricks_mws_network_connectivity_config and databricks_mws_network_connectivity_configs data source #3665

Merged
merged 13 commits into from
Nov 15, 2024
Merged
47 changes: 47 additions & 0 deletions docs/data-sources/mws_network_connectivity_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
---
subcategory: "Deployment"
---
# databricks_mws_network_connectivity_config Data Source

-> **Note** If you have a fully automated setup with workspaces created by [databricks_mws_workspaces](../resources/mws_workspaces.md) or [azurerm_databricks_workspace](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/databricks_workspace), please make sure to add [depends_on attribute](../guides/troubleshooting.md#data-resources-and-authentication-is-not-configured-errors) in order to prevent _default auth: cannot configure default credentials_ errors.
840 marked this conversation as resolved.
Show resolved Hide resolved

Lists all [databricks_mws_network_connectivity_config](../resources/mws_network_connectivity_config.md) in Databricks Account.

-> **Note** [`account_id`](../index.md#account_id) provider configuration property is required for this resource to work.

## Example Usage

Fetching information about a network connectivity configuration in Databricks Account

```hcl
provider "databricks" {
// other configuration
account_id = "<databricks account id>"
}

data "databricks_mws_network_connectivity_config" "this" {
network_connectivity_config_id = "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"
840 marked this conversation as resolved.
Show resolved Hide resolved
}

output "ncc_config" {
value = data.databricks_mws_network_connectivity_config.this
}
```

## Attribute Reference

-> **Note** This resource has an evolving interface, which may change in future versions of the provider.

This data source exports the following attributes:

* `network_connectivity_config_id` - ID of the network connectivity configuration

## Related Resources

The following resources are used in the same context:

* [Provisioning Databricks on AWS](../guides/aws-workspace.md) guide.
* [databricks_mws_customer_managed_keys](mws_customer_managed_keys.md) to configure KMS keys for new workspaces within AWS.
* [databricks_mws_networks](mws_networks.md) to [configure VPC](https://docs.databricks.com/administration-guide/cloud-configurations/aws/customer-managed-vpc.html) & subnets for new workspaces within AWS.
* [databricks_mws_storage_configurations](mws_storage_configurations.md) to configure root bucket new workspaces within AWS.
* [databricks_mws_workspaces](mws_workspaces.md) to set up [workspaces in E2 architecture on AWS](https://docs.databricks.com/getting-started/overview.html#e2-architecture-1).
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccDataSourceMwsNetworkConnectivityConfigTest(t *testing.T) {
accountLevel(t,
840 marked this conversation as resolved.
Show resolved Hide resolved
step{
Template: `
resource "databricks_mws_network_connectivity_config" "this" {
name = "tf-{var.RANDOM}"
region = "eastus2"
}`},
step{
Template: `
resource "databricks_mws_network_connectivity_config" "this" {
name = "tf-{var.RANDOM}"
region = "eastus2"
}

data "databricks_mws_network_connectivity_config" "this" {
depends_on = [databricks_mws_network_connectivity_config.this]
network_connectivity_config_id = databricks_mws_network_connectivity_config.this.network_connectivity_config_id
}`,
Check: func(s *terraform.State) error {
r, ok := s.RootModule().Resources["data.databricks_mws_network_connectivity_config.this"]
if !ok {
return fmt.Errorf("data not found in state")
}
id := r.Primary.Attributes["id"]
if id == "" {
return fmt.Errorf("id is empty: %v", r.Primary.Attributes)
}
expect := "eastus2"
region := r.Primary.Attributes["region"]
if region != expect {
return fmt.Errorf("incorrect region. expected: %v, received: %v",
expect, region)
}
return nil
},
})
}
38 changes: 38 additions & 0 deletions mws/data_mws_network_connectivity_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
package mws

import (
"context"

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

func DataSourceMwsNetworkConnectivityConfig() common.Resource {
return common.AccountData(func(ctx context.Context, data *struct {
840 marked this conversation as resolved.
Show resolved Hide resolved
Id string `json:"id" tf:"computed,optional"`
AccountId string `json:"account_id,omitempty" tf:"computed"`
CreationTime int64 `json:"creation_time,omitempty" tf:"computed"`
EgressConfig settings.NccEgressConfig `json:"egress_config,omitempty" tf:"computed"`
Name string `json:"name,omitempty" tf:"computed"`
NetworkConnectivityConfigId string `json:"network_connectivity_config_id"`
840 marked this conversation as resolved.
Show resolved Hide resolved
Region string `json:"region,omitempty" tf:"computed"`
UpdatedTime int64 `json:"updated_time,omitempty" tf:"computed"`
}, a *databricks.AccountClient) error {
ncc, err := a.NetworkConnectivity.GetNetworkConnectivityConfigurationByNetworkConnectivityConfigId(ctx, data.NetworkConnectivityConfigId)
if err != nil {
return err
}
data.Id = ncc.NetworkConnectivityConfigId
data.AccountId = ncc.AccountId
data.CreationTime = ncc.CreationTime
data.EgressConfig = settings.NccEgressConfig{
DefaultRules: ncc.EgressConfig.DefaultRules,
TargetRules: ncc.EgressConfig.TargetRules,
}
data.Name = ncc.Name
data.Region = ncc.Region
data.UpdatedTime = ncc.UpdatedTime
return nil
})
}
75 changes: 75 additions & 0 deletions mws/data_mws_network_connectivity_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,75 @@
package mws

import (
"fmt"
"testing"

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

"github.com/databricks/terraform-provider-databricks/qa"
)

func TestDataSourceMwsNetworkConnectivityConfig(t *testing.T) {
id := "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx"

var ncc = settings.NetworkConnectivityConfiguration{
AccountId: "abc",
CreationTime: 0,
EgressConfig: &settings.NccEgressConfig{
DefaultRules: nil,
TargetRules: nil,
},
Name: "def",
NetworkConnectivityConfigId: "",
Region: "us-east-1",
UpdatedTime: 0,
}

qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{
{
Method: "GET",
Resource: fmt.Sprintf("/api/2.0/accounts/%s/network-connectivity-configs/%s?", ncc.AccountId, id),
Response: ncc,
},
},
AccountID: "abc",
Read: true,
NonWritable: true,
Resource: DataSourceMwsNetworkConnectivityConfig(),
ID: id,
HCL: fmt.Sprintf(`
network_connectivity_config_id = "%s"
`, id),
}.ApplyAndExpectData(t, map[string]interface{}{
"account_id": "abc",
"creation_time": 0,
"egress_config": []interface{}{map[string]interface{}{"default_rules": []interface{}{}, "target_rules": []interface{}{}}},
"id": id,
"name": "def",
"network_connectivity_config_id": id,
"region": "us-east-1",
"updated_time": 0,
})
}

func TestDataSourceMwsNetworkConnectivityConfig_AccountID(t *testing.T) {
qa.ResourceFixture{
Fixtures: []qa.HTTPFixture{},
Resource: DataSourceMwsNetworkConnectivityConfig(),
Read: true,
NonWritable: true,
ID: "_",
}.ExpectError(t, "invalid Databricks Account configuration")
}

func TestDataSourceMwsNetworkConnectivityConfig_Error(t *testing.T) {
qa.ResourceFixture{
Fixtures: qa.HTTPFailures,
AccountID: "abc",
Resource: DataSourceMwsNetworkConnectivityConfig(),
Read: true,
NonWritable: true,
ID: "_",
}.ExpectError(t, "i'm a teapot")
}
1 change: 1 addition & 0 deletions provider/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,7 @@ func DatabricksProvider() *schema.Provider {
"databricks_mlflow_experiment": mlflow.DataSourceExperiment().ToResource(),
"databricks_mlflow_model": mlflow.DataSourceModel().ToResource(),
"databricks_mws_credentials": mws.DataSourceMwsCredentials().ToResource(),
"databricks_mws_network_connectivity_config": mws.DataSourceMwsNetworkConnectivityConfig().ToResource(),
"databricks_mws_workspaces": mws.DataSourceMwsWorkspaces().ToResource(),
"databricks_node_type": clusters.DataSourceNodeType().ToResource(),
"databricks_notebook": workspace.DataSourceNotebook().ToResource(),
Expand Down
Loading