Skip to content

Commit

Permalink
fix: Project persistence settings error when protected_branches is no…
Browse files Browse the repository at this point in the history
…t provided
  • Loading branch information
mik-ky committed Dec 23, 2024
1 parent 6643d95 commit 1dbb5c7
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 4 deletions.
15 changes: 14 additions & 1 deletion octopusdeploy_framework/resource_project_expand.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,8 @@ package octopusdeploy_framework
import (
"context"
"fmt"
"net/url"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/actiontemplates"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/credentials"
Expand All @@ -11,7 +13,6 @@ import (
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-framework/types/basetypes"
"github.com/hashicorp/terraform-plugin-log/tflog"
"net/url"
)

func expandProject(ctx context.Context, model projectResourceModel) *projects.Project {
Expand Down Expand Up @@ -143,6 +144,10 @@ func expandGitLibraryPersistenceSettings(ctx context.Context, model gitLibraryPe
var protectedBranches []string
model.ProtectedBranches.ElementsAs(ctx, &protectedBranches, false)

if protectedBranches == nil {
protectedBranches = []string{}
}

return projects.NewGitPersistenceSettings(
model.BasePath.ValueString(),
credentials.NewReference(model.GitCredentialID.ValueString()),
Expand All @@ -157,6 +162,10 @@ func expandGitUsernamePasswordPersistenceSettings(ctx context.Context, model git
var protectedBranches []string
model.ProtectedBranches.ElementsAs(ctx, &protectedBranches, false)

if protectedBranches == nil {
protectedBranches = []string{}
}

return projects.NewGitPersistenceSettings(
model.BasePath.ValueString(),
credentials.NewUsernamePassword(
Expand All @@ -174,6 +183,10 @@ func expandGitAnonymousPersistenceSettings(ctx context.Context, model gitAnonymo
var protectedBranches []string
model.ProtectedBranches.ElementsAs(ctx, &protectedBranches, false)

if protectedBranches == nil {
protectedBranches = []string{}
}

return projects.NewGitPersistenceSettings(
model.BasePath.ValueString(),
credentials.NewAnonymous(),
Expand Down
7 changes: 4 additions & 3 deletions octopusdeploy_framework/schemas/project.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ import (
"github.com/hashicorp/terraform-plugin-framework/resource/schema/listplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/objectplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/setplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier"
"github.com/hashicorp/terraform-plugin-framework/types"
)
Expand Down Expand Up @@ -79,7 +80,7 @@ func (p ProjectSchema) GetResourceSchema() resourceSchema.Schema {
"url": util.ResourceString().Required().Description("The URL associated with these version control settings.").Build(),
"base_path": util.ResourceString().Optional().Description("The base path associated with these version control settings.").Build(),
"default_branch": util.ResourceString().Optional().Description("The default branch associated with these version control settings.").Build(),
"protected_branches": util.ResourceSet(types.StringType).Optional().Description("A list of protected branch patterns.").Build(),
"protected_branches": util.ResourceSet(types.StringType).Optional().Computed().PlanModifiers(setplanmodifier.UseStateForUnknown()).Description("A list of protected branch patterns.").Build(),
},
},
Description: "Provides Git-related persistence settings for a version-controlled project.",
Expand All @@ -91,7 +92,7 @@ func (p ProjectSchema) GetResourceSchema() resourceSchema.Schema {
"url": util.ResourceString().Required().Description("The URL associated with these version control settings.").Build(),
"base_path": util.ResourceString().Optional().Description("The base path associated with these version control settings.").Build(),
"default_branch": util.ResourceString().Optional().Description("The default branch associated with these version control settings.").Build(),
"protected_branches": util.ResourceSet(types.StringType).Optional().Description("A list of protected branch patterns.").Build(),
"protected_branches": util.ResourceSet(types.StringType).Optional().Computed().PlanModifiers(setplanmodifier.UseStateForUnknown()).Description("A list of protected branch patterns.").Build(),
},
},
Description: "Provides Git-related persistence settings for a version-controlled project.",
Expand All @@ -104,7 +105,7 @@ func (p ProjectSchema) GetResourceSchema() resourceSchema.Schema {
"password": util.ResourceString().Sensitive().Required().Description("The password for the Git credential").Build(), //util.GetPasswordResourceSchema(false),
"base_path": util.ResourceString().Optional().Description("The base path associated with these version control settings.").Build(),
"default_branch": util.ResourceString().Optional().Description("The default branch associated with these version control settings.").Build(),
"protected_branches": util.ResourceSet(types.StringType).Optional().Description("A list of protected branch patterns.").Build(),
"protected_branches": util.ResourceSet(types.StringType).Optional().Computed().PlanModifiers(setplanmodifier.UseStateForUnknown()).Description("A list of protected branch patterns.").Build(),
},
},
Description: "Provides Git-related persistence settings for a version-controlled project.",
Expand Down

0 comments on commit 1dbb5c7

Please sign in to comment.