-
Notifications
You must be signed in to change notification settings - Fork 67
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Implemented #125
- Loading branch information
Showing
8 changed files
with
517 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,78 @@ | ||
--- | ||
page_title: "octopusdeploy_teams Data Source - terraform-provider-octopusdeploy" | ||
subcategory: "" | ||
description: |- | ||
Provides information about existing users. | ||
--- | ||
|
||
# Data Source `octopusdeploy_teams` | ||
|
||
Provides information about existing users. | ||
|
||
|
||
|
||
## Schema | ||
|
||
### Optional | ||
|
||
- **ids** (List of String, Optional) A filter to search by a list of IDs. | ||
- **include_system** (Boolean, Optional) A filter to include system teams. | ||
- **partial_name** (String, Optional) A filter to search by the partial match of a name. | ||
- **skip** (Number, Optional) A filter to specify the number of items to skip in the response. | ||
- **take** (Number, Optional) A filter to specify the number of items to take (or return) in the response. | ||
|
||
### Read-only | ||
|
||
- **id** (String, Read-only) A auto-generated identifier that includes the timestamp when this data source was last modified. | ||
- **spaces** (Block List) A list of spaces that match the filter(s). (see [below for nested schema](#nestedblock--spaces)) | ||
- **teams** (Block List) A list of teams that match the filter(s). (see [below for nested schema](#nestedblock--teams)) | ||
|
||
<a id="nestedblock--spaces"></a> | ||
### Nested Schema for `spaces` | ||
|
||
Read-only: | ||
|
||
- **can_be_deleted** (Boolean, Read-only) | ||
- **can_be_renamed** (Boolean, Read-only) | ||
- **can_change_members** (Boolean, Read-only) | ||
- **can_change_roles** (Boolean, Read-only) | ||
- **description** (String, Read-only) | ||
- **external_security_groups** (List of Object, Read-only) (see [below for nested schema](#nestedatt--spaces--external_security_groups)) | ||
- **id** (String, Read-only) The unique ID for this resource. | ||
- **name** (String, Read-only) | ||
- **space_id** (String, Read-only) | ||
- **users** (List of String, Read-only) A list of user IDs designated to be members of this team. | ||
|
||
<a id="nestedatt--spaces--external_security_groups"></a> | ||
### Nested Schema for `spaces.external_security_groups` | ||
|
||
- **display_id_and_name** (Boolean) | ||
- **display_name** (String) | ||
- **id** (String) | ||
|
||
|
||
|
||
<a id="nestedblock--teams"></a> | ||
### Nested Schema for `teams` | ||
|
||
Read-only: | ||
|
||
- **can_be_deleted** (Boolean, Read-only) | ||
- **can_be_renamed** (Boolean, Read-only) | ||
- **can_change_members** (Boolean, Read-only) | ||
- **can_change_roles** (Boolean, Read-only) | ||
- **description** (String, Read-only) | ||
- **external_security_groups** (List of Object, Read-only) (see [below for nested schema](#nestedatt--teams--external_security_groups)) | ||
- **id** (String, Read-only) The unique ID for this resource. | ||
- **name** (String, Read-only) | ||
- **space_id** (String, Read-only) | ||
- **users** (List of String, Read-only) A list of user IDs designated to be members of this team. | ||
|
||
<a id="nestedatt--teams--external_security_groups"></a> | ||
### Nested Schema for `teams.external_security_groups` | ||
|
||
- **display_id_and_name** (Boolean) | ||
- **display_name** (String) | ||
- **id** (String) | ||
|
||
|
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: "octopusdeploy_team Resource - terraform-provider-octopusdeploy" | ||
subcategory: "" | ||
description: |- | ||
This resource manages teams in Octopus Deploy. | ||
--- | ||
|
||
# Resource `octopusdeploy_team` | ||
|
||
This resource manages teams in Octopus Deploy. | ||
|
||
|
||
|
||
## Schema | ||
|
||
### Required | ||
|
||
- **name** (String, Required) | ||
|
||
### Optional | ||
|
||
- **can_be_deleted** (Boolean, Optional) | ||
- **can_be_renamed** (Boolean, Optional) | ||
- **can_change_members** (Boolean, Optional) | ||
- **can_change_roles** (Boolean, Optional) | ||
- **description** (String, Optional) | ||
- **external_security_groups** (Block List) (see [below for nested schema](#nestedblock--external_security_groups)) | ||
- **id** (String, Optional) The unique ID for this resource. | ||
- **users** (List of String, Optional) A list of user IDs designated to be members of this team. | ||
|
||
### Read-only | ||
|
||
- **space_id** (String, Read-only) | ||
|
||
<a id="nestedblock--external_security_groups"></a> | ||
### Nested Schema for `external_security_groups` | ||
|
||
Optional: | ||
|
||
- **display_id_and_name** (Boolean, Optional) | ||
- **display_name** (String, Optional) | ||
- **id** (String, Optional) The unique ID for this resource. | ||
|
||
|
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 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"context" | ||
"time" | ||
|
||
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func dataSourceTeams() *schema.Resource { | ||
return &schema.Resource{ | ||
Description: "Provides information about existing users.", | ||
ReadContext: dataSourceTeamsRead, | ||
Schema: getTeamDataSchema(), | ||
} | ||
} | ||
|
||
func dataSourceTeamsRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { | ||
query := octopusdeploy.TeamsQuery{ | ||
IDs: expandArray(d.Get("ids").([]interface{})), | ||
IncludeSystem: d.Get("include_system").(bool), | ||
PartialName: d.Get("partial_name").(string), | ||
Skip: d.Get("skip").(int), | ||
Take: d.Get("take").(int), | ||
} | ||
|
||
client := meta.(*octopusdeploy.Client) | ||
users, err := client.Teams.Get(query) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
flattenedTeams := []interface{}{} | ||
for _, user := range users.Items { | ||
flattenedTeams = append(flattenedTeams, flattenTeam(user)) | ||
} | ||
|
||
d.Set("teams", flattenedTeams) | ||
d.SetId("Teams " + time.Now().UTC().String()) | ||
|
||
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,98 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"context" | ||
"log" | ||
|
||
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/diag" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func resourceTeam() *schema.Resource { | ||
return &schema.Resource{ | ||
CreateContext: resourceTeamCreate, | ||
DeleteContext: resourceTeamDelete, | ||
Description: "This resource manages teams in Octopus Deploy.", | ||
Importer: getImporter(), | ||
ReadContext: resourceTeamRead, | ||
Schema: getTeamSchema(), | ||
UpdateContext: resourceTeamUpdate, | ||
} | ||
} | ||
|
||
func resourceTeamCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
team := expandTeam(d) | ||
|
||
log.Printf("[INFO] creating team: %#v", team) | ||
|
||
client := m.(*octopusdeploy.Client) | ||
createdTeam, err := client.Teams.Add(team) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := setTeam(ctx, d, createdTeam); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId(createdTeam.GetID()) | ||
|
||
log.Printf("[INFO] team created (%s)", d.Id()) | ||
return nil | ||
} | ||
|
||
func resourceTeamDelete(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
log.Printf("[INFO] deleting team (%s)", d.Id()) | ||
|
||
client := m.(*octopusdeploy.Client) | ||
if err := client.Teams.DeleteByID(d.Id()); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
d.SetId("") | ||
|
||
log.Printf("[INFO] team deleted") | ||
return nil | ||
} | ||
|
||
func resourceTeamRead(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
log.Printf("[INFO] reading team (%s)", d.Id()) | ||
|
||
client := m.(*octopusdeploy.Client) | ||
team, err := client.Teams.GetByID(d.Id()) | ||
if err != nil { | ||
apiError := err.(*octopusdeploy.APIError) | ||
if apiError.StatusCode == 404 { | ||
log.Printf("[INFO] team (%s) not found; deleting from state", d.Id()) | ||
d.SetId("") | ||
return nil | ||
} | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := setTeam(ctx, d, team); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
log.Printf("[INFO] team read (%s)", d.Id()) | ||
return nil | ||
} | ||
|
||
func resourceTeamUpdate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { | ||
log.Printf("[INFO] updating team (%s)", d.Id()) | ||
|
||
team := expandTeam(d) | ||
client := m.(*octopusdeploy.Client) | ||
updatedTeam, err := client.Teams.Update(team) | ||
if err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
if err := setTeam(ctx, d, updatedTeam); err != nil { | ||
return diag.FromErr(err) | ||
} | ||
|
||
log.Printf("[INFO] team updated (%s)", d.Id()) | ||
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,73 @@ | ||
package octopusdeploy | ||
|
||
import ( | ||
"github.com/OctopusDeploy/go-octopusdeploy/octopusdeploy" | ||
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" | ||
) | ||
|
||
func expandExternalSecurityGroups(externalSecurityGroups []interface{}) []octopusdeploy.NamedReferenceItem { | ||
expandedExternalSecurityGroups := make([]octopusdeploy.NamedReferenceItem, 0, len(externalSecurityGroups)) | ||
for _, externalSecurityGroup := range externalSecurityGroups { | ||
if externalSecurityGroup != nil { | ||
rawExternalSecurityGroup := externalSecurityGroup.(map[string]interface{}) | ||
|
||
displayIDAndName := false | ||
if rawExternalSecurityGroup["display_id_and_name"] != nil { | ||
displayIDAndName = rawExternalSecurityGroup["display_id_and_name"].(bool) | ||
} | ||
|
||
displayName := "" | ||
if rawExternalSecurityGroup["display_name"] != nil { | ||
displayName = rawExternalSecurityGroup["display_name"].(string) | ||
} | ||
|
||
id := "" | ||
if rawExternalSecurityGroup["id"] != nil { | ||
id = rawExternalSecurityGroup["id"].(string) | ||
} | ||
|
||
item := octopusdeploy.NamedReferenceItem{ | ||
DisplayIDAndName: displayIDAndName, | ||
DisplayName: displayName, | ||
ID: id, | ||
} | ||
expandedExternalSecurityGroups = append(expandedExternalSecurityGroups, item) | ||
} | ||
} | ||
return expandedExternalSecurityGroups | ||
} | ||
|
||
func flattenExternalSecurityGroups(externalSecurityGroups []octopusdeploy.NamedReferenceItem) []interface{} { | ||
if externalSecurityGroups == nil { | ||
return nil | ||
} | ||
|
||
flattenedExternalSecurityGroups := make([]interface{}, len(externalSecurityGroups)) | ||
for i, externalSecurityGroup := range externalSecurityGroups { | ||
rawExternalSecurityGroup := map[string]interface{}{ | ||
"display_id_and_name": externalSecurityGroup.DisplayIDAndName, | ||
"display_name": externalSecurityGroup.DisplayName, | ||
"id": externalSecurityGroup.ID, | ||
} | ||
|
||
flattenedExternalSecurityGroups[i] = rawExternalSecurityGroup | ||
} | ||
|
||
return flattenedExternalSecurityGroups | ||
} | ||
|
||
func getExternalSecurityGroupsSchema() map[string]*schema.Schema { | ||
return map[string]*schema.Schema{ | ||
"display_id_and_name": { | ||
Computed: true, | ||
Optional: true, | ||
Type: schema.TypeBool, | ||
}, | ||
"display_name": { | ||
Computed: true, | ||
Optional: true, | ||
Type: schema.TypeString, | ||
}, | ||
"id": getIDSchema(), | ||
} | ||
} |
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
Oops, something went wrong.