Skip to content

Commit

Permalink
New data source: azurerm_databricks_workspace (#8502)
Browse files Browse the repository at this point in the history
Fixes #8475
  • Loading branch information
favoretti authored Sep 19, 2020
1 parent 27f18df commit ba71bb4
Show file tree
Hide file tree
Showing 4 changed files with 181 additions and 1 deletion.
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
package databricks

import (
"fmt"
"time"

"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils"
)

func dataSourceArmDatabricksWorkspace() *schema.Resource {
return &schema.Resource{
Read: dataSourceDatabricksWorkspaceRead,

Timeouts: &schema.ResourceTimeout{
Read: schema.DefaultTimeout(5 * time.Minute),
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Required: true,
},

"resource_group_name": azure.SchemaResourceGroupNameForDataSource(),

"sku": {
Type: schema.TypeString,
Computed: true,
},

"workspace_id": {
Type: schema.TypeString,
Computed: true,
},

"workspace_url": {
Type: schema.TypeString,
Computed: true,
},
},
}
}

func dataSourceDatabricksWorkspaceRead(d *schema.ResourceData, meta interface{}) error {
client := meta.(*clients.Client).DataBricks.WorkspacesClient
ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d)
defer cancel()

name := d.Get("name").(string)
resourceGroup := d.Get("resource_group_name").(string)

resp, err := client.Get(ctx, resourceGroup, name)
if err != nil {
if utils.ResponseWasNotFound(resp.Response) {
return fmt.Errorf("Error: Databricks Workspace %q (Resource Group %q) was not found", name, resourceGroup)
}

return fmt.Errorf("Error making Read request on EventHub %q (Resource Group %q): %+v", name, resourceGroup, err)
}

d.SetId(*resp.ID)

d.Set("name", name)
d.Set("resource_group_name", resourceGroup)
d.Set("sku", resp.Sku.Name)
if props := resp.WorkspaceProperties; props != nil {
d.Set("workspace_id", props.WorkspaceID)
d.Set("workspace_url", props.WorkspaceURL)
}

return nil
}
4 changes: 3 additions & 1 deletion azurerm/internal/services/databricks/registration.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,9 @@ func (r Registration) WebsiteCategories() []string {

// SupportedDataSources returns the supported Data Sources supported by this Service
func (r Registration) SupportedDataSources() map[string]*schema.Resource {
return map[string]*schema.Resource{}
return map[string]*schema.Resource{
"azurerm_databricks_workspace": dataSourceArmDatabricksWorkspace(),
}
}

// SupportedResources returns the supported Resources supported by this Service
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
package tests

import (
"fmt"
"regexp"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/helper/resource"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance"
)

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

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
Steps: []resource.TestStep{
{
Config: testAccDataSourceDatabricksWorkspace_basic(data),
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(data.ResourceName, "workspace_url", regexp.MustCompile("azuredatabricks.net")),
resource.TestCheckResourceAttrSet(data.ResourceName, "workspace_id"),
),
},
},
})
}

func testAccDataSourceDatabricksWorkspace_basic(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-databricks-%d"
location = "%s"
}
resource "azurerm_databricks_workspace" "test" {
name = "acctestDBW-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
sku = "standard"
}
data "azurerm_databricks_workspace" "test" {
name = azurerm_databricks_workspace.test.name
resource_group_name = azurerm_resource_group.test.name
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}
49 changes: 49 additions & 0 deletions website/docs/d/databricks_workspace.html.markdown
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
---
subcategory: "Databricks"
layout: "azurerm"
page_title: "Azure Resource Manager: azurerm_databricks_workspace"
description: |-
Gets information on an existing Databricks Workspace
---

# Data Source: azurerm_databricks_workspace

Use this data source to access information about an existing Databricks workspace.

## Example Usage

```hcl
data "azurerm_databricks_workspace" "example" {
name = "example-workspace"
resource_group_name = "example-rg"
}
output "databricks_workspace_id" {
value = data.azurerm_databricks_workspace.example.workspace_id
}
```

## Argument Reference

* `name` - The name of the Databricks Workspace.
* `resource_group_name` - The Name of the Resource Group where the Databricks Workspace exists.

## Attributes Reference

* `id` - The ID of the Databricks Workspace.

* `location` - The Azure location where the Databricks Workspace exists.

* `sku` - SKU of this Databricks Workspace.

* `workspace_id` - Unique ID of this Databricks Workspace in Databricks management plane.

* `workspace_url` - URL this Databricks Workspace is accessible on.

* `tags` - A mapping of tags to assign to the Databricks Workspace.

## Timeouts

The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions:

* `read` - (Defaults to 5 minutes) Used when retrieving the Databricks Workspace.

0 comments on commit ba71bb4

Please sign in to comment.