Skip to content

Commit

Permalink
added debug logging to datasources
Browse files Browse the repository at this point in the history
  • Loading branch information
benPearce1 committed Aug 21, 2024
1 parent 13881dc commit 638a650
Show file tree
Hide file tree
Showing 11 changed files with 54 additions and 2 deletions.
5 changes: 5 additions & 0 deletions octopusdeploy_framework/data_source_library_variable_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -66,12 +66,16 @@ func (l *libraryVariableSetDataSource) Read(ctx context.Context, req datasource.
Take: int(data.Take.ValueInt64()),
}

tflog.Debug(ctx, fmt.Sprintf("Reading library variable set with query: %+v", query))

existingLibraryVariableSets, err := libraryvariablesets.Get(l.Config.Client, data.SpaceID.ValueString(), query)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read library variable sets, got error: %s", err))
return
}

tflog.Debug(ctx, fmt.Sprintf("Read library variable set returned %d items", len(existingLibraryVariableSets.Items)))

data.LibraryVariableSets = flattenLibraryVariableSets(existingLibraryVariableSets.Items)

data.ID = types.StringValue("Library Variables Sets " + time.Now().UTC().String())
Expand All @@ -94,5 +98,6 @@ func flattenLibraryVariableSets(items []*variables.LibraryVariableSet) types.Lis
}
libraryVariableSetList = append(libraryVariableSetList, types.ObjectValueMust(schemas.GetLibraryVariableSetObjectType(), libraryVariableSetMap))
}

return types.ListValueMust(types.ObjectType{AttrTypes: schemas.GetLibraryVariableSetObjectType()}, libraryVariableSetList)
}
3 changes: 3 additions & 0 deletions octopusdeploy_framework/data_source_script_modules.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,8 @@ func (l *scriptModulesDataSource) Read(ctx context.Context, req datasource.ReadR
Take: int(data.Take.ValueInt64()),
}

tflog.Debug(ctx, fmt.Sprintf("Reading script modules data source query: %+v", query))

spaceID := data.SpaceID.ValueString()
existingScriptModules, err := scriptmodules.Get(l.Config.Client, spaceID, query)
if err != nil {
Expand All @@ -70,5 +72,6 @@ func (l *scriptModulesDataSource) Read(ctx context.Context, req datasource.ReadR
flattenedScriptModules)
data.ID = types.StringValue("Script Modules " + time.Now().UTC().String())

tflog.Debug(ctx, fmt.Sprintf("Read script modules data source returned %d items", len(existingScriptModules.Items)))
resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
}
4 changes: 4 additions & 0 deletions octopusdeploy_framework/datasource_environments.go
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,8 @@ func (e *environmentDataSource) Read(ctx context.Context, req datasource.ReadReq
Take: util.GetNumber(data.Take),
}

tflog.Debug(ctx, fmt.Sprintf("Reading environments with query %+v", query))

existingEnvironments, err := environments.Get(e.Client, data.SpaceID.ValueString(), query)
if err != nil {
resp.Diagnostics.AddError("unable to load environments", err.Error())
Expand All @@ -109,6 +111,8 @@ func (e *environmentDataSource) Read(ctx context.Context, req datasource.ReadReq
}
}

tflog.Debug(ctx, fmt.Sprintf("Reading environments data source returned %d items", len(mappedEnvironments)))

data.Environments, _ = types.ListValueFrom(ctx, types.ObjectType{AttrTypes: schemas.EnvironmentObjectType()}, mappedEnvironments)
data.ID = types.StringValue("Environments " + time.Now().UTC().String())

Expand Down
4 changes: 3 additions & 1 deletion octopusdeploy_framework/datasource_feeds.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,12 +60,14 @@ func (e *feedsDataSource) Read(ctx context.Context, req datasource.ReadRequest,
Take: util.GetNumber(data.Take),
}

tflog.Debug(ctx, fmt.Sprintf("Reading feeds with query %+v", query))

