Skip to content

Commit

Permalink
Fix repository resource importability (ImportStatePassthrough require…
Browse files Browse the repository at this point in the history
…s ID only refresh capability)
  • Loading branch information
pdecat committed Oct 5, 2017
1 parent 7f298c6 commit c758202
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 2 deletions.
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
```

0 comments on commit c758202

Please sign in to comment.