Skip to content
This repository has been archived by the owner on Dec 8, 2020. It is now read-only.

Fix repository resource importability #7

Merged
merged 1 commit into from
Nov 7, 2017
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
11 changes: 11 additions & 0 deletions bitbucket/resource_repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"io/ioutil"

"github.com/hashicorp/terraform/helper/schema"
"strings"
)

type CloneUrl struct {
Expand Down Expand Up @@ -186,6 +187,16 @@ func resourceRepositoryCreate(d *schema.ResourceData, m interface{}) error {
return resourceRepositoryRead(d, m)
}
func resourceRepositoryRead(d *schema.ResourceData, m interface{}) error {
id := d.Id()
if id != "" {
idparts := strings.Split(id, "/")
if len(idparts) == 2 {
d.Set("owner", idparts[0])
d.Set("slug", idparts[1])
} else {
return fmt.Errorf("Incorrect ID format, should match `owner/slug`")
}
}

var repoSlug string
repoSlug = d.Get("slug").(string)
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/repository.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,8 +63,8 @@ The following arguments are computed. You can access both `clone_ssh` and

## Import

Repositories can be imported using the `name`, e.g.
Repositories can be imported using their `owner/name` ID, e.g.

```
$ terraform import bitbucket_repository.my-repo my-repo
$ terraform import bitbucket_repository.my-repo my-account/my-repo
```