diff --git a/octopusdeploy_framework/data_source_library_variable_sets.go b/octopusdeploy_framework/data_source_library_variable_sets.go index a68c8fae8..5f8137d29 100644 --- a/octopusdeploy_framework/data_source_library_variable_sets.go +++ b/octopusdeploy_framework/data_source_library_variable_sets.go @@ -66,12 +66,16 @@ func (l *libraryVariableSetDataSource) Read(ctx context.Context, req datasource. Take: int(data.Take.ValueInt64()), } + util.DatasourceReading(ctx, "library variable set", 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 } + util.DatasourceResultCount(ctx, "library variable set", len(existingLibraryVariableSets.Items)) + data.LibraryVariableSets = flattenLibraryVariableSets(existingLibraryVariableSets.Items) data.ID = types.StringValue("Library Variables Sets " + time.Now().UTC().String()) @@ -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) } diff --git a/octopusdeploy_framework/data_source_script_modules.go b/octopusdeploy_framework/data_source_script_modules.go index 8374402de..c56ab3cee 100644 --- a/octopusdeploy_framework/data_source_script_modules.go +++ b/octopusdeploy_framework/data_source_script_modules.go @@ -54,6 +54,8 @@ func (l *scriptModulesDataSource) Read(ctx context.Context, req datasource.ReadR Take: int(data.Take.ValueInt64()), } + util.DatasourceReading(ctx, "script modules", query) + spaceID := data.SpaceID.ValueString() existingScriptModules, err := scriptmodules.Get(l.Config.Client, spaceID, query) if err != nil { @@ -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()) + util.DatasourceResultCount(ctx, "script modules", len(existingScriptModules.Items)) resp.Diagnostics.Append(resp.State.Set(ctx, &data)...) } diff --git a/octopusdeploy_framework/datasource_environments.go b/octopusdeploy_framework/datasource_environments.go index da219658c..d8ff7c4f8 100644 --- a/octopusdeploy_framework/datasource_environments.go +++ b/octopusdeploy_framework/datasource_environments.go @@ -84,6 +84,8 @@ func (e *environmentDataSource) Read(ctx context.Context, req datasource.ReadReq Take: util.GetNumber(data.Take), } + util.DatasourceReading(ctx, "environments", query) + existingEnvironments, err := environments.Get(e.Client, data.SpaceID.ValueString(), query) if err != nil { resp.Diagnostics.AddError("unable to load environments", err.Error()) @@ -109,6 +111,8 @@ func (e *environmentDataSource) Read(ctx context.Context, req datasource.ReadReq } } + util.DatasourceResultCount(ctx, "environments", len(mappedEnvironments)) + data.Environments, _ = types.ListValueFrom(ctx, types.ObjectType{AttrTypes: schemas.EnvironmentObjectType()}, mappedEnvironments) data.ID = types.StringValue("Environments " + time.Now().UTC().String()) diff --git a/octopusdeploy_framework/datasource_feeds.go b/octopusdeploy_framework/datasource_feeds.go index fad80df86..58fcd2087 100644 --- a/octopusdeploy_framework/datasource_feeds.go +++ b/octopusdeploy_framework/datasource_feeds.go @@ -2,13 +2,11 @@ package octopusdeploy_framework import ( "context" - "fmt" "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" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds" @@ -60,12 +58,15 @@ func (e *feedsDataSource) Read(ctx context.Context, req datasource.ReadRequest, Take: util.GetNumber(data.Take), } + util.DatasourceReading(ctx, "feeds", 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)) + + util.DatasourceResultCount(ctx, "feeds", len(existingFeeds.Items)) flattenedFeeds := []interface{}{} for _, feed := range existingFeeds.Items { diff --git a/octopusdeploy_framework/datasource_git_credentials.go b/octopusdeploy_framework/datasource_git_credentials.go index 0e9ef70fb..961ef3e40 100644 --- a/octopusdeploy_framework/datasource_git_credentials.go +++ b/octopusdeploy_framework/datasource_git_credentials.go @@ -64,6 +64,9 @@ func (g *gitCredentialsDataSource) Read(ctx context.Context, req datasource.Read Skip: int(data.Skip.ValueInt64()), Take: int(data.Take.ValueInt64()), } + + util.DatasourceReading(ctx, "git credentials", query) + spaceID := data.SpaceID.ValueString() existingGitCredentials, err := credentials.Get(g.Client, spaceID, query) @@ -72,6 +75,8 @@ func (g *gitCredentialsDataSource) Read(ctx context.Context, req datasource.Read return } + util.DatasourceResultCount(ctx, "git credentials", len(existingGitCredentials.Items)) + flattenedGitCredentials := make([]GitCredentialDatasourceModel, 0, len(existingGitCredentials.Items)) for _, gitCredential := range existingGitCredentials.Items { flattenedGitCredential := FlattenGitCredential(gitCredential) diff --git a/octopusdeploy_framework/datasource_lifecycle.go b/octopusdeploy_framework/datasource_lifecycle.go index 3f07b54ce..3acd52a0e 100644 --- a/octopusdeploy_framework/datasource_lifecycle.go +++ b/octopusdeploy_framework/datasource_lifecycle.go @@ -62,12 +62,16 @@ func (l *lifecyclesDataSource) Read(ctx context.Context, req datasource.ReadRequ Take: int(data.Take.ValueInt64()), } + util.DatasourceReading(ctx, "lifecycles", 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 } + util.DatasourceResultCount(ctx, "lifecycles", len(lifecyclesResult.Items)) + data.Lifecycles = flattenLifecycles(lifecyclesResult.Items) data.ID = types.StringValue("Lifecycles " + time.Now().UTC().String()) diff --git a/octopusdeploy_framework/datasource_project.go b/octopusdeploy_framework/datasource_project.go index 2653294b7..8d68227a7 100644 --- a/octopusdeploy_framework/datasource_project.go +++ b/octopusdeploy_framework/datasource_project.go @@ -62,6 +62,8 @@ func (p *projectsDataSource) Read(ctx context.Context, req datasource.ReadReques Take: int(data.Take.ValueInt64()), } + util.DatasourceReading(ctx, "projects", query) + if !data.IDs.IsNull() { var ids []string resp.Diagnostics.Append(data.IDs.ElementsAs(ctx, &ids, false)...) @@ -79,6 +81,8 @@ func (p *projectsDataSource) Read(ctx context.Context, req datasource.ReadReques return } + util.DatasourceResultCount(ctx, "projects", len(existingProjects.Items)) + data.Projects = make([]projectResourceModel, 0, len(existingProjects.Items)) for _, project := range existingProjects.Items { flattenedProject, diags := flattenProject(ctx, project, &projectResourceModel{}) diff --git a/octopusdeploy_framework/datasource_project_groups.go b/octopusdeploy_framework/datasource_project_groups.go index 6e647ca1a..5f8ac460c 100644 --- a/octopusdeploy_framework/datasource_project_groups.go +++ b/octopusdeploy_framework/datasource_project_groups.go @@ -104,6 +104,8 @@ func (p *projectGroupsDataSource) Read(ctx context.Context, req datasource.ReadR } spaceID := data.SpaceID.ValueString() + util.DatasourceReading(ctx, "project groups", query) + existingProjectGroups, err := projectgroups.Get(p.Client, spaceID, query) if err != nil { resp.Diagnostics.AddError("unable to load project groups", err.Error()) @@ -121,7 +123,8 @@ func (p *projectGroupsDataSource) Read(ctx context.Context, req datasource.ReadR newGroups = append(newGroups, g) } - //groups, _ := types.ObjectValueFrom(ctx, types.ObjectType{AttrTypes: getNestedGroupAttributes()}, newGroups) + util.DatasourceResultCount(ctx, "project groups", len(newGroups)) + for _, projectGroup := range newGroups { tflog.Debug(ctx, "mapped group "+projectGroup.Name.ValueString()) } diff --git a/octopusdeploy_framework/datasource_space.go b/octopusdeploy_framework/datasource_space.go index a5935e455..1a261ed3e 100644 --- a/octopusdeploy_framework/datasource_space.go +++ b/octopusdeploy_framework/datasource_space.go @@ -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" @@ -46,6 +47,9 @@ func (b *spaceDataSource) Read(ctx context.Context, req datasource.ReadRequest, // construct query query := spaces.SpacesQuery{PartialName: data.Name.ValueString()} + + util.DatasourceReading(ctx, "space", query) + spacesResult, err := spaces.Get(b.Client, query) if err != nil { @@ -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)...) diff --git a/octopusdeploy_framework/datasource_spaces.go b/octopusdeploy_framework/datasource_spaces.go index 1e447e16b..5828974b0 100644 --- a/octopusdeploy_framework/datasource_spaces.go +++ b/octopusdeploy_framework/datasource_spaces.go @@ -74,6 +74,8 @@ func (b *spacesDataSource) Read(ctx context.Context, req datasource.ReadRequest, Take: schemas.GetNumber(data.Take), } + util.DatasourceReading(ctx, "spaces", query) + existingSpaces, err := spaces.Get(b.Client, query) if err != nil { resp.Diagnostics.AddError("unable to load spaces", err.Error()) @@ -87,6 +89,8 @@ func (b *spacesDataSource) Read(ctx context.Context, req datasource.ReadRequest, mappedSpaces = append(mappedSpaces, s) } + util.DatasourceResultCount(ctx, "spaces", len(mappedSpaces)) + data.Spaces, _ = types.ListValueFrom(ctx, schemas.GetSpaceTypeAttributes(), mappedSpaces) data.ID = types.StringValue("Spaces " + time.Now().UTC().String()) diff --git a/octopusdeploy_framework/datasource_tag_sets.go b/octopusdeploy_framework/datasource_tag_sets.go index 10566e299..53cfc3ebd 100644 --- a/octopusdeploy_framework/datasource_tag_sets.go +++ b/octopusdeploy_framework/datasource_tag_sets.go @@ -47,6 +47,9 @@ func (t *tagSetsDataSource) Read(ctx context.Context, req datasource.ReadRequest Skip: int(data.Skip.ValueInt64()), Take: int(data.Take.ValueInt64()), } + + util.DatasourceReading(ctx, "tag sets", query) + spaceID := data.SpaceID.ValueString() existingTagSets, err := tagsets.Get(t.Client, spaceID, query) @@ -55,8 +58,9 @@ func (t *tagSetsDataSource) Read(ctx context.Context, req datasource.ReadRequest return } - data.TagSets = flattenTagSets(existingTagSets.Items) + util.DatasourceResultCount(ctx, "tag sets", 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)...) diff --git a/octopusdeploy_framework/datasource_tenants.go b/octopusdeploy_framework/datasource_tenants.go index bf8b2867a..fc0654a3e 100644 --- a/octopusdeploy_framework/datasource_tenants.go +++ b/octopusdeploy_framework/datasource_tenants.go @@ -62,6 +62,8 @@ func (b *tenantsDataSource) Read(ctx context.Context, req datasource.ReadRequest Take: int(data.Take.ValueInt64()), } + util.DatasourceReading(ctx, "tenants", query) + existingTenants, err := tenants.Get(b.Client, data.SpaceID.ValueString(), query) if err != nil { resp.Diagnostics.AddError("unable to load tenants", err.Error()) @@ -73,6 +75,8 @@ func (b *tenantsDataSource) Read(ctx context.Context, req datasource.ReadRequest flattenedTenants = append(flattenedTenants, schemas.FlattenTenant(tenant)) } + util.DatasourceResultCount(ctx, "tenants", len(flattenedTenants)) + data.ID = types.StringValue("Tenants " + time.Now().UTC().String()) data.Tenants, _ = types.ListValueFrom(ctx, types.ObjectType{AttrTypes: schemas.TenantObjectType()}, flattenedTenants) diff --git a/octopusdeploy_framework/util/logging.go b/octopusdeploy_framework/util/logging.go index 66b3ca311..1a225b921 100644 --- a/octopusdeploy_framework/util/logging.go +++ b/octopusdeploy_framework/util/logging.go @@ -3,7 +3,6 @@ package util import ( "context" "fmt" - "github.com/hashicorp/terraform-plugin-log/tflog" ) @@ -27,6 +26,14 @@ func Reading(ctx context.Context, resource string, v ...any) { tflog.Info(ctx, fmt.Sprintf("reading %s: %#v", resource, v)) } +func DatasourceReading(ctx context.Context, resource string, v ...any) { + tflog.Debug(ctx, fmt.Sprintf("reading %s data source with query: %+v", resource, v)) +} + +func DatasourceResultCount(ctx context.Context, resource string, count int) { + tflog.Debug(ctx, fmt.Sprintf("reading %s returned %d items", resource, count)) +} + func Read(ctx context.Context, resource string, v ...any) { tflog.Info(ctx, fmt.Sprintf("read %s: %#v", resource, v)) }