From f65c5b9fc041ef8159ef22aa7e43e7d0fcd4b259 Mon Sep 17 00:00:00 2001 From: hnrkndrssn Date: Thu, 8 Aug 2024 14:20:33 +1000 Subject: [PATCH] chore: update remaining migrated resources --- .../resource_aws_elastic_container_registry.go | 6 +++++- .../resource_docker_container_registry.go | 6 +++++- octopusdeploy_framework/resource_environment.go | 6 +++++- .../resource_git_credential.go | 9 +++++++-- .../resource_github_repository_feed.go | 6 +++++- octopusdeploy_framework/resource_helm_feed.go | 6 +++++- .../resource_library_variable_set.go | 8 ++++++-- octopusdeploy_framework/resource_lifecycle.go | 17 ++++++++++++----- .../resource_lifecycle_test.go | 7 ++++--- octopusdeploy_framework/resource_maven_feed.go | 6 +++++- octopusdeploy_framework/resource_nuget_feed.go | 6 +++++- octopusdeploy_framework/resource_project.go | 6 +++++- .../resource_project_flatten.go | 4 +++- .../resource_project_group.go | 6 +++++- .../resource_project_model.go | 4 +++- octopusdeploy_framework/resource_space.go | 8 ++++++-- .../resource_tenant_common_variable.go | 3 ++- .../resource_tenant_project.go | 3 ++- .../resource_tenant_project_variable.go | 6 ++++-- .../schemas/aws_elastic_container_registry.go | 3 ++- .../schemas/docker_container_registry_feed.go | 3 ++- octopusdeploy_framework/schemas/environment.go | 3 ++- .../schemas/github_repository_feed.go | 3 ++- octopusdeploy_framework/schemas/helm_feed.go | 3 ++- .../schemas/library_variable_set.go | 3 ++- octopusdeploy_framework/schemas/maven_feed.go | 3 ++- octopusdeploy_framework/schemas/nuget_feed.go | 3 ++- .../schemas/project_group.go | 3 ++- octopusdeploy_framework/schemas/resource.go | 2 +- octopusdeploy_framework/schemas/space.go | 3 ++- 30 files changed, 115 insertions(+), 40 deletions(-) diff --git a/octopusdeploy_framework/resource_aws_elastic_container_registry.go b/octopusdeploy_framework/resource_aws_elastic_container_registry.go index 72cef3b51..daeb36f31 100644 --- a/octopusdeploy_framework/resource_aws_elastic_container_registry.go +++ b/octopusdeploy_framework/resource_aws_elastic_container_registry.go @@ -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" @@ -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 } diff --git a/octopusdeploy_framework/resource_docker_container_registry.go b/octopusdeploy_framework/resource_docker_container_registry.go index fa73ef902..0b246633e 100644 --- a/octopusdeploy_framework/resource_docker_container_registry.go +++ b/octopusdeploy_framework/resource_docker_container_registry.go @@ -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" @@ -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 } diff --git a/octopusdeploy_framework/resource_environment.go b/octopusdeploy_framework/resource_environment.go index a393279ad..281639f6d 100644 --- a/octopusdeploy_framework/resource_environment.go +++ b/octopusdeploy_framework/resource_environment.go @@ -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" @@ -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) diff --git a/octopusdeploy_framework/resource_git_credential.go b/octopusdeploy_framework/resource_git_credential.go index 478b4f8b4..8a5baeec1 100644 --- a/octopusdeploy_framework/resource_git_credential.go +++ b/octopusdeploy_framework/resource_git_credential.go @@ -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" @@ -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 { @@ -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 } diff --git a/octopusdeploy_framework/resource_github_repository_feed.go b/octopusdeploy_framework/resource_github_repository_feed.go index 30f7bdb28..6b6aabb63 100644 --- a/octopusdeploy_framework/resource_github_repository_feed.go +++ b/octopusdeploy_framework/resource_github_repository_feed.go @@ -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" @@ -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 } diff --git a/octopusdeploy_framework/resource_helm_feed.go b/octopusdeploy_framework/resource_helm_feed.go index 64ec52677..dd7667eff 100644 --- a/octopusdeploy_framework/resource_helm_feed.go +++ b/octopusdeploy_framework/resource_helm_feed.go @@ -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" @@ -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 } diff --git a/octopusdeploy_framework/resource_library_variable_set.go b/octopusdeploy_framework/resource_library_variable_set.go index 733b88664..cdf616aa0 100644 --- a/octopusdeploy_framework/resource_library_variable_set.go +++ b/octopusdeploy_framework/resource_library_variable_set.go @@ -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 { @@ -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 } diff --git a/octopusdeploy_framework/resource_lifecycle.go b/octopusdeploy_framework/resource_lifecycle.go index afdea2ef6..a4c863f8c 100644 --- a/octopusdeploy_framework/resource_lifecycle.go +++ b/octopusdeploy_framework/resource_lifecycle.go @@ -3,8 +3,11 @@ 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" @@ -12,7 +15,6 @@ import ( "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 { @@ -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 { @@ -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) @@ -195,8 +200,7 @@ 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), @@ -204,6 +208,9 @@ func flattenLifecycleResource(lifecycle *lifecycles.Lifecycle) *lifecycleTypeRes ReleaseRetentionPolicy: flattenRetentionPeriod(lifecycle.ReleaseRetentionPolicy), TentacleRetentionPolicy: flattenRetentionPeriod(lifecycle.TentacleRetentionPolicy), } + flattenedLifecycle.ID = types.StringValue(lifecycle.GetID()) + + return flattenedLifecycle } func flattenPhases(phases []*lifecycles.Phase) types.List { diff --git a/octopusdeploy_framework/resource_lifecycle_test.go b/octopusdeploy_framework/resource_lifecycle_test.go index 639fc6a93..bbcc08030 100644 --- a/octopusdeploy_framework/resource_lifecycle_test.go +++ b/octopusdeploy_framework/resource_lifecycle_test.go @@ -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" @@ -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) { @@ -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), @@ -62,6 +62,7 @@ func TestExpandLifecycle(t *testing.T) { }, ), } + data.ID = types.StringValue(Id) lifecycle := expandLifecycle(data) diff --git a/octopusdeploy_framework/resource_maven_feed.go b/octopusdeploy_framework/resource_maven_feed.go index 722081e81..55346da60 100644 --- a/octopusdeploy_framework/resource_maven_feed.go +++ b/octopusdeploy_framework/resource_maven_feed.go @@ -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" @@ -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 } diff --git a/octopusdeploy_framework/resource_nuget_feed.go b/octopusdeploy_framework/resource_nuget_feed.go index f053ea450..bf0576248 100644 --- a/octopusdeploy_framework/resource_nuget_feed.go +++ b/octopusdeploy_framework/resource_nuget_feed.go @@ -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" @@ -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 } diff --git a/octopusdeploy_framework/resource_project.go b/octopusdeploy_framework/resource_project.go index 6b73a6d7a..bcefbbf69 100644 --- a/octopusdeploy_framework/resource_project.go +++ b/octopusdeploy_framework/resource_project.go @@ -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" @@ -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 { diff --git a/octopusdeploy_framework/resource_project_flatten.go b/octopusdeploy_framework/resource_project_flatten.go index 39b4c3e80..6e411b08d 100644 --- a/octopusdeploy_framework/resource_project_flatten.go +++ b/octopusdeploy_framework/resource_project_flatten.go @@ -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" @@ -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), @@ -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) diff --git a/octopusdeploy_framework/resource_project_group.go b/octopusdeploy_framework/resource_project_group.go index e78f49cef..8d7a628de 100644 --- a/octopusdeploy_framework/resource_project_group.go +++ b/octopusdeploy_framework/resource_project_group.go @@ -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" @@ -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 } diff --git a/octopusdeploy_framework/resource_project_model.go b/octopusdeploy_framework/resource_project_model.go index 7e7386079..d58409893 100644 --- a/octopusdeploy_framework/resource_project_model.go +++ b/octopusdeploy_framework/resource_project_model.go @@ -1,11 +1,11 @@ package octopusdeploy_framework import ( + "github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/schemas" "github.com/hashicorp/terraform-plugin-framework/types" ) type projectResourceModel struct { - ID types.String `tfsdk:"id"` SpaceID types.String `tfsdk:"space_id"` Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` @@ -37,6 +37,8 @@ type projectResourceModel struct { ServiceNowExtensionSettings types.List `tfsdk:"servicenow_extension_settings"` IncludedLibraryVariableSets types.List `tfsdk:"included_library_variable_sets"` AutoDeployReleaseOverrides types.List `tfsdk:"auto_deploy_release_overrides"` + + schemas.ResourceModel } type connectivityPolicyModel struct { diff --git a/octopusdeploy_framework/resource_space.go b/octopusdeploy_framework/resource_space.go index 01cf13cdb..42470551a 100644 --- a/octopusdeploy_framework/resource_space.go +++ b/octopusdeploy_framework/resource_space.go @@ -3,7 +3,10 @@ package octopusdeploy_framework import ( "context" "fmt" + "strings" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/spaces" + "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/path" @@ -11,7 +14,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource/schema" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "strings" ) const spaceManagersTeamIDPrefix = "teams-spacemanagers-" @@ -129,7 +131,9 @@ func (s *spaceResource) Read(ctx context.Context, req resource.ReadRequest, resp spaceResult, err := spaces.GetByID(s.Client, data.ID.ValueString()) if err != nil { - resp.Diagnostics.AddError("unable to query spaces", err.Error()) + if err := errors.ProcessApiErrorV2(ctx, resp, data, err, "space"); err != nil { + resp.Diagnostics.AddError("unable to query spaces", err.Error()) + } return } diff --git a/octopusdeploy_framework/resource_tenant_common_variable.go b/octopusdeploy_framework/resource_tenant_common_variable.go index 5ce0bd4a3..715f306bb 100644 --- a/octopusdeploy_framework/resource_tenant_common_variable.go +++ b/octopusdeploy_framework/resource_tenant_common_variable.go @@ -24,12 +24,13 @@ type tenantCommonVariableResource struct { } type tenantCommonVariableResourceModel struct { - ID types.String `tfsdk:"id"` SpaceID types.String `tfsdk:"space_id"` TenantID types.String `tfsdk:"tenant_id"` LibraryVariableSetID types.String `tfsdk:"library_variable_set_id"` TemplateID types.String `tfsdk:"template_id"` Value types.String `tfsdk:"value"` + + schemas.ResourceModel } func NewTenantCommonVariableResource() resource.Resource { diff --git a/octopusdeploy_framework/resource_tenant_project.go b/octopusdeploy_framework/resource_tenant_project.go index f860af3e3..37a6879c9 100644 --- a/octopusdeploy_framework/resource_tenant_project.go +++ b/octopusdeploy_framework/resource_tenant_project.go @@ -21,11 +21,12 @@ import ( ) type TenantProjectModel struct { - ID types.String `tfsdk:"id"` SpaceID types.String `tfsdk:"space_id"` TenantID types.String `tfsdk:"tenant_id"` ProjectID types.String `tfsdk:"project_id"` EnvironmentIDs types.List `tfsdk:"environment_ids"` + + schemas.ResourceModel } type tenantProjectResource struct { diff --git a/octopusdeploy_framework/resource_tenant_project_variable.go b/octopusdeploy_framework/resource_tenant_project_variable.go index 7c7fb8191..7718f658e 100644 --- a/octopusdeploy_framework/resource_tenant_project_variable.go +++ b/octopusdeploy_framework/resource_tenant_project_variable.go @@ -3,6 +3,8 @@ package octopusdeploy_framework import ( "context" "fmt" + "strings" + "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/core" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/tenants" "github.com/OctopusDeploy/go-octopusdeploy/v2/pkg/variables" @@ -12,7 +14,6 @@ import ( "github.com/hashicorp/terraform-plugin-framework/resource" "github.com/hashicorp/terraform-plugin-framework/types" "github.com/hashicorp/terraform-plugin-log/tflog" - "strings" ) var _ resource.Resource = &tenantProjectVariableResource{} @@ -23,13 +24,14 @@ type tenantProjectVariableResource struct { } type tenantProjectVariableResourceModel struct { - ID types.String `tfsdk:"id"` SpaceID types.String `tfsdk:"space_id"` TenantID types.String `tfsdk:"tenant_id"` ProjectID types.String `tfsdk:"project_id"` EnvironmentID types.String `tfsdk:"environment_id"` TemplateID types.String `tfsdk:"template_id"` Value types.String `tfsdk:"value"` + + schemas.ResourceModel } func NewTenantProjectVariableResource() resource.Resource { diff --git a/octopusdeploy_framework/schemas/aws_elastic_container_registry.go b/octopusdeploy_framework/schemas/aws_elastic_container_registry.go index 92c3c847b..fbc321f9e 100644 --- a/octopusdeploy_framework/schemas/aws_elastic_container_registry.go +++ b/octopusdeploy_framework/schemas/aws_elastic_container_registry.go @@ -32,10 +32,11 @@ func GetAwsElasticContainerRegistryFeedResourceSchema() map[string]resourceSchem type AwsElasticContainerRegistryFeedTypeResourceModel struct { AccessKey types.String `tfsdk:"access_key"` - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` PackageAcquisitionLocationOptions types.List `tfsdk:"package_acquisition_location_options"` Region types.String `tfsdk:"region"` SecretKey types.String `tfsdk:"secret_key"` SpaceID types.String `tfsdk:"space_id"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/docker_container_registry_feed.go b/octopusdeploy_framework/schemas/docker_container_registry_feed.go index d7ff550c4..346eee869 100644 --- a/octopusdeploy_framework/schemas/docker_container_registry_feed.go +++ b/octopusdeploy_framework/schemas/docker_container_registry_feed.go @@ -29,11 +29,12 @@ func GetDockerContainerRegistryFeedResourceSchema() map[string]resourceSchema.At type DockerContainerRegistryFeedTypeResourceModel struct { APIVersion types.String `tfsdk:"api_version"` FeedUri types.String `tfsdk:"feed_uri"` - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` PackageAcquisitionLocationOptions types.List `tfsdk:"package_acquisition_location_options"` Password types.String `tfsdk:"password"` SpaceID types.String `tfsdk:"space_id"` Username types.String `tfsdk:"username"` RegistryPath types.String `tfsdk:"registry_path"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/environment.go b/octopusdeploy_framework/schemas/environment.go index af4a31e20..964532446 100644 --- a/octopusdeploy_framework/schemas/environment.go +++ b/octopusdeploy_framework/schemas/environment.go @@ -180,7 +180,6 @@ func MapServiceNowExtensionSettings(serviceNowExtensionSettings *environments.Se } type EnvironmentTypeResourceModel struct { - ID types.String `tfsdk:"id"` Slug types.String `tfsdk:"slug"` Name types.String `tfsdk:"name"` Description types.String `tfsdk:"description"` @@ -191,4 +190,6 @@ type EnvironmentTypeResourceModel struct { JiraExtensionSettings types.List `tfsdk:"jira_extension_settings"` JiraServiceManagementExtensionSettings types.List `tfsdk:"jira_service_management_extension_settings"` ServiceNowExtensionSettings types.List `tfsdk:"servicenow_extension_settings"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/github_repository_feed.go b/octopusdeploy_framework/schemas/github_repository_feed.go index 12cda7b7e..71049f464 100644 --- a/octopusdeploy_framework/schemas/github_repository_feed.go +++ b/octopusdeploy_framework/schemas/github_repository_feed.go @@ -26,10 +26,11 @@ type GitHubRepositoryFeedTypeResourceModel struct { DownloadAttempts types.Int64 `tfsdk:"download_attempts"` DownloadRetryBackoffSeconds types.Int64 `tfsdk:"download_retry_backoff_seconds"` FeedUri types.String `tfsdk:"feed_uri"` - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` PackageAcquisitionLocationOptions types.List `tfsdk:"package_acquisition_location_options"` Password types.String `tfsdk:"password"` SpaceID types.String `tfsdk:"space_id"` Username types.String `tfsdk:"username"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/helm_feed.go b/octopusdeploy_framework/schemas/helm_feed.go index 62b567b60..7e3072fee 100644 --- a/octopusdeploy_framework/schemas/helm_feed.go +++ b/octopusdeploy_framework/schemas/helm_feed.go @@ -22,10 +22,11 @@ func GetHelmFeedResourceSchema() map[string]resourceSchema.Attribute { type HelmFeedTypeResourceModel struct { FeedUri types.String `tfsdk:"feed_uri"` - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` PackageAcquisitionLocationOptions types.List `tfsdk:"package_acquisition_location_options"` Password types.String `tfsdk:"password"` SpaceID types.String `tfsdk:"space_id"` Username types.String `tfsdk:"username"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/library_variable_set.go b/octopusdeploy_framework/schemas/library_variable_set.go index 5fab75d02..3ca65b627 100644 --- a/octopusdeploy_framework/schemas/library_variable_set.go +++ b/octopusdeploy_framework/schemas/library_variable_set.go @@ -12,12 +12,13 @@ import ( type LibraryVariableSetResourceModel struct { Description types.String `tfsdk:"description"` - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` SpaceID types.String `tfsdk:"space_id"` Template types.List `tfsdk:"template"` TemplateIds types.Map `tfsdk:"template_ids"` VariableSetId types.String `tfsdk:"variable_set_id"` + + ResourceModel } func GetLibraryVariableSetDataSourceSchema() datasourceSchema.Schema { diff --git a/octopusdeploy_framework/schemas/maven_feed.go b/octopusdeploy_framework/schemas/maven_feed.go index 096d7b4f4..9c01debc3 100644 --- a/octopusdeploy_framework/schemas/maven_feed.go +++ b/octopusdeploy_framework/schemas/maven_feed.go @@ -26,10 +26,11 @@ type MavenFeedTypeResourceModel struct { DownloadAttempts types.Int64 `tfsdk:"download_attempts"` DownloadRetryBackoffSeconds types.Int64 `tfsdk:"download_retry_backoff_seconds"` FeedUri types.String `tfsdk:"feed_uri"` - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` PackageAcquisitionLocationOptions types.List `tfsdk:"package_acquisition_location_options"` Password types.String `tfsdk:"password"` SpaceID types.String `tfsdk:"space_id"` Username types.String `tfsdk:"username"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/nuget_feed.go b/octopusdeploy_framework/schemas/nuget_feed.go index a9d5567fb..a744dafb1 100644 --- a/octopusdeploy_framework/schemas/nuget_feed.go +++ b/octopusdeploy_framework/schemas/nuget_feed.go @@ -33,11 +33,12 @@ type NugetFeedTypeResourceModel struct { DownloadAttempts types.Int64 `tfsdk:"download_attempts"` DownloadRetryBackoffSeconds types.Int64 `tfsdk:"download_retry_backoff_seconds"` FeedUri types.String `tfsdk:"feed_uri"` - ID types.String `tfsdk:"id"` IsEnhancedMode types.Bool `tfsdk:"is_enhanced_mode"` Name types.String `tfsdk:"name"` PackageAcquisitionLocationOptions types.List `tfsdk:"package_acquisition_location_options"` Password types.String `tfsdk:"password"` SpaceID types.String `tfsdk:"space_id"` Username types.String `tfsdk:"username"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/project_group.go b/octopusdeploy_framework/schemas/project_group.go index 1aaf65d18..bafc5ea42 100644 --- a/octopusdeploy_framework/schemas/project_group.go +++ b/octopusdeploy_framework/schemas/project_group.go @@ -43,9 +43,10 @@ func GetProjectGroupResourceSchema() map[string]resourceSchema.Attribute { } type ProjectGroupTypeResourceModel struct { - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` SpaceID types.String `tfsdk:"space_id"` Description types.String `tfsdk:"description"` RetentionPolicyID types.String `tfsdk:"retention_policy_id"` + + ResourceModel } diff --git a/octopusdeploy_framework/schemas/resource.go b/octopusdeploy_framework/schemas/resource.go index b06b16555..b97eb5efc 100644 --- a/octopusdeploy_framework/schemas/resource.go +++ b/octopusdeploy_framework/schemas/resource.go @@ -11,7 +11,7 @@ type IResourceModel interface { type ResourceModel struct { ID types.String `tfsdk:"id"` - IResourceModel `tfsdk:"-"` + IResourceModel `tfsdk:"-"` // Ignore resource model interface in object conversion } func (r ResourceModel) GetID() string { diff --git a/octopusdeploy_framework/schemas/space.go b/octopusdeploy_framework/schemas/space.go index c14354752..662a95c96 100644 --- a/octopusdeploy_framework/schemas/space.go +++ b/octopusdeploy_framework/schemas/space.go @@ -11,7 +11,6 @@ import ( const spaceDescription = "space" type SpaceModel struct { - ID types.String `tfsdk:"id"` Name types.String `tfsdk:"name"` Slug types.String `tfsdk:"slug"` Description types.String `tfsdk:"description"` @@ -19,6 +18,8 @@ type SpaceModel struct { SpaceManagersTeams types.Set `tfsdk:"space_managers_teams"` SpaceManagersTeamMembers types.Set `tfsdk:"space_managers_team_members"` IsTaskQueueStopped types.Bool `tfsdk:"is_task_queue_stopped"` + + ResourceModel } func GetSpaceResourceSchema() map[string]resourceSchema.Attribute {