-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
New data source:
azurerm_databricks_workspace
(#8502)
Fixes #8475
- Loading branch information
Showing
4 changed files
with
181 additions
and
1 deletion.
There are no files selected for viewing
76 changes: 76 additions & 0 deletions
76
azurerm/internal/services/databricks/databricks_workspace_data_source.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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 | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
53 changes: 53 additions & 0 deletions
53
azurerm/internal/services/databricks/tests/databricks_workspace_data_source_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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) | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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. |