Skip to content

Commit d60e113

Browse files
authored
Add attribute workspace_url for current_user data source (databricks#1107)
it helps to work with some resources, like, `mlflow_webhook` that require URL of the workspace
1 parent 7d2ab13 commit d60e113

File tree

5 files changed

+18
-10
lines changed

5 files changed

+18
-10
lines changed

CHANGELOG.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Version changelog
22

3+
## 0.5.0
4+
5+
* Added `workspace_url` attribute to the `databricks_current_user` data source ([#1107](https://github.com/databrickslabs/terraform-provider-databricks/pull/1107))
6+
37
## 0.4.9
48

59
* Prevent creation of `databricks_group` with `users` and `admins` reserved names ([#1089](https://github.com/databrickslabs/terraform-provider-databricks/issues/1089)).

common/http.go

+1-1
Original file line numberDiff line numberDiff line change
@@ -482,7 +482,7 @@ func (c *DatabricksClient) genericQuery(ctx context.Context, method, requestURL
482482
}
483483
}
484484
headers := c.createDebugHeaders(request.Header, c.Host)
485-
log.Printf("[DEBUG] %s %s %s%v", method, escapeNewLines(request.URL.Path),
485+
log.Printf("[DEBUG] %s %s %s%v", method, escapeNewLines(request.URL.Path),
486486
headers, c.redactedDump(requestBody)) // lgtm [go/log-injection]
487487

488488
r, err := retryablehttp.FromRequest(request)

docs/data-sources/current_user.md

+1
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ Data source exposes the following attributes:
6161
* `home` - Home folder of the [user](../resources/user.md), e.g. `/Users/[email protected]`.
6262
* `repos` - Personal Repos location of the [user](../resources/user.md), e.g. `/Repos/[email protected]`.
6363
* `alphanumeric` - Alphanumeric representation of user local name. e.g. `mr_foo`.
64+
* `workspace_url` - URL of the current Databricks workspace.
6465

6566

6667
## Related Resources

docs/resources/mlflow_webhook.md

+7-9
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,6 @@ This resource allows you to create [MLflow Model Registry Webhooks](https://docs
1010
### Triggering Databricks job
1111

1212
```hcl
13-
variable "dbhost" {
14-
description = "URL of Databricks workspace"
15-
}
16-
variable "dbtoken" {
17-
description = "Token to access Databricks workspace"
18-
}
19-
2013
data "databricks_current_user" "me" {}
2114
data "databricks_spark_version" "latest" {}
2215
data "databricks_node_type" "smallest" {
@@ -50,14 +43,19 @@ resource "databricks_job" "this" {
5043
}
5144
}
5245
46+
resource "databricks_token" "pat_for_webhook" {
47+
comment = "MLflow Webhook"
48+
lifetime_seconds = 86400000
49+
}
50+
5351
resource "databricks_mlflow_webhook" "job" {
5452
events = ["TRANSITION_REQUEST_CREATED"]
5553
description = "Databricks Job webhook trigger"
5654
status = "ACTIVE"
5755
job_spec {
5856
job_id = databricks_job.this.id
59-
workspace_url = var.dbhost
60-
access_token = var.dbtoken
57+
workspace_url = data.databricks_current_user.me.workspace_url
58+
access_token = databricks_token.pat_for_webhook.token_value
6159
}
6260
}
6361
```

scim/data_current_user.go

+5
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,10 @@ func DataSourceCurrentUser() *schema.Resource {
3636
Type: schema.TypeString,
3737
Computed: true,
3838
},
39+
"workspace_url": {
40+
Type: schema.TypeString,
41+
Computed: true,
42+
},
3943
},
4044
ReadContext: func(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics {
4145
usersAPI := NewUsersAPI(ctx, m)
@@ -51,6 +55,7 @@ func DataSourceCurrentUser() *schema.Resource {
5155
norm := nonAlphanumeric.ReplaceAllLiteralString(splits[0], "_")
5256
norm = strings.ToLower(norm)
5357
d.Set("alphanumeric", norm)
58+
d.Set("workspace_url", usersAPI.client.Host)
5459
d.SetId(me.ID)
5560
return nil
5661
},

0 commit comments

Comments
 (0)