Skip to content
This repository was archived by the owner on Jul 22, 2025. It is now read-only.
Open
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
24 changes: 12 additions & 12 deletions docs/data-sources/teams.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,12 @@
page_title: "octopusdeploy_teams Data Source - terraform-provider-octopusdeploy"
subcategory: ""
description: |-
Provides information about existing users.
Provides information about existing teams.
---

# octopusdeploy_teams (Data Source)

Provides information about existing users.
Provides information about existing teams.



Expand All @@ -27,7 +27,7 @@ Provides information about existing users.
### Read-Only

- `id` (String) An auto-generated identifier that includes the timestamp when this data source was last modified.
- `teams` (List of Object) A list of teams that match the filter(s). (see [below for nested schema](#nestedatt--teams))
- `teams` (Attributes List) A list of teams that match the filter(s). (see [below for nested schema](#nestedatt--teams))

<a id="nestedatt--teams"></a>
### Nested Schema for `teams`
Expand All @@ -38,20 +38,20 @@ Read-Only:
- `can_be_renamed` (Boolean)
- `can_change_members` (Boolean)
- `can_change_roles` (Boolean)
- `description` (String)
- `external_security_group` (List of Object) (see [below for nested schema](#nestedobjatt--teams--external_security_group))
- `id` (String)
- `name` (String)
- `space_id` (String)
- `users` (Set of String)

<a id="nestedobjatt--teams--external_security_group"></a>
- `description` (String) The user-friendly description of this team.
- `external_security_group` (Attributes List) (see [below for nested schema](#nestedatt--teams--external_security_group))
- `id` (String) The unique ID for this resource.
- `name` (String) The name of this team.
- `space_id` (String) The space associated with this team.
- `users` (Set of String) A list of user IDs designated to be members of this team.

<a id="nestedatt--teams--external_security_group"></a>
### Nested Schema for `teams.external_security_group`

Read-Only:

- `display_id_and_name` (Boolean)
- `display_name` (String)
- `id` (String)
- `id` (String) The unique ID for this resource.


46 changes: 0 additions & 46 deletions octopusdeploy/data_source_teams.go

This file was deleted.

1 change: 0 additions & 1 deletion octopusdeploy/provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@ func Provider() *schema.Provider {
"octopusdeploy_offline_package_drop_deployment_targets": dataSourceOfflinePackageDropDeploymentTargets(),
"octopusdeploy_polling_tentacle_deployment_targets": dataSourcePollingTentacleDeploymentTargets(),
"octopusdeploy_ssh_connection_deployment_targets": dataSourceSSHConnectionDeploymentTargets(),
"octopusdeploy_teams": dataSourceTeams(),
"octopusdeploy_user_roles": dataSourceUserRoles(),
"octopusdeploy_worker_pools": dataSourceWorkerPools(),
},
Expand Down
87 changes: 87 additions & 0 deletions octopusdeploy_framework/data_source_teams.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
package octopusdeploy_framework

import (
"context"
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/teams"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"time"
)

type teamDataSource struct {
*Config
}

type teamsDataSourceModel struct {
ID types.String `tfsdk:"id"`
IDs types.List `tfsdk:"ids"`
IncludeSystem types.Bool `tfsdk:"include_system"`
PartialName types.String `tfsdk:"partial_name"`
Spaces types.List `tfsdk:"spaces"`
Skip types.Int64 `tfsdk:"skip"`
Take types.Int64 `tfsdk:"take"`
Teams []schemas.TeamTypeDatasourceModel `tfsdk:"teams"`
}

var _ datasource.DataSource = &teamDataSource{}

func NewTeamsDataSource() datasource.DataSource {
return &teamDataSource{}
}

func (t *teamDataSource) Metadata(ctx context.Context, req datasource.MetadataRequest, resp *datasource.MetadataResponse) {
resp.TypeName = util.GetTypeName("teams")
}

func (t *teamDataSource) Schema(ctx context.Context, req datasource.SchemaRequest, resp *datasource.SchemaResponse) {
resp.Schema = schemas.TeamSchema{}.GetDatasourceSchema()
}

func (t *teamDataSource) Configure(_ context.Context, req datasource.ConfigureRequest, resp *datasource.ConfigureResponse) {
t.Config = DataSourceConfiguration(req, resp)
}

func (t *teamDataSource) Read(ctx context.Context, req datasource.ReadRequest, resp *datasource.ReadResponse) {
var err error
var data teamsDataSourceModel
resp.Diagnostics.Append(req.Config.Get(ctx, &data)...)
if resp.Diagnostics.HasError() {
return
}

query := teams.TeamsQuery{
IDs: util.GetIds(data.IDs),
IncludeSystem: data.IncludeSystem.ValueBool(),
PartialName: data.PartialName.ValueString(),
Spaces: util.ExpandStringList(data.Spaces),
Skip: util.GetNumber(data.Skip),
Take: util.GetNumber(data.Take),
}

util.DatasourceReading(ctx, "teams", query)

existingTeams, err := t.Client.Teams.Get(query)

if err != nil {
diag.FromErr(err)
return
}

tflog.Debug(ctx, fmt.Sprintf("users returned from API: %#v", existingTeams))

data.Teams = make([]schemas.TeamTypeDatasourceModel, 0, len(existingTeams.Items))
for _, team := range existingTeams.Items {
data.Teams = append(data.Teams, schemas.MapToTeamsDatasourceModel(team))
}

util.DatasourceResultCount(ctx, "teams", len(data.Teams))

data.ID = types.StringValue("Teams " + time.Now().UTC().String())

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
1 change: 1 addition & 0 deletions octopusdeploy_framework/framework_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ func (p *octopusDeployFrameworkProvider) DataSources(ctx context.Context) []func
NewServiceAccountOIDCIdentityDataSource,
NewWorkersDataSource,
NewDeploymentFreezeDataSource,
NewTeamsDataSource,
}
}

Expand Down
133 changes: 133 additions & 0 deletions octopusdeploy_framework/schemas/team.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,133 @@
package schemas

import (
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/teams"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
)

var _ EntitySchema = TeamSchema{}

type TeamSchema struct{}

func (l TeamSchema) GetResourceSchema() resourceSchema.Schema {
return resourceSchema.Schema{
Description: "This resource manages teams in Octopus Deploy.",
Attributes: map[string]resourceSchema.Attribute{},
Blocks: map[string]resourceSchema.Block{},
}
}

func (l TeamSchema) GetDatasourceSchema() datasourceSchema.Schema {
return datasourceSchema.Schema{
Description: "Provides information about existing teams.",
Attributes: map[string]datasourceSchema.Attribute{
"id": util.DataSourceString().Computed().Description("An auto-generated identifier that includes the timestamp when this data source was last modified.").Build(),
"ids": util.DataSourceList(types.StringType).Optional().Description("A filter to search by a list of IDs.").Build(),
"include_system": util.DataSourceBool().Optional().Description("A filter to include system teams.").Build(),
"partial_name": util.DataSourceString().Optional().Description("A filter to search by the partial match of a name.").Build(),
"spaces": util.DataSourceList(types.StringType).Optional().Description("A filter to search by a list of space IDs.").Build(),
"skip": util.DataSourceInt64().Optional().Description("A filter to specify the number of items to skip in the response.").Build(),
"take": util.DataSourceInt64().Optional().Description("A filter to specify the number of items to take (or return) in the response.").Build(),
"teams": getDatasourceTeamsAttributes(),
},
}
}

func getDatasourceTeamsAttributes() datasourceSchema.ListNestedAttribute {
return datasourceSchema.ListNestedAttribute{
Computed: true,
Description: "A list of teams that match the filter(s).",
Optional: false,
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: map[string]datasourceSchema.Attribute{
"can_be_deleted": util.DataSourceBool().Computed().Build(),
"can_be_renamed": util.DataSourceBool().Computed().Build(),
"can_change_members": util.DataSourceBool().Computed().Build(),
"can_change_roles": util.DataSourceBool().Computed().Build(),
"description": util.DataSourceString().Computed().Description("The user-friendly description of this team.").Build(),
"external_security_group": getDatasourceExternalSecurityGroupsAttributes(),
"id": util.DataSourceString().Computed().Description("The unique ID for this resource.").Build(),
"name": util.DataSourceString().Computed().Description("The name of this team.").Build(),
"space_id": util.DataSourceString().Computed().Description("The space associated with this team.").Build(),
"users": util.DataSourceSet(types.StringType).Computed().Description("A list of user IDs designated to be members of this team.").Build(),
},
},
}
}

func getDatasourceExternalSecurityGroupsAttributes() datasourceSchema.ListNestedAttribute {
return datasourceSchema.ListNestedAttribute{
Computed: true,
NestedObject: datasourceSchema.NestedAttributeObject{
Attributes: map[string]datasourceSchema.Attribute{
"display_id_and_name": util.DataSourceBool().Computed().Build(),
"display_name": util.DataSourceString().Computed().Build(),
"id": util.DataSourceString().Computed().Description("The unique ID for this resource.").Build(),
},
},
}
}

func MapToTeamsDatasourceModel(t *teams.Team) TeamTypeDatasourceModel {
var team TeamTypeDatasourceModel
team.CanBeDeleted = types.BoolValue(t.CanBeDeleted)
team.CanBeRenamed = types.BoolValue(t.CanBeRenamed)
team.CanChangeMembers = types.BoolValue(t.CanChangeMembers)
team.CanChangeRoles = types.BoolValue(t.CanChangeRoles)
team.Description = types.StringValue(t.Description)
team.ExternalSecurityGroups = MapToExternalSecurityGroupsDatasourceModel(t.ExternalSecurityGroups)
team.Name = types.StringValue(t.Name)
team.SpaceId = types.StringValue(t.SpaceID)
team.Users = basetypes.SetValue(util.FlattenStringList(t.MemberUserIDs))

team.ID = types.StringValue(t.ID)
return team
}

func MapToExternalSecurityGroupsDatasourceModel(es []core.NamedReferenceItem) types.List {
groups := make([]attr.Value, 0, len(es))
for _, g := range es {
group := map[string]attr.Value{
"display_id_and_name": types.BoolValue(g.DisplayIDAndName),
"display_name": types.StringValue(g.DisplayName),
"id": types.StringValue(g.ID),
}
groups = append(groups, types.ObjectValueMust(getExternalSecurityGroupsAttrTypes(), group))
}

return types.ListValueMust(types.ObjectType{AttrTypes: getExternalSecurityGroupsAttrTypes()}, groups)
}

func getExternalSecurityGroupsAttrTypes() map[string]attr.Type {
return map[string]attr.Type{
"display_id_and_name": types.BoolType,
"display_name": types.StringType,
"id": types.StringType,
}
}

type TeamTypeDatasourceModel struct {
CanBeDeleted types.Bool `tfsdk:"can_be_deleted"`
CanBeRenamed types.Bool `tfsdk:"can_be_renamed"`
CanChangeMembers types.Bool `tfsdk:"can_change_members"`
CanChangeRoles types.Bool `tfsdk:"can_change_roles"`
Description types.String `tfsdk:"description"`
ExternalSecurityGroups types.List `tfsdk:"external_security_group"`
Name types.String `tfsdk:"name"`
SpaceId types.String `tfsdk:"space_id"`
Users types.Set `tfsdk:"users"`
ResourceModel
}

type TeamExternalSecurityGroupTypeDatasourceModel struct {
DisplayIdAndName types.Bool `tfsdk:"display_id_and_name"`
DisplayName types.String `tfsdk:"display_name"`

ResourceModel
}
Loading