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

azurerm_databricks_workspace - changing the sku no longer forces a new resource unless it is required #9541

Merged
merged 3 commits into from
Jan 13, 2021
Merged
Show file tree
Hide file tree
Changes from all 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
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,6 @@ func resourceDatabricksWorkspace() *schema.Resource {
"sku": {
Type: schema.TypeString,
Required: true,
ForceNew: true,
ValidateFunc: validation.StringInSlice([]string{
"standard",
"premium",
Expand Down Expand Up @@ -123,6 +122,21 @@ func resourceDatabricksWorkspace() *schema.Resource {
Computed: true,
},
},

CustomizeDiff: func(d *schema.ResourceDiff, v interface{}) error {
if d.HasChange("sku") {
sku, changedSKU := d.GetChange("sku")

if changedSKU == "trial" {
log.Printf("[DEBUG] recreate databricks workspace, could't be migrated to %s", changedSKU)
d.ForceNew("sku")
} else {
log.Printf("[DEBUG] databricks workspace can be upgraded from %s to %s", sku, changedSKU)
}
}

return nil
},
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -113,7 +113,7 @@ func TestAccDatabricksWorkspace_basic(t *testing.T) {

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.basic(data),
Config: r.basic(data, "standard"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
check.That(data.ResourceName).Key("managed_resource_group_id").Exists(),
Expand All @@ -131,7 +131,7 @@ func TestAccDatabricksWorkspace_requiresImport(t *testing.T) {

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.basic(data),
Config: r.basic(data, "standard"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
Expand Down Expand Up @@ -193,6 +193,35 @@ func TestAccDatabricksWorkspace_update(t *testing.T) {
})
}

func TestAccDatabricksWorkspace_updateSKU(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_databricks_workspace", "test")
r := DatabricksWorkspaceResource{}

data.ResourceTest(t, r, []resource.TestStep{
{
Config: r.basic(data, "trial"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data, "standard"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
{
Config: r.basic(data, "trial"),
Check: resource.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func (DatabricksWorkspaceResource) Exists(ctx context.Context, clients *clients.Client, state *terraform.InstanceState) (*bool, error) {
id, err := parse.WorkspaceID(state.ID)
if err != nil {
Expand All @@ -207,7 +236,7 @@ func (DatabricksWorkspaceResource) Exists(ctx context.Context, clients *clients.
return utils.Bool(resp.WorkspaceProperties != nil), nil
}

func (DatabricksWorkspaceResource) basic(data acceptance.TestData) string {
func (DatabricksWorkspaceResource) basic(data acceptance.TestData, sku string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
Expand All @@ -222,13 +251,13 @@ resource "azurerm_databricks_workspace" "test" {
name = "acctestDBW-%d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
sku = "standard"
sku = "%s"
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, sku)
}

func (DatabricksWorkspaceResource) requiresImport(data acceptance.TestData) string {
template := DatabricksWorkspaceResource{}.basic(data)
template := DatabricksWorkspaceResource{}.basic(data, "standard")
return fmt.Sprintf(`
%s

Expand Down
4 changes: 3 additions & 1 deletion website/docs/r/databricks_workspace.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,9 @@ The following arguments are supported:

* `location` - (Required) Specifies the supported Azure location where the resource has to be created. Changing this forces a new resource to be created.

* `sku` - (Required) The `sku` to use for the Databricks Workspace. Possible values are `standard`, `premium`, or `trial`. Changing this forces a new resource to be created.
* `sku` - (Required) The `sku` to use for the Databricks Workspace. Possible values are `standard`, `premium`, or `trial`. Changing this can force a new resource to be created in some circumstances.

~> **NOTE** While downgrading to `trial`, the Databricks Workspace resource would be recreated.

* `managed_resource_group_name` - (Optional) The name of the resource group where Azure should place the managed Databricks resources. Changing this forces a new resource to be created.

Expand Down