Skip to content

Commit fb3e15b

Browse files
authored
[Exporter] Support exporting of databricks_mws_ncc_binding (#5184)
## Changes <!-- Summary of your changes that are easy to understand --> ## Tests <!-- How is this tested? Please see the checklist below and also describe any other relevant tests --> - [x] `make test` run locally - [x] relevant change in `docs/` folder - [ ] covered with integration tests in `internal/acceptance` - [x] using Go SDK - [ ] using TF Plugin Framework - [x] has entry in `NEXT_CHANGELOG.md` file
1 parent 99a0ada commit fb3e15b

File tree

5 files changed

+60
-3
lines changed

5 files changed

+60
-3
lines changed

NEXT_CHANGELOG.md

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

1717
### Exporter
1818

19+
* Support exporting of `databricks_mws_ncc_binding` ([#5184](https://github.com/databricks/terraform-provider-databricks/pull/5184)).
1920
* Initial support for resources implemented with plugin framework ([#5176](https://github.com/databricks/terraform-provider-databricks/pull/5176)).
2021

2122
### Internal Changes

docs/guides/experimental-exporter.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -167,7 +167,7 @@ Services could be specified in combination with predefined aliases (`all` - for
167167
* `model-serving` - **listing** [databricks_model_serving](../resources/model_serving.md).
168168
* `mounts` - **listing** works only in combination with `-mounts` command-line option.
169169
* `mws` - **listing** resources related to deployment of workspaces on AWS and GCP (networks, credentials, workspaces, ...).
170-
* `nccs` - **listing** [databricks_mws_network_connectivity_config](../resources/mws_network_connectivity_config.md) and [databricks_mws_ncc_private_endpoint_rule](../resources/mws_ncc_private_endpoint_rule.md). **Note** we can't export [databricks_mws_ncc_binding](../resources/mws_ncc_binding.md) because of the missing API.
170+
* `nccs` - **listing** [databricks_mws_network_connectivity_config](../resources/mws_network_connectivity_config.md), [databricks_mws_ncc_private_endpoint_rule](../resources/mws_ncc_private_endpoint_rule.md), and [databricks_mws_ncc_binding](../resources/mws_ncc_binding.md).
171171
* `notebooks` - **listing** [databricks_notebook](../resources/notebook.md).
172172
* `policies` - **listing** [databricks_cluster_policy](../resources/cluster_policy).
173173
* `pools` - **listing** [instance pools](../resources/instance_pool.md).
@@ -251,7 +251,7 @@ Exporter aims to generate HCL code for most of the resources within the Databric
251251
| [databricks_model_serving](../resources/model_serving) | Yes | Yes | Yes | No |
252252
| [databricks_mws_credentials](../resources/mws_credentials.md) | Yes | Yes | No | Yes |
253253
| [databricks_mws_customer_managed_keys](../resources/mws_customer_managed_keys.md) | Yes | Yes | No | Yes |
254-
| [databricks_mws_ncc_binding](../resources/mws_ncc_binding.md) | No | No | No | No |
254+
| [databricks_mws_ncc_binding](../resources/mws_ncc_binding.md) | Yes | No | No | Yes |
255255
| [databricks_mws_ncc_private_endpoint_rule](../resources/mws_ncc_private_endpoint_rule.md) | Yes | No | No | Yes |
256256
| [databricks_mws_network_connectivity_config](../resources/mws_network_connectivity_config.md) | Yes | Yes | No | Yes |
257257
| [databricks_mws_networks](../resources/mws_networks.md) | Yes | No | No | Yes |

exporter/importables.go

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2822,6 +2822,9 @@ var resourcesMap map[string]importable = map[string]importable{
28222822
"databricks_mws_network_connectivity_config": {
28232823
AccountLevel: true,
28242824
Service: "nccs",
2825+
Name: func(ic *importContext, d *schema.ResourceData) string {
2826+
return d.Get("name").(string)
2827+
},
28252828
List: func(ic *importContext) error {
28262829
updatedSinceMs := ic.getUpdatedSinceMs()
28272830
it := ic.accountClient.NetworkConnectivity.ListNetworkConnectivityConfigurations(ic.Context,
@@ -2844,7 +2847,6 @@ var resourcesMap map[string]importable = map[string]importable{
28442847
ic.Emit(&resource{
28452848
Resource: "databricks_mws_network_connectivity_config",
28462849
ID: nc.AccountId + "/" + nc.NetworkConnectivityConfigId,
2847-
Name: nc.Name,
28482850
})
28492851
if nc.EgressConfig.TargetRules != nil {
28502852
for _, rule := range nc.EgressConfig.TargetRules.AzurePrivateEndpointRules {
@@ -2878,6 +2880,35 @@ var resourcesMap map[string]importable = map[string]importable{
28782880
Match: "network_connectivity_config_id"},
28792881
},
28802882
},
2883+
"databricks_mws_ncc_binding": {
2884+
AccountLevel: true,
2885+
Service: "nccs",
2886+
List: func(ic *importContext) error {
2887+
workspaces, err := ic.accountClient.Workspaces.List(ic.Context)
2888+
if err != nil {
2889+
return err
2890+
}
2891+
for _, workspace := range workspaces {
2892+
if workspace.NetworkConnectivityConfigId != "" {
2893+
ic.emitNccBindingAndNcc(workspace.WorkspaceId, workspace.NetworkConnectivityConfigId)
2894+
if !ic.accountClient.Config.IsAzure() {
2895+
wsIdString := strconv.FormatInt(workspace.WorkspaceId, 10)
2896+
ic.Emit(&resource{
2897+
Resource: "databricks_mws_workspaces",
2898+
ID: ic.accountClient.Config.AccountID + "/" + wsIdString,
2899+
Name: workspace.WorkspaceName + "_" + wsIdString,
2900+
})
2901+
}
2902+
}
2903+
}
2904+
return nil
2905+
},
2906+
Depends: []reference{
2907+
{Path: "network_connectivity_config_id", Resource: "databricks_mws_network_connectivity_config",
2908+
Match: "network_connectivity_config_id"},
2909+
{Path: "workspace_id", Resource: "databricks_mws_workspaces", Match: "workspace_id"},
2910+
},
2911+
},
28812912
"databricks_mws_credentials": {
28822913
AccountLevel: true,
28832914
Service: "mws",
@@ -3096,6 +3127,7 @@ var resourcesMap map[string]importable = map[string]importable{
30963127
Service: "mws",
30973128
List: func(ic *importContext) error {
30983129
if ic.accountClient.Config.IsAzure() {
3130+
// TODO: use listing on Azure just to emit the NCC bindings
30993131
return nil
31003132
}
31013133
workspaces, err := ic.accountClient.Workspaces.List(ic.Context)
@@ -3166,6 +3198,9 @@ var resourcesMap map[string]importable = map[string]importable{
31663198
ID: ic.accountClient.Config.AccountID + "/" + workspace.CredentialsID,
31673199
})
31683200
}
3201+
if workspace.NetworkConnectivityConfigID != "" {
3202+
ic.emitNccBindingAndNcc(workspace.WorkspaceID, workspace.NetworkConnectivityConfigID)
3203+
}
31693204
if ic.isServiceEnabled("idfed") {
31703205
err := emitIdfedAndUsersSpsGroups(ic, workspace.WorkspaceID)
31713206
if err != nil {

exporter/util.go

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ import (
1515
"github.com/databricks/terraform-provider-databricks/aws"
1616
"github.com/databricks/terraform-provider-databricks/clusters"
1717
"github.com/databricks/terraform-provider-databricks/common"
18+
"github.com/databricks/terraform-provider-databricks/mws"
1819
"github.com/databricks/terraform-provider-databricks/storage"
1920
"golang.org/x/exp/maps"
2021

@@ -567,3 +568,22 @@ func makeNameOrIdFunc(nm string) func(ic *importContext, d *schema.ResourceData)
567568
return name
568569
}
569570
}
571+
572+
func (ic *importContext) emitNccBindingAndNcc(workspaceId int64, nccId string) {
573+
id := fmt.Sprintf("%d/%s", workspaceId, nccId)
574+
data := mws.ResourceMwsNccBinding().ToResource().TestResourceData()
575+
data.MarkNewResource()
576+
data.SetId(id)
577+
data.Set("workspace_id", workspaceId)
578+
data.Set("network_connectivity_config_id", nccId)
579+
ic.Emit(&resource{
580+
Resource: "databricks_mws_ncc_binding",
581+
Data: data,
582+
ID: id,
583+
Name: fmt.Sprintf("ws_%d_%s", workspaceId, nccId),
584+
})
585+
ic.Emit(&resource{
586+
Resource: "databricks_mws_network_connectivity_config",
587+
ID: ic.accountClient.Config.AccountID + "/" + nccId,
588+
})
589+
}

mws/resource_mws_workspaces.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -108,6 +108,7 @@ type Workspace struct {
108108
CustomTags map[string]string `json:"custom_tags,omitempty"` // Optional for AWS, not allowed for GCP
109109
ComputeMode string `json:"compute_mode,omitempty" tf:"force_new"`
110110
EffectiveComputeMode string `json:"effective_compute_mode" tf:"computed"`
111+
NetworkConnectivityConfigID string `json:"network_connectivity_config_id,omitempty" tf:"computed"`
111112
}
112113

113114
// this type alias hack is required for Marshaller to work without an infinite loop

0 commit comments

Comments
 (0)