Skip to content

Commit

Permalink
azurerm_databricks_workspace: support for the no_public_ip custom par…
Browse files Browse the repository at this point in the history
…ameter (#5469)
  • Loading branch information
katbyte authored Jan 22, 2020
1 parent d425cbf commit b7d1cca
Show file tree
Hide file tree
Showing 3 changed files with 83 additions and 35 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -76,20 +76,29 @@ func resourceArmDatabricksWorkspace() *schema.Resource {
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"no_public_ip": {
Type: schema.TypeBool,
ForceNew: true,
Optional: true,
},

"public_subnet_name": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
},

"private_subnet_name": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
},

"virtual_network_id": {
Type: schema.TypeString,
ForceNew: true,
Optional: true,
Type: schema.TypeString,
ForceNew: true,
Optional: true,
ValidateFunc: azure.ValidateResourceIDOrEmpty,
},
},
},
Expand Down Expand Up @@ -259,21 +268,28 @@ func flattenWorkspaceCustomParameters(p *databricks.WorkspaceCustomParameters) [
}

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

if v := p.EnableNoPublicIP; v != nil {
if v.Value != nil {
parameters["no_public_ip"] = *v.Value
}
}

if v := p.CustomPrivateSubnetName; v != nil {
if v.Value != nil {
parameters["private_subnet_name"] = *v.Value
}
}

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

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

Expand All @@ -288,6 +304,12 @@ func expandWorkspaceCustomParameters(d *schema.ResourceData) *databricks.Workspa
config := configList.([]interface{})[0].(map[string]interface{})
parameters := databricks.WorkspaceCustomParameters{}

if v, ok := config["no_public_ip"].(bool); ok {
parameters.EnableNoPublicIP = &databricks.WorkspaceCustomBooleanParameter{
Value: &v,
}
}

if v := config["public_subnet_name"].(string); v != "" {
parameters.CustomPublicSubnetName = &databricks.WorkspaceCustomStringParameter{
Value: &v,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -109,15 +109,37 @@ func TestAccAzureRMDatabricksWorkspace_requiresImport(t *testing.T) {
testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName),
),
},
data.RequiresImportErrorStep(testAccAzureRMDatabricksWorkspace_requiresImport),
},
})
}

func TestAccAzureRMDatabricksWorkspace_complete(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMDatabricksWorkspaceDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMDatabricksWorkspace_requiresImport(data),
ExpectError: acceptance.RequiresImportError("azurerm_databricks_workspace"),
Config: testAccAzureRMDatabricksWorkspace_complete(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_name"),
resource.TestCheckResourceAttrSet(data.ResourceName, "custom_parameters.0.virtual_network_id"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.%", "2"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.Environment", "Production"),
resource.TestCheckResourceAttr(data.ResourceName, "tags.Pricing", "Standard"),
),
},
data.ImportStep(),
},
})
}

func TestAccAzureRMDatabricksWorkspace_complete(t *testing.T) {
func TestAccAzureRMDatabricksWorkspace_update(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test")

resource.ParallelTest(t, resource.TestCase{
Expand All @@ -132,22 +154,18 @@ func TestAccAzureRMDatabricksWorkspace_complete(t *testing.T) {
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_name"),
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"),
),
},
data.ImportStep(),
{
Config: testAccAzureRMDatabricksWorkspace_completeUpdate(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMDatabricksWorkspaceExists(data.ResourceName),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_id"),
resource.TestCheckResourceAttrSet(data.ResourceName, "managed_resource_group_name"),
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 @@ -214,12 +232,12 @@ func testCheckAzureRMDatabricksWorkspaceDestroy(s *terraform.State) error {
func testAccAzureRMDatabricksWorkspace_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-db-%d"
location = "%s"
}
resource "azurerm_databricks_workspace" "test" {
name = "acctestdbw-%d"
name = "acctestDBW-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
sku = "standard"
Expand All @@ -233,7 +251,7 @@ func testAccAzureRMDatabricksWorkspace_requiresImport(data acceptance.TestData)
%s
resource "azurerm_databricks_workspace" "import" {
name = "$[azurerm_databricks_workspace.test.name}"
name = "${azurerm_databricks_workspace.test.name}"
resource_group_name = "${azurerm_databricks_workspace.test.resource_group_name}"
location = "${azurerm_databricks_workspace.test.location}"
sku = "${azurerm_databricks_workspace.test.sku}"
Expand All @@ -244,19 +262,20 @@ resource "azurerm_databricks_workspace" "import" {
func testAccAzureRMDatabricksWorkspace_complete(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
name = "acctestRG-db-%[1]d"
location = "%[2]s"
}
resource "azurerm_virtual_network" "test" {
name = "test"
name = "acctest-vnet-%[1]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
address_space = ["10.0.0.0/16"]
}
resource "azurerm_subnet" "public" {
name = "public"
name = "acctest-sn-public-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.1.0/24"
Expand All @@ -281,7 +300,7 @@ resource "azurerm_subnet" "public" {
}
resource "azurerm_subnet" "private" {
name = "private"
name = "acctest-sn-private-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
virtual_network_name = "${azurerm_virtual_network.test.name}"
address_prefix = "10.0.2.0/24"
Expand All @@ -306,7 +325,7 @@ resource "azurerm_subnet" "private" {
}
resource "azurerm_network_security_group" "nsg" {
name = "private-nsg"
name = "acctest-nsg-private-%[1]d"
location = "${azurerm_resource_group.test.location}"
resource_group_name = "${azurerm_resource_group.test.name}"
}
Expand All @@ -322,13 +341,14 @@ resource "azurerm_subnet_network_security_group_association" "private" {
}
resource "azurerm_databricks_workspace" "test" {
name = "acctestdbw-%d"
name = "acctestDBW-%[1]d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
sku = "standard"
managed_resource_group_name = "acctestRG-%d-managed"
managed_resource_group_name = "acctestRG-DBW-%[1]d-managed"
custom_parameters {
no_public_ip = true
public_subnet_name = "${azurerm_subnet.public.name}"
private_subnet_name = "${azurerm_subnet.private.name}"
virtual_network_id = "${azurerm_virtual_network.test.id}"
Expand All @@ -339,26 +359,30 @@ resource "azurerm_databricks_workspace" "test" {
Pricing = "Standard"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary)
}

func testAccAzureRMDatabricksWorkspace_completeUpdate(data acceptance.TestData) string {
return fmt.Sprintf(`
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
name = "acctestRG-db-%d"
location = "%s"
}
resource "azurerm_databricks_workspace" "test" {
name = "acctestdbw-%d"
name = "acctestDBW-%d"
resource_group_name = "${azurerm_resource_group.test.name}"
location = "${azurerm_resource_group.test.location}"
sku = "standard"
managed_resource_group_name = "acctestRG-%d-managed"
managed_resource_group_name = "acctestRG-DBW-%d-managed"
tags = {
Pricing = "Standard"
}
custom_parameters {
no_public_ip = false
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger)
}
2 changes: 2 additions & 0 deletions website/docs/r/databricks_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ The following arguments are supported:

`custom_parameters` supports the following:

* `no_public_ip` - (Optional) Are public IP Addresses not allowed?

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

* `private_subnet_name` - (Optional) The name of the Private Subnet within the Virtual Network. Required if `virtual_network_id` is set.
Expand Down

0 comments on commit b7d1cca

Please sign in to comment.