Skip to content
Merged
Show file tree
Hide file tree
Changes from 12 commits
Commits
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
67 changes: 67 additions & 0 deletions docs/data-sources/mws_network_connectivity_config.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
---
subcategory: "Deployment"
---
# databricks_mws_network_connectivity_config Data Source

-> **Note** This data source can only be used with an account-level provider!

Retrieves information about [databricks_mws_network_connectivity_config](../resources/mws_network_connectivity_config.md) in Databricks Account.

## 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" {
name = "ncc"
}

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

## Argument Reference

* `name` - (Required) Name of the network connectivity configuration.

## Attribute Reference

* `account_id` - The Databricks account ID associated with this network configuration.
* `creation_time` - Time in epoch milliseconds when the network was created.
* `egress_config` - Array of egress configuration objects.
* `default_rules` - Array of default rules.
* `aws_stable_ip_rule` - The stable AWS IP CIDR blocks. You can use these to configure the firewall of your resources to allow traffic from your Databricks workspace.
* `cidr_blocks` - The list of stable IP CIDR blocks from which Databricks network traffic originates when accessing your resources.
* `azure_service_endpoint_rule` - Array of Azure service endpoint rules.
* `subnets` - Array of strings representing the subnet IDs.
* `target_region` - The target region for the service endpoint.
* `target_services` - Array of target services.
* `target_rules` - Array of target rules.
* `azure_private_endpoint_rules` - Array of private endpoint rule objects.
* `rule_id` - The ID of a private endpoint rule.
* `network_connectivity_config_id` - The ID of a network connectivity configuration, which is the parent resource of this private endpoint rule object.
* `resource_id` - The Azure resource ID of the target resource.
* `group_id` - The sub-resource type (group ID) of the target resource.
* `endpoint_name` - The name of the Azure private endpoint resource.
* `connection_state` - The current status of this private endpoint.
* `deactivated` - Whether this private endpoint is deactivated.
* `deactivated_at` - Time in epoch milliseconds when this object was deactivated.
* `creation_time` - Time in epoch milliseconds when this object was created.
* `updated_time` - Time in epoch milliseconds when this object was updated.
* `name` - The name of the network connectivity configuration.
* `network_connectivity_config_id` - The Databricks network connectivity configuration ID.
* `region` - The region of the network connectivity configuration.
* `updated_time` - Time in epoch milliseconds when the network was updated.

## Related Resources

The following resources are used in the same context:

* [databricks_mws_network_connectivity_configs](./mws_network_connectivity_configs.md) to get names of all network connectivity configurations.
* [databricks_mws_network_connectivity_config](../resources/mws_network_connectivity_config.md) to manage network connectivity configuration.
55 changes: 55 additions & 0 deletions docs/data-sources/mws_network_connectivity_configs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,55 @@
---
subcategory: "Deployment"
---
# databricks_mws_network_connectivity_configs Data Source

-> **Note** This data source can only be used with an account-level provider!

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

## Example Usage

List all network connectivity configurations in Databricks Account

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

data "databricks_mws_network_connectivity_configs" "this" {}

output "all" {
value = data.databricks_mws_network_connectivity_configs.this
}
```

List network connectivity configurations from a specific region in Databricks Account

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

data "databricks_mws_network_connectivity_configs" "this" {
region = "us-east-1"
}

output "filtered" {
value = data.databricks_mws_network_connectivity_configs.this
}
```

## Argument Reference

* `region` - (Optional) Filter network connectivity configurations by region.

## Attribute Reference

This data source exports the following attributes:

* `names` - List of names of [databricks_mws_network_connectivity_config](./databricks_mws_network_connectivity_config.md)

* [databricks_mws_network_connectivity_config](./mws_network_connectivity_config.md) to get information about a single network connectivity configuration.
* [databricks_mws_network_connectivity_config](../resources/mws_network_connectivity_config.md) to manage network connectivity configuration.
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourceMwsNetworkConnectivityConfigTest(t *testing.T) {
loadWorkspaceEnv(t)
if isGcp(t) {
skipf(t)("GCP not supported")
}
AccountLevel(t,
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]
name = databricks_mws_network_connectivity_config.this.name
}`,
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")
}
name := r.Primary.Attributes["name"]
if name == "" {
return fmt.Errorf("name 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
},
})
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
package acceptance

import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-testing/terraform"
)

func TestAccDataSourceMwsNetworkConnectivityConfigsTest(t *testing.T) {
loadWorkspaceEnv(t)
if isGcp(t) {
skipf(t)("GCP not supported")
}
AccountLevel(t,
Step{
Template: `
resource "databricks_mws_network_connectivity_configs" "this" {
name = "tf-{var.RANDOM}"
region = "eastus2"
}

