Skip to content

Commit

Permalink
chore: update remaining migrated resources
Browse files Browse the repository at this point in the history
  • Loading branch information
hnrkndrssn committed Aug 8, 2024
1 parent 8d08416 commit f65c5b9
Show file tree
Hide file tree
Showing 30 changed files with 115 additions and 40 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand Down Expand Up @@ -78,7 +80,9 @@ func (r *awsElasticContainerRegistryFeedTypeResource) Read(ctx context.Context,
client := r.Config.Client
feed, err := feeds.GetByID(client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load aws elastic container registry", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "aws elastic container registry"); err != nil {
resp.Diagnostics.AddError("unable to load aws elastic container registry", err.Error())
}
return
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand Down Expand Up @@ -76,7 +78,9 @@ func (r *dockerContainerRegistryFeedTypeResource) Read(ctx context.Context, req
client := r.Config.Client
feed, err := feeds.GetByID(client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load docker container registry feed", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "docker container registry feed"); err != nil {
resp.Diagnostics.AddError("unable to load docker container registry feed", err.Error())
}
return
}

Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/resource_environment.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import (

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/environments"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/extensions"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -82,7 +83,10 @@ func (r *environmentTypeResource) Read(ctx context.Context, req resource.ReadReq

environment, err := environments.GetByID(r.Config.Client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load environment", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "environment"); err != nil {
resp.Diagnostics.AddError("unable to load environment", err.Error())
}
return
}

updateEnvironment(ctx, &data, environment)
Expand Down
9 changes: 7 additions & 2 deletions octopusdeploy_framework/resource_git_credential.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,10 @@ package octopusdeploy_framework

import (
"context"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/credentials"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand All @@ -18,13 +20,14 @@ type gitCredentialResource struct {
}

type gitCredentialResourceModel struct {
ID types.String `tfsdk:"id"`
SpaceID types.String `tfsdk:"space_id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
Type types.String `tfsdk:"type"`
Username types.String `tfsdk:"username"`
Password types.String `tfsdk:"password"`

schemas.ResourceModel
}

func NewGitCredentialResource() resource.Resource {
Expand Down Expand Up @@ -92,7 +95,9 @@ func (g *gitCredentialResource) Read(ctx context.Context, req resource.ReadReque

gitCredential, err := credentials.GetByID(g.Client, state.SpaceID.ValueString(), state.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("Error reading Git credential", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, state, err, "git credential"); err != nil {
resp.Diagnostics.AddError("Error reading Git credential", err.Error())
}
return
}

Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/resource_github_repository_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand Down Expand Up @@ -78,7 +80,9 @@ func (r *githubRepositoryFeedTypeResource) Read(ctx context.Context, req resourc
client := r.Config.Client
feed, err := feeds.GetByID(client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load github repository feed", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "github repository feed"); err != nil {
resp.Diagnostics.AddError("unable to load github repository feed", err.Error())
}
return
}

Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/resource_helm_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand Down Expand Up @@ -77,7 +79,9 @@ func (r *helmFeedTypeResource) Read(ctx context.Context, req resource.ReadReques
client := r.Config.Client
feed, err := feeds.GetByID(client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load helm feed", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "helm feed"); err != nil {
resp.Diagnostics.AddError("unable to load helm feed", err.Error())
}
return
}

Expand Down
8 changes: 6 additions & 2 deletions octopusdeploy_framework/resource_library_variable_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,14 @@ package octopusdeploy_framework
import (
"context"
"fmt"
"log"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/libraryvariablesets"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-log/tflog"
"log"
)

type libraryVariableSetFeedTypeResource struct {
Expand Down Expand Up @@ -61,7 +63,9 @@ func (r *libraryVariableSetFeedTypeResource) Read(ctx context.Context, req resou

libraryVariableSet, err := libraryvariablesets.GetByID(r.Config.Client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load library variable set", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "library variable set"); err != nil {
resp.Diagnostics.AddError("unable to load library variable set", err.Error())
}
return
}

Expand Down
17 changes: 12 additions & 5 deletions octopusdeploy_framework/resource_lifecycle.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,16 +3,18 @@ package octopusdeploy_framework
import (
"context"
"fmt"
"strings"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/lifecycles"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
"github.com/hashicorp/terraform-plugin-framework/path"
"github.com/hashicorp/terraform-plugin-framework/resource"
"github.com/hashicorp/terraform-plugin-framework/types"
"github.com/hashicorp/terraform-plugin-log/tflog"
"strings"
)

type lifecycleTypeResource struct {
Expand All @@ -23,13 +25,14 @@ var _ resource.Resource = &lifecycleTypeResource{}
var _ resource.ResourceWithImportState = &lifecycleTypeResource{}

type lifecycleTypeResourceModel struct {
ID types.String `tfsdk:"id"`
SpaceID types.String `tfsdk:"space_id"`
Name types.String `tfsdk:"name"`
Description types.String `tfsdk:"description"`
Phase types.List `tfsdk:"phase"`
ReleaseRetentionPolicy types.List `tfsdk:"release_retention_policy"`
TentacleRetentionPolicy types.List `tfsdk:"tentacle_retention_policy"`

schemas.ResourceModel
}

func NewLifecycleResource() resource.Resource {
Expand Down Expand Up @@ -88,7 +91,9 @@ func (r *lifecycleTypeResource) Read(ctx context.Context, req resource.ReadReque

lifecycle, err := lifecycles.GetByID(r.Config.Client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load lifecycle", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "lifecycle"); err != nil {
resp.Diagnostics.AddError("unable to load lifecycle", err.Error())
}
return
}
data = flattenLifecycleResource(lifecycle)
Expand Down Expand Up @@ -195,15 +200,17 @@ func setDefaultRetentionPolicies(data *lifecycleTypeResourceModel) {
}

func flattenLifecycleResource(lifecycle *lifecycles.Lifecycle) *lifecycleTypeResourceModel {
return &lifecycleTypeResourceModel{
ID: types.StringValue(lifecycle.ID),
flattenedLifecycle := &lifecycleTypeResourceModel{
SpaceID: types.StringValue(lifecycle.SpaceID),
Name: types.StringValue(lifecycle.Name),
Description: types.StringValue(lifecycle.Description),
Phase: flattenPhases(lifecycle.Phases),
ReleaseRetentionPolicy: flattenRetentionPeriod(lifecycle.ReleaseRetentionPolicy),
TentacleRetentionPolicy: flattenRetentionPeriod(lifecycle.TentacleRetentionPolicy),
}
flattenedLifecycle.ID = types.StringValue(lifecycle.GetID())

return flattenedLifecycle
}

func flattenPhases(phases []*lifecycles.Phase) types.List {
Expand Down
7 changes: 4 additions & 3 deletions octopusdeploy_framework/resource_lifecycle_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,9 @@ package octopusdeploy_framework

import (
"fmt"
"path/filepath"
"testing"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/client"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/lifecycles"
Expand All @@ -13,8 +16,6 @@ import (
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-plugin-testing/terraform"
"github.com/stretchr/testify/require"
"path/filepath"
"testing"
)

func TestExpandLifecycleWithNil(t *testing.T) {
Expand All @@ -31,7 +32,6 @@ func TestExpandLifecycle(t *testing.T) {
tentacleRetention := core.NewRetentionPeriod(2, "Items", false)

data := &lifecycleTypeResourceModel{
ID: types.StringValue(Id),
Description: types.StringValue(description),
Name: types.StringValue(name),
SpaceID: types.StringValue(spaceID),
Expand Down Expand Up @@ -62,6 +62,7 @@ func TestExpandLifecycle(t *testing.T) {
},
),
}
data.ID = types.StringValue(Id)

lifecycle := expandLifecycle(data)

Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/resource_maven_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand Down Expand Up @@ -76,7 +78,9 @@ func (r *mavenFeedTypeResource) Read(ctx context.Context, req resource.ReadReque
client := r.Config.Client
feed, err := feeds.GetByID(client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load maven feed", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "maven feed"); err != nil {
resp.Diagnostics.AddError("unable to load maven feed", err.Error())
}
return
}

Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/resource_nuget_feed.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/feeds"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/attr"
Expand Down Expand Up @@ -78,7 +80,9 @@ func (r *nugetFeedTypeResource) Read(ctx context.Context, req resource.ReadReque
client := r.Config.Client
feed, err := feeds.GetByID(client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load nuget feed", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "nuget feed"); err != nil {
resp.Diagnostics.AddError("unable to load nuget feed", err.Error())
}
return
}

Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/resource_project.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projects"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -92,7 +94,9 @@ func (r *projectResource) Read(ctx context.Context, req resource.ReadRequest, re

project, err := projects.GetByID(r.Client, state.SpaceID.ValueString(), state.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("Error reading project", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, state, err, "lifecycle"); err != nil {
resp.Diagnostics.AddError("Error reading project", err.Error())
}
return
}
if persistenceSettings != nil {
Expand Down
4 changes: 3 additions & 1 deletion octopusdeploy_framework/resource_project_flatten.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/OctopusDeploy/go-octopusdeploy/v2/pkg/actiontemplates"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core"
"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/credentials"
Expand All @@ -26,7 +27,6 @@ func flattenProject(ctx context.Context, project *projects.Project, state *proje
}

model := &projectResourceModel{
ID: types.StringValue(project.GetID()),
SpaceID: types.StringValue(project.SpaceID),
Name: types.StringValue(project.Name),
Description: types.StringValue(project.Description),
Expand All @@ -48,6 +48,8 @@ func flattenProject(ctx context.Context, project *projects.Project, state *proje
ClonedFromProjectID: util.StringOrNull(project.ClonedFromProjectID),
}

model.ID = types.StringValue(project.GetID())

model.IncludedLibraryVariableSets = util.FlattenStringList(project.IncludedLibraryVariableSets)
model.AutoDeployReleaseOverrides = flattenAutoDeployReleaseOverrides(project.AutoDeployReleaseOverrides)

Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/resource_project_group.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,9 @@ package octopusdeploy_framework
import (
"context"
"fmt"

"github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/projectgroups"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/internal/errors"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas"
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
"github.com/hashicorp/terraform-plugin-framework/resource"
Expand Down Expand Up @@ -67,7 +69,9 @@ func (r *projectGroupTypeResource) Read(ctx context.Context, req resource.ReadRe

group, err := projectgroups.GetByID(r.Config.Client, data.SpaceID.ValueString(), data.ID.ValueString())
if err != nil {
resp.Diagnostics.AddError("unable to load project group", err.Error())
if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "project group"); err != nil {
resp.Diagnostics.AddError("unable to load project group", err.Error())
}
return
}

Expand Down
Loading

0 comments on commit f65c5b9

Please sign in to comment.