-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #121 from bigcommerce/data-source-teams
Add firehydrant_teams and firehydrant_team data source
- Loading branch information
Showing
15 changed files
with
778 additions
and
78 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,35 @@ | ||
--- | ||
page_title: "FireHydrant Data Source: firehydrant_team" | ||
subcategory: "" | ||
--- | ||
|
||
# firehydrant_team Data Source | ||
|
||
Use this data source to get information on a team matching the given criteria. | ||
|
||
## Example Usage | ||
|
||
Basic usage: | ||
|
||
```hcl | ||
data "firehydrant_team" "test-team" { | ||
id = "157a83c4-17d1-4362-a4e8-a45412d19af2" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `id` - (Required) The ID of the team to retrieve. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `id` - The ID of the team. | ||
* `name` - The name of the team. | ||
* `description` - A description of the team. | ||
* `slug` - The slug for the team. | ||
* `service_ids` - A set of IDs of the services associated with this team | ||
* `owned_service_ids` - A set of IDs of the services owned by this team |
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 @@ | ||
--- | ||
page_title: "FireHydrant Data Source: firehydrant_teams" | ||
subcategory: "" | ||
--- | ||
|
||
# firehydrant_teams Data Source | ||
|
||
Use this data source to get information on all teams matching the given criteria. | ||
|
||
## Example Usage | ||
|
||
Basic usage: | ||
```hcl | ||
data "firehydrant_teams" "all-teams" { | ||
} | ||
``` | ||
|
||
Getting all teams with `database` in the name: | ||
```hcl | ||
data "firehydrant_teams" "database-named-teams" { | ||
query = "database" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
The following arguments are supported: | ||
|
||
* `query` - (Optional) A query to search for teams by their name. | ||
|
||
## Attributes Reference | ||
|
||
In addition to all arguments above, the following attributes are exported: | ||
|
||
* `teams` - All the teams matching the criteria specified by `query`. | ||
|
||
The `teams` block contains: | ||
|
||
* `id` - The ID of the team. | ||
* `name` - The name of the team. | ||
* `description` - A description of the team. | ||
* `slug` - The slug for the team. | ||
* `service_ids` - A set of IDs of the services associated with this team | ||
* `owned_service_ids` - A set of IDs of the services owned by this team |
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 |
---|---|---|
@@ -1,3 +1,14 @@ | ||
resource "firehydrant_team" "firefighters" { | ||
name = "Firefighters" | ||
} | ||
|
||
data "firehydrant_team" "firefighters" { | ||
id = "857a83c4-17d1-4362-a4e8-42d1a3d19ed1" | ||
} | ||
|
||
data "firehydrant_teams" "all_teams" { | ||
} | ||
|
||
data "firehydrant_teams" "test_teams" { | ||
query = "Test" | ||
} |
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,121 @@ | ||
package firehydrant | ||
|
||
import ( | ||
"context" | ||
"github.com/dghubble/sling" | ||
"github.com/pkg/errors" | ||
) | ||
|
||
// TeamsClient is an interface for interacting with teams on FireHydrant | ||
type TeamsClient interface { | ||
Get(ctx context.Context, slug string) (*TeamResponse, error) | ||
List(ctx context.Context, req *TeamQuery) (*TeamsResponse, error) | ||
Create(ctx context.Context, createReq CreateTeamRequest) (*TeamResponse, error) | ||
Update(ctx context.Context, slug string, updateReq UpdateTeamRequest) (*TeamResponse, error) | ||
Archive(ctx context.Context, slug string) error | ||
} | ||
|
||
// RESTTeamsClient implements the TeamsClient interface | ||
type RESTTeamsClient struct { | ||
client *APIClient | ||
} | ||
|
||
var _ TeamsClient = &RESTTeamsClient{} | ||
|
||
func (c *RESTTeamsClient) restClient() *sling.Sling { | ||
return c.client.client() | ||
} | ||
|
||
// Get retrieves a team from FireHydrant | ||
func (c *RESTTeamsClient) Get(ctx context.Context, id string) (*TeamResponse, error) { | ||
teamResponse := &TeamResponse{} | ||
apiError := &APIError{} | ||
response, err := c.restClient().Get("teams/"+id).Receive(teamResponse, apiError) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not get team") | ||
} | ||
|
||
err = checkResponseStatusCode(response, apiError) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return teamResponse, nil | ||
} | ||
|
||
// List retrieves a list of teams based on a team query | ||
func (c *RESTTeamsClient) List(ctx context.Context, req *TeamQuery) (*TeamsResponse, error) { | ||
teamsResponse := &TeamsResponse{} | ||
apiError := &APIError{} | ||
curPage := 1 | ||
|
||
for { | ||
req.Page = curPage | ||
response, err := c.restClient().Get("teams").QueryStruct(req).Receive(teamsResponse, apiError) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not get teams") | ||
} | ||
|
||
err = checkResponseStatusCode(response, apiError) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
if teamsResponse.Pagination == nil || teamsResponse.Pagination.Last == curPage { | ||
break | ||
} | ||
curPage += 1 | ||
} | ||
|
||
return teamsResponse, nil | ||
} | ||
|
||
// Create creates a team | ||
func (c *RESTTeamsClient) Create(ctx context.Context, createReq CreateTeamRequest) (*TeamResponse, error) { | ||
teamResponse := &TeamResponse{} | ||
apiError := &APIError{} | ||
response, err := c.restClient().Post("teams").BodyJSON(&createReq).Receive(teamResponse, apiError) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not create team") | ||
} | ||
|
||
err = checkResponseStatusCode(response, apiError) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return teamResponse, nil | ||
} | ||
|
||
// Update updates a team in FireHydrant | ||
func (c *RESTTeamsClient) Update(ctx context.Context, slug string, updateReq UpdateTeamRequest) (*TeamResponse, error) { | ||
teamResponse := &TeamResponse{} | ||
apiError := &APIError{} | ||
response, err := c.restClient().Patch("teams/"+slug).BodyJSON(&updateReq).Receive(teamResponse, apiError) | ||
if err != nil { | ||
return nil, errors.Wrap(err, "could not update team") | ||
} | ||
|
||
err = checkResponseStatusCode(response, apiError) | ||
if err != nil { | ||
return nil, err | ||
} | ||
|
||
return teamResponse, nil | ||
} | ||
|
||
// Archive archives a team in FireHydrant | ||
func (c *RESTTeamsClient) Archive(ctx context.Context, slug string) error { | ||
apiError := &APIError{} | ||
response, err := c.restClient().Delete("teams/"+slug).Receive(nil, apiError) | ||
if err != nil { | ||
return errors.Wrap(err, "could not archive team") | ||
} | ||
|
||
err = checkResponseStatusCode(response, apiError) | ||
if err != nil { | ||
return err | ||
} | ||
|
||
return nil | ||
} |
Oops, something went wrong.