Skip to content

Commit

Permalink
databricks - custom parameters nil check and naming
Browse files Browse the repository at this point in the history
  • Loading branch information
notchairmk committed Jan 20, 2020
1 parent 59dea4b commit d50a0ca
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 15 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -69,7 +69,7 @@ func resourceArmDatabricksWorkspace() *schema.Resource {
ValidateFunc: validate.NoEmptyStrings,
},

"workspace_custom_parameters": {
"custom_parameters": {
Type: schema.TypeList,
Optional: true,
Computed: true,
Expand Down Expand Up @@ -220,7 +220,7 @@ func resourceArmDatabricksWorkspaceRead(d *schema.ResourceData, meta interface{}
}
d.Set("managed_resource_group_id", props.ManagedResourceGroupID)
d.Set("managed_resource_group_name", managedResourceGroupID.ResourceGroup)
d.Set("workspace_custom_parameters", flattenWorkspaceCustomParameters(props.Parameters))
d.Set("custom_parameters", flattenWorkspaceCustomParameters(props.Parameters))
}

return tags.FlattenAndSet(d, resp.Tags)
Expand Down Expand Up @@ -260,22 +260,28 @@ func flattenWorkspaceCustomParameters(p *databricks.WorkspaceCustomParameters) [

parameters := make(map[string]interface{})
if privateSubnet := p.CustomPrivateSubnetName; privateSubnet != nil {
parameters["private_subnet_name"] = *privateSubnet.Value
if privateSubnet.Value != nil {
parameters["private_subnet_name"] = *privateSubnet.Value
}
}

if publicSubnet := p.CustomPublicSubnetName; publicSubnet != nil {
parameters["public_subnet_name"] = *publicSubnet.Value
if publicSubnet.Value != nil {
parameters["public_subnet_name"] = *publicSubnet.Value
}
}

if vnetID := p.CustomVirtualNetworkID; vnetID != nil {
parameters["virtual_network_id"] = *vnetID.Value
if vnetID.Value != nil {
parameters["virtual_network_id"] = *vnetID.Value
}
}

return []interface{}{parameters}
}

func expandWorkspaceCustomParameters(d *schema.ResourceData) *databricks.WorkspaceCustomParameters {
configList, ok := d.GetOkExists("workspace_custom_parameters")
configList, ok := d.GetOkExists("custom_parameters")
if !ok {
return nil
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,9 +131,9 @@ func TestAccAzureRMDatabricksWorkspace_complete(t *testing.T) {
testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "workspace_custom_parameters.0.virtual_network_id"),
resource.TestCheckResourceAttr(data.ResourceName, "workspace_custom_parameters.0.public_subnet_name", "public"),
resource.TestCheckResourceAttr(data.ResourceName, "workspace_custom_parameters.0.private_subnet_name", "private"),
resource.TestCheckResourceAttrSet(data.ResourceName, "custom_parameters.0.virtual_network_id"),
resource.TestCheckResourceAttr(data.ResourceName, "custom_parameters.0.public_subnet_name", "public"),
resource.TestCheckResourceAttr(data.ResourceName, "custom_parameters.0.private_subnet_name", "private"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.Environment", "Production"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.Pricing", "Standard"),
Expand All @@ -145,9 +145,9 @@ func TestAccAzureRMDatabricksWorkspace_complete(t *testing.T) {
testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "workspace_custom_parameters.0.virtual_network_id"),
resource.TestCheckResourceAttr(data.ResourceName, "workspace_custom_parameters.0.public_subnet_name", "public"),
resource.TestCheckResourceAttr(data.ResourceName, "workspace_custom_parameters.0.private_subnet_name", "private"),
resource.TestCheckResourceAttrSet(data.ResourceName, "custom_parameters.0.virtual_network_id"),
resource.TestCheckResourceAttr(data.ResourceName, "custom_parameters.0.public_subnet_name", "public"),
resource.TestCheckResourceAttr(data.ResourceName, "custom_parameters.0.private_subnet_name", "private"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "1"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.Pricing", "Standard"),
),
Expand Down Expand Up @@ -328,7 +328,7 @@ resource "azurerm_databricks_workspace" "test" {
sku = "standard"
managed_resource_group_name = "acctestRG-%d-managed"
workspace_custom_parameters {
custom_parameters {
public_subnet_name = "${azurerm_subnet.public.name}"
private_subnet_name = "${azurerm_subnet.private.name}"
virtual_network_id = "${azurerm_virtual_network.test.id}"
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/databricks_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -46,13 +46,13 @@ The following arguments are supported:

~> **NOTE** Azure requires that this Resource Group does not exist in this Subscription (and that the Azure API creates it) - otherwise the deployment will fail.

* `workspace_custom_parameters` - (Optional) A `workspace_custom_parameters` block as documented below.
* `custom_parameters` - (Optional) A `custom_parameters` block as documented below.

* `tags` - (Optional) A mapping of tags to assign to the resource.

---

`workspace_custom_parameters` supports the following:
`custom_parameters` supports the following:

* `public_subnet_name` - (Optional) The name of the Public Subnet within the Virtual Network. Required if `virtual_network_id` is set.

Expand Down

0 comments on commit d50a0ca

Please sign in to comment.