existingFeeds, err := feeds.Get(e.Client, data.SpaceID.ValueString(), query)
if err != nil {
resp.Diagnostics.AddError("unable to load feeds", err.Error())
return
}
tflog.Debug(ctx, fmt.Sprintf("environments returned from API: %#v", existingFeeds))
tflog.Debug(ctx, fmt.Sprintf("Reading feeds returned %d items", len(existingFeeds.Items)))

flattenedFeeds := []interface{}{}
for _, feed := range existingFeeds.Items {
Expand Down
6 changes: 6 additions & 0 deletions octopusdeploy_framework/datasource_git_credentials.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"time"
)

Expand Down Expand Up @@ -64,6 +65,9 @@ func (g *gitCredentialsDataSource) Read(ctx context.Context, req datasource.Read
Skip: int(data.Skip.ValueInt64()),
Take: int(data.Take.ValueInt64()),
}

tflog.Debug(ctx, fmt.Sprintf("Reading git credentials with query %+v", query))

spaceID := data.SpaceID.ValueString()

existingGitCredentials, err := credentials.Get(g.Client, spaceID, query)
Expand All @@ -72,6 +76,8 @@ func (g *gitCredentialsDataSource) Read(ctx context.Context, req datasource.Read
return
}

tflog.Debug(ctx, fmt.Sprintf("Reading git credentials returned %d items", len(existingGitCredentials.Items)))

flattenedGitCredentials := make([]GitCredentialDatasourceModel, 0, len(existingGitCredentials.Items))
for _, gitCredential := range existingGitCredentials.Items {
flattenedGitCredential := FlattenGitCredential(gitCredential)
Expand Down
4 changes: 4 additions & 0 deletions octopusdeploy_framework/datasource_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,12 +62,16 @@ func (l *lifecyclesDataSource) Read(ctx context.Context, req datasource.ReadRequ
Take: int(data.Take.ValueInt64()),
}

tflog.Debug(ctx, fmt.Sprintf("Reading lifecycles with query: %+v", query))

lifecyclesResult, err := lifecycles.Get(l.Config.Client, data.SpaceID.ValueString(), query)
if err != nil {
resp.Diagnostics.AddError("Client Error", fmt.Sprintf("Unable to read lifecycles, got error: %s", err))
return
}

tflog.Debug(ctx, fmt.Sprintf("Reading lifecycles returned %d items", len(lifecyclesResult.Items)))

data.Lifecycles = flattenLifecycles(lifecyclesResult.Items)
data.ID = types.StringValue("Lifecycles " + time.Now().UTC().String())

Expand Down
5 changes: 5 additions & 0 deletions octopusdeploy_framework/datasource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"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"
"time"
)

Expand Down Expand Up @@ -62,6 +63,8 @@ func (p *projectsDataSource) Read(ctx context.Context, req datasource.ReadReques
Take: int(data.Take.ValueInt64()),
}

tflog.Debug(ctx, fmt.Sprintf("Reading projects with query %+v", query))

