forked from aeirola/terraform-provider-bitbucket
-
Notifications
You must be signed in to change notification settings - Fork 33
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Joachim Desroches
committed
Aug 13, 2024
1 parent
8de67e9
commit e6e10d2
Showing
4 changed files
with
127 additions
and
2 deletions.
There are no files selected for viewing
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
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,80 @@ | ||
package bitbucket | ||
|
||
import ( | ||
"context" | ||
"encoding/json" | ||
"fmt" | ||
"io" | ||
"log" | ||
"net/http" | ||
|
||
"github.com/DrFaust92/bitbucket-go-client" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataRepository() *schema.Resource { | ||
return &schema.Resource{ | ||
ReadWithoutTimeout: dataReadRepository, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"uuid": { | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
"slug": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
"workspace": { | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataReadRepository(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
c := m.(Clients).httpClient | ||
|
||
slug := d.Get("slug").(string) | ||
workspace := d.Get("workspace").(string) | ||
|
||
res, err := c.Get(fmt.Sprintf("2.0/repositories/%s/%s", | ||
workspace, | ||
slug)) | ||
|
||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if res.StatusCode == http.StatusNotFound { | ||
return diag.Errorf(("repository not found")) | ||
} | ||
|
||
if res.StatusCode == http.StatusInternalServerError { | ||
return diag.Errorf("internal server error fetching repository") | ||
} | ||
|
||
var repository bitbucket.Repository | ||
body, readerr := io.ReadAll(res.Body) | ||
|
||
if readerr != nil { | ||
return diag.FromErr(readerr) | ||
} | ||
|
||
log.Printf("[DEBUG] Deployment response raw: %s", string(body)) | ||
|
||
decodeerr := json.Unmarshal(body, &repository) | ||
if decodeerr != nil { | ||
return diag.FromErr(decodeerr) | ||
} | ||
|
||
log.Printf("[DEBUG] Deployment response: %#v", repository) | ||
|
||
d.SetId(fmt.Sprintf("%s/%s", workspace, slug)) | ||
d.Set("workspace", workspace) | ||
d.Set("slug", slug) | ||
|
||
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
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,44 @@ | ||
--- | ||
layout: bitbucket | ||
page_title: "Bitbucket: bitbucket_repository" | ||
sidebar_current: "docs-bitbucket-data-repository" | ||
description: |- | ||
Provides a data source for a Bitbucket repository | ||
--- | ||
|
||
# bitbucket\_repository | ||
|
||
Provide a way to fetch data about a repository. | ||
|
||
OAuth2 Scopes: `repository` | ||
|
||
## Example Usage | ||
|
||
```hcl | ||
data "bitbucket_repository" "my_repo" { | ||
workspace = "myworspace" | ||
slug = "my-repo-slug" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `workspace` - (Required) This can either be the workspace ID (slug) or the workspace UUID surrounded by curly-braces | ||
* `slug`: - (Required) This can either be the repository slug or the UUID of the repository, surrounded by curly-braces | ||
|
||
## Attribute Reference | ||
|
||
* `owner` - The owner of this repository. | ||
* `name` - The name of the repository. | ||
* `slug` - The slug of the repository. | ||
* `scm` - The SCM (`git` or `hg`) of the repository. | ||
* `is_private` - If this repository is private or not. | ||
* `website` - URL of website associated with this repository. | ||
* `language` - The programming language of this repository. | ||
* `has_issues` - If this repository has issues turned on. | ||
* `has_wiki` - If this repository has wiki turned on. | ||
* `project_key` - The key of a project the repository is linked to, if applicable. | ||
* `fork_policy` - The repository fork policy. Valid values are | ||
`allow_forks`. Valid values are `allow_forks`, `no_public_forks`, `no_forks`. | ||
* `description` - The description of the repo. | ||
* `pipelines_enabled` - If this repository has pipelines turned on. |