Skip to content

Commit 06da533

Browse files
alexottmgyucht
andauthored
Modify databricks_repo to support Git folders in the workspace (#3447)
* Modify `databricks_repo` to support Git folders in the workspace Changes include: * adjust `path` check to enforce it only on `/Repos`, not everywhere. * adjust documentation * address comments --------- Co-authored-by: Miles Yucht <[email protected]>
1 parent 5d255ad commit 06da533

File tree

3 files changed

+19
-23
lines changed

3 files changed

+19
-23
lines changed

docs/resources/repo.md

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,13 @@ subcategory: "Workspace"
33
---
44
# databricks_repo Resource
55

6-
This resource allows you to manage [Databricks Repos](https://docs.databricks.com/repos.html).
6+
This resource allows you to manage [Databricks Git folders](https://docs.databricks.com/en/repos/index.html) (formerly known as Databricks Repos).
77

8-
-> **Note** To create a Repo from a private repository you need to configure Git token as described in the [documentation](https://docs.databricks.com/repos.html#configure-your-git-integration-with-databricks). To set this token you can use [databricks_git_credential](git_credential.md) resource.
8+
-> **Note** To create a Git folder from a private repository you need to configure Git token as described in the [documentation](https://docs.databricks.com/en/repos/index.html#configure-your-git-integration-with-databricks). To set this token you can use [databricks_git_credential](git_credential.md) resource.
99

1010
## Example Usage
1111

12-
You can declare Terraform-managed Repo by specifying `url` attribute of Git repository. In addition to that you may need to specify `git_provider` attribute if Git provider doesn't belong to cloud Git providers (Github, GitLab, ...). If `path` attribute isn't provided, then repo will be created in the user's repo directory (`/Repos/<username>/...`):
12+
You can declare Terraform-managed Git folder by specifying `url` attribute of Git repository. In addition to that you may need to specify `git_provider` attribute if Git provider doesn't belong to cloud Git providers (Github, GitLab, ...). If `path` attribute isn't provided, then Git folder will be created in the default location:
1313

1414

1515
```hcl
@@ -20,30 +20,30 @@ resource "databricks_repo" "nutter_in_home" {
2020

2121
## Argument Reference
2222

23-
-> **Note** Repo in Databricks workspace would only be changed, if Terraform stage did change. This means that any manual changes to managed repository won't be overwritten by Terraform, if there's no local changes to configuration. If Repo in Databricks workspace is modifying, application of configuration changes will fail.
23+
-> **Note** Git folder in Databricks workspace would only be changed, if Terraform stage did change. This means that any manual changes to managed repository won't be overwritten by Terraform, if there's no local changes to configuration. If Git folder in Databricks workspace is modified, application of configuration changes will fail.
2424

2525
The following arguments are supported:
2626

27-
* `url` - (Required) The URL of the Git Repository to clone from. If the value changes, repo is re-created.
27+
* `url` - (Required) The URL of the Git Repository to clone from. If the value changes, Git folder is re-created.
2828
* `git_provider` - (Optional, if it's possible to detect Git provider by host name) case insensitive name of the Git provider. Following values are supported right now (could be a subject for a change, consult [Repos API documentation](https://docs.databricks.com/dev-tools/api/latest/repos.html)): `gitHub`, `gitHubEnterprise`, `bitbucketCloud`, `bitbucketServer`, `azureDevOpsServices`, `gitLab`, `gitLabEnterpriseEdition`, `awsCodeCommit`.
29-
* `path` - (Optional) path to put the checked out Repo. If not specified, then repo will be created in the user's repo directory (`/Repos/<username>/...`). If the value changes, repo is re-created.
29+
* `path` - (Optional) path to put the checked out Git folder. If not specified, , then the Git folder will be created in the default location. If the value changes, Git folder is re-created.
3030
* `branch` - (Optional) name of the branch for initial checkout. If not specified, the default branch of the repository will be used. Conflicts with `tag`. If `branch` is removed, and `tag` isn't specified, then the repository will stay at the previously checked out state.
3131
* `tag` - (Optional) name of the tag for initial checkout. Conflicts with `branch`.
3232

3333
### sparse_checkout
3434

35-
Optional `sparse_checkout` configuration block contains attributes related to [sparse checkout feature](https://docs.databricks.com/repos/git-operations-with-repos.html#configure-sparse-checkout-mode) in Databricks Repos. It supports following attributes:
35+
Optional `sparse_checkout` configuration block contains attributes related to [sparse checkout feature](https://docs.databricks.com/repos/git-operations-with-repos.html#configure-sparse-checkout-mode) in Databricks Git folders. It supports following attributes:
3636

3737
* `patterns` - array of paths (directories) that will be used for sparse checkout. List of patterns could be updated in-place.
3838

39-
Addition or removal of the `sparse_checkout` configuration block will lead to recreation of the repo.
39+
Addition or removal of the `sparse_checkout` configuration block will lead to recreation of the Git folder.
4040

4141

4242
## Attribute Reference
4343

4444
In addition to all arguments above, the following attributes are exported:
4545

46-
* `id` - Repo identifier
46+
* `id` - Git folder identifier
4747
* `commit_hash` - Hash of the HEAD commit at time of the last executed operation. It won't change if you manually perform pull operation via UI or API
4848
* `workspace_path` - path on Workspace File System (WSFS) in form of `/Workspace` + `path`
4949

@@ -53,7 +53,7 @@ In addition to all arguments above, the following attributes are exported:
5353

5454
## Import
5555

56-
The resource Repo can be imported using the Repo ID (obtained via UI or using API)
56+
The resource can be imported using the Git folder ID (obtained via UI or using API)
5757

5858
```bash
5959
$ terraform import databricks_repo.this repo_id

repos/resource_repo.go

Lines changed: 7 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -152,17 +152,13 @@ func GetGitProviderFromUrl(uri string) string {
152152

153153
func validatePath(i interface{}, k string) (_ []string, errors []error) {
154154
v := i.(string)
155-
if v != "" {
156-
if !strings.HasPrefix(v, "/Repos/") {
157-
errors = append(errors, fmt.Errorf("should start with /Repos/, got '%s'", v))
158-
return
159-
}
160-
v = strings.TrimSuffix(v, "/")
161-
parts := strings.Split(v, "/")
162-
if len(parts) != 4 { // we require 3 path parts + starting /
163-
errors = append(errors, fmt.Errorf("should have 3 components (/Repos/<directory>/<repo>), got %d", len(parts)-1))
164-
return
165-
}
155+
if v == "" || !strings.HasPrefix(v, "/Repos/") {
156+
return
157+
}
158+
v = strings.TrimSuffix(v, "/")
159+
parts := strings.Split(v, "/")
160+
if len(parts) != 4 { // we require 3 path parts + starting /
161+
errors = append(errors, fmt.Errorf("should have 3 components (/Repos/<directory>/<repo>), got %d", len(parts)-1))
166162
}
167163
return
168164
}

repos/resource_repo_test.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -203,10 +203,10 @@ func TestResourceRepoCreateCustomDirectoryWrongLocation(t *testing.T) {
203203
Resource: ResourceRepo(),
204204
State: map[string]any{
205205
"url": "https://github.com/user/test.git",
206-
"path": "/NotRepos/Production/test/",
206+
"path": "/Repos/Production/test/abc/",
207207
},
208208
Create: true,
209-
}.ExpectError(t, "invalid config supplied. [path] should start with /Repos/, got '/NotRepos/Production/test/'")
209+
}.ExpectError(t, "invalid config supplied. [path] should have 3 components (/Repos/<directory>/<repo>), got 4")
210210
}
211211

212212
func TestResourceRepoCreateCustomDirectoryWrongPath(t *testing.T) {

0 commit comments

Comments
 (0)