Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix project persistence settings #844

Merged
merged 2 commits into from
Dec 24, 2024
Merged
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
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
13 changes: 7 additions & 6 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 @@ -77,9 +78,9 @@ func (p ProjectSchema) GetResourceSchema() resourceSchema.Schema {
NestedObject: resourceSchema.NestedBlockObject{
Attributes: map[string]resourceSchema.Attribute{
"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(),
"base_path": util.ResourceString().Optional().Computed().Default(".octopus").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 @@ -89,9 +90,9 @@ func (p ProjectSchema) GetResourceSchema() resourceSchema.Schema {
Attributes: map[string]resourceSchema.Attribute{
"git_credential_id": util.ResourceString().Required().Build(),
"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(),
"base_path": util.ResourceString().Optional().Computed().Default(".octopus").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 @@ -102,9 +103,9 @@ func (p ProjectSchema) GetResourceSchema() resourceSchema.Schema {
"url": util.ResourceString().Required().Description("The URL associated with these version control settings.").Build(),
"username": util.ResourceString().Required().Description("The username for the Git credential.").Build(),
"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(),
"base_path": util.ResourceString().Optional().Computed().Default(".octopus").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
Loading