From 638a6503bcb7df3292ce2efade1a49a693035583 Mon Sep 17 00:00:00 2001 From: Ben Pearce Date: Wed, 21 Aug 2024 21:22:08 +1000 Subject: [PATCH] added debug logging to datasources --- .../data_source_library_variable_sets.go | 5 +++++ octopusdeploy_framework/data_source_script_modules.go | 3 +++ octopusdeploy_framework/datasource_environments.go | 4 ++++ octopusdeploy_framework/datasource_feeds.go | 4 +++- octopusdeploy_framework/datasource_git_credentials.go | 6 ++++++ octopusdeploy_framework/datasource_lifecycle.go | 4 ++++ octopusdeploy_framework/datasource_project.go | 5 +++++ octopusdeploy_framework/datasource_space.go | 6 ++++++ octopusdeploy_framework/datasource_spaces.go | 6 ++++++ octopusdeploy_framework/datasource_tag_sets.go | 7 ++++++- octopusdeploy_framework/datasource_tenants.go | 6 ++++++ 11 files changed, 54 insertions(+), 2 deletions(-) diff --git a/octopusdeploy_framework/data_source_library_variable_sets.go b/octopusdeploy_framework/data_source_library_variable_sets.go index a68c8fae8..bb195fa87 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()), } + 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()) @@ -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..0ad6deff0 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()), } + 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 { @@ -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)...) } diff --git a/octopusdeploy_framework/datasource_environments.go b/octopusdeploy_framework/datasource_environments.go index da219658c..3742c8d01 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), } + 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()) @@ -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()) diff --git a/octopusdeploy_framework/datasource_feeds.go b/octopusdeploy_framework/datasource_feeds.go index fad80df86..29783ae8a 100644 --- a/octopusdeploy_framework/datasource_feeds.go +++ b/octopusdeploy_framework/datasource_feeds.go @@ -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 { diff --git a/octopusdeploy_framework/datasource_git_credentials.go b/octopusdeploy_framework/datasource_git_credentials.go index 0e9ef70fb..57728c8ec 100644 --- a/octopusdeploy_framework/datasource_git_credentials.go +++ b/octopusdeploy_framework/datasource_git_credentials.go @@ -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" ) @@ -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) @@ -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) diff --git a/octopusdeploy_framework/datasource_lifecycle.go b/octopusdeploy_framework/datasource_lifecycle.go index 3f07b54ce..c794aae37 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()), } + 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()) diff --git a/octopusdeploy_framework/datasource_project.go b/octopusdeploy_framework/datasource_project.go index 2653294b7..a2c28d5dc 100644 --- a/octopusdeploy_framework/datasource_project.go +++ b/octopusdeploy_framework/datasource_project.go @@ -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" ) @@ -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)...) @@ -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{}) diff --git a/octopusdeploy_framework/datasource_space.go b/octopusdeploy_framework/datasource_space.go index a5935e455..3ac6bb353 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()} + + tflog.Debug(ctx, fmt.Sprintf("Reading space with query %+v", 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..c29c21893 100644 --- a/octopusdeploy_framework/datasource_spaces.go +++ b/octopusdeploy_framework/datasource_spaces.go @@ -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" ) @@ -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()) @@ -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()) diff --git a/octopusdeploy_framework/datasource_tag_sets.go b/octopusdeploy_framework/datasource_tag_sets.go index 10566e299..ccf1c3029 100644 --- a/octopusdeploy_framework/datasource_tag_sets.go +++ b/octopusdeploy_framework/datasource_tag_sets.go @@ -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" ) @@ -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) @@ -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)...) diff --git a/octopusdeploy_framework/datasource_tenants.go b/octopusdeploy_framework/datasource_tenants.go index bf8b2867a..ad1da6d81 100644 --- a/octopusdeploy_framework/datasource_tenants.go +++ b/octopusdeploy_framework/datasource_tenants.go @@ -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" ) @@ -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()) @@ -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)