if !data.IDs.IsNull() {
var ids []string
resp.Diagnostics.Append(data.IDs.ElementsAs(ctx, &ids, false)...)
Expand All @@ -79,6 +82,8 @@ func (p *projectsDataSource) Read(ctx context.Context, req datasource.ReadReques
return
}

tflog.Debug(ctx, fmt.Sprintf("Reading projects returned %d items", len(existingProjects.Items)))

data.Projects = make([]projectResourceModel, 0, len(existingProjects.Items))
for _, project := range existingProjects.Items {
flattenedProject, diags := flattenProject(ctx, project, &projectResourceModel{})
Expand Down
6 changes: 6 additions & 0 deletions octopusdeploy_framework/datasource_space.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package octopusdeploy_framework
import (
"context"
"fmt"
"github.com/hashicorp/terraform-plugin-log/tflog"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
Expand Down Expand Up @@ -46,6 +47,9 @@ func (b *spaceDataSource) Read(ctx context.Context, req datasource.ReadRequest,

// construct query
query := spaces.SpacesQuery{PartialName: data.Name.ValueString()}

tflog.Debug(ctx, fmt.Sprintf("Reading space with query %+v", query))

spacesResult, err := spaces.Get(b.Client, query)

if err != nil {
Expand All @@ -64,6 +68,8 @@ func (b *spaceDataSource) Read(ctx context.Context, req datasource.ReadRequest,
return
}

tflog.Debug(ctx, fmt.Sprintf("Reading space returned ID %s", matchedSpace.ID))

mapSpaceToState(ctx, &data, matchedSpace)

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down
6 changes: 6 additions & 0 deletions octopusdeploy_framework/datasource_spaces.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package octopusdeploy_framework

import (
"context"
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces"
"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/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"time"
)

Expand Down Expand Up @@ -74,6 +76,8 @@ func (b *spacesDataSource) Read(ctx context.Context, req datasource.ReadRequest,
Take: schemas.GetNumber(data.Take),
}

tflog.Debug(ctx, fmt.Sprintf("Reading Spaces with query %+v", query))

existingSpaces, err := spaces.Get(b.Client, query)
if err != nil {
resp.Diagnostics.AddError("unable to load spaces", err.Error())
Expand All @@ -87,6 +91,8 @@ func (b *spacesDataSource) Read(ctx context.Context, req datasource.ReadRequest,
mappedSpaces = append(mappedSpaces, s)
}

tflog.Debug(ctx, fmt.Sprintf("Reading spaces returned %d items", len(mappedSpaces)))

data.Spaces, _ = types.ListValueFrom(ctx, schemas.GetSpaceTypeAttributes(), mappedSpaces)
data.ID = types.StringValue("Spaces " + time.Now().UTC().String())

Expand Down
7 changes: 6 additions & 1 deletion octopusdeploy_framework/datasource_tag_sets.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/datasource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"time"
)

Expand Down Expand Up @@ -47,6 +48,9 @@ func (t *tagSetsDataSource) Read(ctx context.Context, req datasource.ReadRequest
Skip: int(data.Skip.ValueInt64()),
Take: int(data.Take.ValueInt64()),
}

tflog.Debug(ctx, fmt.Sprintf("Reading tag sets %+v", query))

spaceID := data.SpaceID.ValueString()

existingTagSets, err := tagsets.Get(t.Client, spaceID, query)
Expand All @@ -55,8 +59,9 @@ func (t *tagSetsDataSource) Read(ctx context.Context, req datasource.ReadRequest
return
}

data.TagSets = flattenTagSets(existingTagSets.Items)
tflog.Debug(ctx, fmt.Sprintf("Reading tag sets returned %d items", len(existingTagSets.Items)))

data.TagSets = flattenTagSets(existingTagSets.Items)
data.ID = types.StringValue(fmt.Sprintf("TagSets-%s", time.Now().UTC().String()))

resp.Diagnostics.Append(resp.State.Set(ctx, &data)...)
Expand Down
6 changes: 6 additions & 0 deletions octopusdeploy_framework/datasource_tenants.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,14 @@ package octopusdeploy_framework

import (
"context"
"fmt"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tenants"
"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"
datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"time"
)

Expand Down Expand Up @@ -62,6 +64,8 @@ func (b *tenantsDataSource) Read(ctx context.Context, req datasource.ReadRequest
Take: int(data.Take.ValueInt64()),
}

tflog.Debug(ctx, fmt.Sprintf("Reading tenats with query: %+v", query))

existingTenants, err := tenants.Get(b.Client, data.SpaceID.ValueString(), query)
if err != nil {
resp.Diagnostics.AddError("unable to load tenants", err.Error())
Expand All @@ -73,6 +77,8 @@ func (b *tenantsDataSource) Read(ctx context.Context, req datasource.ReadRequest
flattenedTenants = append(flattenedTenants, schemas.FlattenTenant(tenant))
}

tflog.Debug(ctx, fmt.Sprintf("Reading tenants returned %d items", len(flattenedTenants)))

data.ID = types.StringValue("Tenants " + time.Now().UTC().String())
data.Tenants, _ = types.ListValueFrom(ctx, types.ObjectType{AttrTypes: schemas.TenantObjectType()}, flattenedTenants)

Expand Down

0 comments on commit 638a650

Please sign in to comment.