data "databricks_mws_network_connectivity_configs" "this" {
depends_on = [databricks_mws_network_connectivity_config.this]
region = databricks_mws_network_connectivity_config.this.region
}`,
Check: func(s *terraform.State) error {
r, ok := s.RootModule().Resources["data.databricks_mws_network_connectivity_configs.this"]
if !ok {
return fmt.Errorf("data not found in state")
}
names := r.Primary.Attributes["names"]
if names == "" {
return fmt.Errorf("names is empty: %v", r.Primary.Attributes)
}
return nil
},
})
}
2 changes: 2 additions & 0 deletions internal/providers/sdkv2/sdkv2.go
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,8 @@ func DatabricksProvider(sdkV2Fallbacks ...pluginfw.SdkV2FallbackOption) *schema.
"databricks_mlflow_model": mlflow.DataSourceModel().ToResource(),
"databricks_mlflow_models": mlflow.DataSourceModels().ToResource(),
"databricks_mws_credentials": mws.DataSourceMwsCredentials().ToResource(),
"databricks_mws_network_connectivity_config": mws.DataSourceMwsNetworkConnectivityConfig().ToResource(),
"databricks_mws_network_connectivity_configs": mws.DataSourceMwsNetworkConnectivityConfigs().ToResource(),
"databricks_mws_workspaces": mws.DataSourceMwsWorkspaces().ToResource(),
"databricks_node_type": clusters.DataSourceNodeType().ToResource(),
"databricks_notebook": workspace.DataSourceNotebook().ToResource(),
Expand Down
33 changes: 33 additions & 0 deletions mws/data_mws_network_connectivity_config.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
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 {
type mwsNetworkConnectivityConfiguration struct {
settings.NetworkConnectivityConfiguration
}

type mwsNetworkConnectivityConfigurationParams struct {
Name string `json:"name"`
}

return common.AccountDataWithParams(func(ctx context.Context, data mwsNetworkConnectivityConfigurationParams, a *databricks.AccountClient) (*mwsNetworkConnectivityConfiguration, error) {
list, err := a.NetworkConnectivity.ListNetworkConnectivityConfigurationsAll(ctx, settings.ListNetworkConnectivityConfigurationsRequest{})
if err != nil {
return nil, err
}

for _, ncc := range list {
if data.Name == ncc.Name {
return &mwsNetworkConnectivityConfiguration{NetworkConnectivityConfiguration: ncc}, nil
}
}
return nil, nil
})
}
67 changes: 67 additions & 0 deletions mws/data_mws_network_connectivity_config_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
package mws

import (
"fmt"
"testing"

"github.com/databricks/databricks-sdk-go/experimental/mocks"
"github.com/databricks/databricks-sdk-go/service/settings"
"github.com/stretchr/testify/mock"

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

func TestDataSourceMwsNetworkConnectivityConfig(t *testing.T) {
var ncc = settings.NetworkConnectivityConfiguration{
AccountId: "abc",
CreationTime: 0,
EgressConfig: &settings.NccEgressConfig{
DefaultRules: nil,
TargetRules: nil,
},
Name: "def",
NetworkConnectivityConfigId: "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
Region: "us-east-1",
UpdatedTime: 0,
}

qa.ResourceFixture{
MockAccountClientFunc: func(a *mocks.MockAccountClient) {
api := a.GetMockNetworkConnectivityAPI().EXPECT()
api.ListNetworkConnectivityConfigurationsAll(mock.Anything, settings.ListNetworkConnectivityConfigurationsRequest{}).Return(
[]settings.NetworkConnectivityConfiguration{ncc}, nil,
)
},
AccountID: "abc",
Read: true,
NonWritable: true,
Resource: DataSourceMwsNetworkConnectivityConfig(),
ID: "_",
HCL: fmt.Sprintf(`
name = "%s"
`, ncc.Name),
}.ApplyAndExpectData(t, map[string]interface{}{
"account_id": "abc",
"creation_time": 0,
"egress_config": []interface{}{map[string]interface{}{"default_rules": []interface{}{}, "target_rules": []interface{}{}}},
"id": "_",
"name": "def",
"network_connectivity_config_id": "xxxxxxxx-xxxx-xxxx-xxxx-xxxxxxxxxxxx",
"region": "us-east-1",
"updated_time": 0,
})
}

func TestDataSourceMwsNetworkConnectivityConfig_Error(t *testing.T) {
qa.ResourceFixture{
Fixtures: qa.HTTPFailures,
AccountID: "abc",
Resource: DataSourceMwsNetworkConnectivityConfig(),
Read: true,
NonWritable: true,
ID: "_",
HCL: `
name = "def"
`,
}.ExpectError(t, "i'm a teapot")
}
43 changes: 43 additions & 0 deletions mws/data_mws_network_connectivity_configs.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
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 DataSourceMwsNetworkConnectivityConfigs() common.Resource {
type mwsNetworkConnectivityConfiguration struct {
Names []string `json:"names" tf:"computed,optional"`
}

type mwsNetworkConnectivityConfigurationParams struct {
Names []string `json:"names" tf:"computed,optional"`
Region string `json:"region" tf:"optional"`
}

return common.AccountDataWithParams(func(ctx context.Context, data mwsNetworkConnectivityConfigurationParams, a *databricks.AccountClient) (*mwsNetworkConnectivityConfiguration, error) {
list, err := a.NetworkConnectivity.ListNetworkConnectivityConfigurationsAll(ctx, settings.ListNetworkConnectivityConfigurationsRequest{})
if err != nil {
return nil, err
}

if data.Region != "" {
filtered := []string{}
for _, ncc := range list {
if data.Region == ncc.Region {
filtered = append(filtered, ncc.Name)
}
}
return &mwsNetworkConnectivityConfiguration{Names: filtered}, nil
}

names := []string{}
for _, ncc := range list {
names = append(names, ncc.Name)
}
return &mwsNetworkConnectivityConfiguration{Names: names}, nil
})
}
Loading