From 4f8f2e661864b9d110b9d1e36ee8b13e3da267e4 Mon Sep 17 00:00:00 2001 From: Rocktavious Date: Fri, 16 Aug 2024 13:31:02 -0500 Subject: [PATCH] hotfix 1.1.3 state upgraders for checks --- .github/workflows/release.yml | 20 ++++++----- opslevel/common.go | 8 +++++ ...ource_opslevel_check_alert_source_usage.go | 23 ++++++++++++ ...resource_opslevel_check_repository_file.go | 28 +++++++++++++++ ...resource_opslevel_check_repository_grep.go | 28 +++++++++++++++ ...source_opslevel_check_repository_search.go | 27 ++++++++++++++ ...source_opslevel_check_service_ownership.go | 36 +++++++++++++++++++ ...esource_opslevel_check_service_property.go | 25 +++++++++++++ .../resource_opslevel_check_tag_defined.go | 19 ++++++++++ .../resource_opslevel_check_tool_usage.go | 25 +++++++++++++ submodules/opslevel-go | 2 +- 11 files changed, 232 insertions(+), 9 deletions(-) diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index 9153f2bf..f2addb54 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -1,7 +1,17 @@ name: "Release" on: - workflow_dispatch: {} + workflow_dispatch: + inputs: + bump: + description: 'The version bump type' + required: true + default: 'patch' + type: choice + options: + - patch + - minor + - major repository_dispatch: types: - release @@ -21,18 +31,12 @@ jobs: token: ${{ secrets.ORG_GITHUB_TOKEN }} - name: Fetch All Tags run: git fetch --force --tags - - name: Get version bump - id: bump - env: - VERSION_BUMP: ${{ toJson(github.event.client_payload.bump) }} - run: | - echo version_bump=$(echo $VERSION_BUMP | tr -d "\"") >> $GITHUB_OUTPUT - name: Determine Next Version id: next_version uses: zwaldowski/semver-release-action@v4 with: dry_run: true - bump: ${{ steps.bump.outputs.version_bump }} + bump: ${{ inputs.bump || toJson(github.event.client_payload.bump) }} prefix: "v" github_token: ${{ secrets.GITHUB_TOKEN }} - name: Set up Go diff --git a/opslevel/common.go b/opslevel/common.go index c5d3bdd4..0c41d276 100644 --- a/opslevel/common.go +++ b/opslevel/common.go @@ -167,3 +167,11 @@ func flattenTeamsArray(teams *opslevel.TeamConnection) []string { } return output } + +func CheckUpgradeFunc[T any]() func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { + return func(ctx context.Context, req resource.UpgradeStateRequest, resp *resource.UpgradeStateResponse) { + upgradedStateModel := *new(T) + resp.Diagnostics.Append(req.State.Get(ctx, &upgradedStateModel)...) + resp.Diagnostics.Append(resp.State.Set(ctx, upgradedStateModel)...) + } +} diff --git a/opslevel/resource_opslevel_check_alert_source_usage.go b/opslevel/resource_opslevel_check_alert_source_usage.go index dd6f5983..1912e920 100644 --- a/opslevel/resource_opslevel_check_alert_source_usage.go +++ b/opslevel/resource_opslevel_check_alert_source_usage.go @@ -92,6 +92,7 @@ func (r *CheckAlertSourceUsageResource) Metadata(ctx context.Context, req resour func (r *CheckAlertSourceUsageResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Alert Source Usage Resource", @@ -109,6 +110,28 @@ func (r *CheckAlertSourceUsageResource) Schema(ctx context.Context, req resource } } +func (r *CheckAlertSourceUsageResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "alert_type": schema.StringAttribute{ + Description: fmt.Sprintf( + "The type of the alert source. One of `%s`", + strings.Join(opslevel.AllAlertSourceTypeEnum, "`, `"), + ), + Required: true, + Validators: []validator.String{stringvalidator.OneOf(opslevel.AllAlertSourceTypeEnum...)}, + }, + "alert_name_predicate": PredicateSchema(), + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckAlertSourceUsageResourceModel](), + }, + } +} + func (r *CheckAlertSourceUsageResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckAlertSourceUsageResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/opslevel/resource_opslevel_check_repository_file.go b/opslevel/resource_opslevel_check_repository_file.go index 96a4a68d..ff3b7835 100644 --- a/opslevel/resource_opslevel_check_repository_file.go +++ b/opslevel/resource_opslevel_check_repository_file.go @@ -96,6 +96,7 @@ func (r *CheckRepositoryFileResource) Metadata(ctx context.Context, req resource func (r *CheckRepositoryFileResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Repository File Resource", @@ -118,6 +119,33 @@ func (r *CheckRepositoryFileResource) Schema(ctx context.Context, req resource.S } } +func (r *CheckRepositoryFileResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "directory_search": schema.BoolAttribute{ + Description: "Whether the check looks for the existence of a directory instead of a file.", + Required: true, + }, + "filepaths": schema.ListAttribute{ + Description: "Restrict the search to certain file paths.", + Required: true, + ElementType: types.StringType, + }, + "file_contents_predicate": PredicateSchema(), + "use_absolute_root": schema.BoolAttribute{ + Description: "Whether the checks looks at the absolute root of a repo or the relative root (the directory specified when attached a repo to a service).", + Required: true, + }, + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckRepositoryFileResourceModel](), + }, + } +} + func (r *CheckRepositoryFileResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckRepositoryFileResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/opslevel/resource_opslevel_check_repository_grep.go b/opslevel/resource_opslevel_check_repository_grep.go index 9a74f5f2..880407c7 100644 --- a/opslevel/resource_opslevel_check_repository_grep.go +++ b/opslevel/resource_opslevel_check_repository_grep.go @@ -95,6 +95,7 @@ func (r *CheckRepositoryGrepResource) Schema(ctx context.Context, req resource.S predicateSchema.Required = true resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Repository Grep Resource", @@ -113,6 +114,33 @@ func (r *CheckRepositoryGrepResource) Schema(ctx context.Context, req resource.S } } +func (r *CheckRepositoryGrepResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + predicateSchema := PredicateSchema() + predicateSchema.Optional = false + predicateSchema.Required = true + + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "directory_search": schema.BoolAttribute{ + Description: "Whether the check looks for the existence of a directory instead of a file.", + Required: true, + }, + "filepaths": schema.ListAttribute{ + Description: "Restrict the search to certain file paths.", + Required: true, + ElementType: types.StringType, + }, + "file_contents_predicate": predicateSchema, + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckRepositoryGrepResourceModel](), + }, + } +} + func (r *CheckRepositoryGrepResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckRepositoryGrepResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/opslevel/resource_opslevel_check_repository_search.go b/opslevel/resource_opslevel_check_repository_search.go index 6c615677..84a2287b 100644 --- a/opslevel/resource_opslevel_check_repository_search.go +++ b/opslevel/resource_opslevel_check_repository_search.go @@ -101,6 +101,7 @@ func (r *CheckRepositorySearchResource) Schema(ctx context.Context, req resource predicateSchema.Required = true resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Repository Search Resource", @@ -118,6 +119,32 @@ func (r *CheckRepositorySearchResource) Schema(ctx context.Context, req resource } } +func (r *CheckRepositorySearchResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + predicateSchema := PredicateSchema() + predicateSchema.Optional = false + predicateSchema.Required = true + + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "file_extensions": schema.SetAttribute{ + Description: "Restrict the search to files of given extensions. Extensions should contain only letters and numbers. For example: [\"py\", \"rb\"].", + Optional: true, + ElementType: types.StringType, + Validators: []validator.Set{ + setvalidator.SizeAtLeast(1), + }, + }, + "file_contents_predicate": predicateSchema, + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckRepositorySearchResourceModel](), + }, + } +} + func (r *CheckRepositorySearchResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckRepositorySearchResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/opslevel/resource_opslevel_check_service_ownership.go b/opslevel/resource_opslevel_check_service_ownership.go index cf8c5004..d7608b94 100644 --- a/opslevel/resource_opslevel_check_service_ownership.go +++ b/opslevel/resource_opslevel_check_service_ownership.go @@ -107,6 +107,7 @@ func (r *CheckServiceOwnershipResource) Metadata(ctx context.Context, req resour func (r *CheckServiceOwnershipResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { enumAllContactTypes := append(opslevel.AllContactType, "any") resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Service Ownership Resource", @@ -136,6 +137,41 @@ func (r *CheckServiceOwnershipResource) Schema(ctx context.Context, req resource } } +func (r *CheckServiceOwnershipResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + enumAllContactTypes := append(opslevel.AllContactType, "any") + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "require_contact_method": schema.BoolAttribute{ + Description: "True if a service's owner must have a contact method, False otherwise.", + Computed: true, + Optional: true, + Default: booldefault.StaticBool(false), + }, + "contact_method": schema.StringAttribute{ + Description: fmt.Sprintf( + "The type of contact method that is required. One of `%s`", + strings.Join(enumAllContactTypes, "`, `"), + ), + Computed: true, + Optional: true, + Default: stringdefault.StaticString("ANY"), + Validators: []validator.String{stringvalidator.OneOfCaseInsensitive(enumAllContactTypes...)}, + }, + "tag_key": schema.StringAttribute{ + Description: "The tag key where the tag predicate should be applied.", + Optional: true, + }, + "tag_predicate": PredicateSchema(), + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckServiceOwnershipResourceModel](), + }, + } +} + func (r *CheckServiceOwnershipResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckServiceOwnershipResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/opslevel/resource_opslevel_check_service_property.go b/opslevel/resource_opslevel_check_service_property.go index 11a05695..a2c42de9 100644 --- a/opslevel/resource_opslevel_check_service_property.go +++ b/opslevel/resource_opslevel_check_service_property.go @@ -93,6 +93,7 @@ func (r *CheckServicePropertyResource) Metadata(ctx context.Context, req resourc func (r *CheckServicePropertyResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Service Property Resource", @@ -112,6 +113,30 @@ func (r *CheckServicePropertyResource) Schema(ctx context.Context, req resource. } } +func (r *CheckServicePropertyResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "property": schema.StringAttribute{ + Description: fmt.Sprintf( + "The property of the service that the check will verify. One of `%s`", + strings.Join(opslevel.AllServicePropertyTypeEnum, "`, `"), + ), + Required: true, + Validators: []validator.String{ + stringvalidator.OneOf(opslevel.AllServicePropertyTypeEnum...), + }, + }, + "predicate": PredicateSchema(), + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckServicePropertyResourceModel](), + }, + } +} + func (r *CheckServicePropertyResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckServicePropertyResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/opslevel/resource_opslevel_check_tag_defined.go b/opslevel/resource_opslevel_check_tag_defined.go index 2bdb3e8b..f33864d1 100644 --- a/opslevel/resource_opslevel_check_tag_defined.go +++ b/opslevel/resource_opslevel_check_tag_defined.go @@ -90,6 +90,7 @@ func (r *CheckTagDefinedResource) Metadata(ctx context.Context, req resource.Met func (r *CheckTagDefinedResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Tag Defined Resource", @@ -103,6 +104,24 @@ func (r *CheckTagDefinedResource) Schema(ctx context.Context, req resource.Schem } } +func (r *CheckTagDefinedResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "tag_key": schema.StringAttribute{ + Description: "The tag key where the tag predicate should be applied.", + Required: true, + }, + "tag_predicate": PredicateSchema(), + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckTagDefinedResourceModel](), + }, + } +} + func (r *CheckTagDefinedResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckTagDefinedResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/opslevel/resource_opslevel_check_tool_usage.go b/opslevel/resource_opslevel_check_tool_usage.go index f11972d0..6c1578f6 100644 --- a/opslevel/resource_opslevel_check_tool_usage.go +++ b/opslevel/resource_opslevel_check_tool_usage.go @@ -116,6 +116,7 @@ func (r *CheckToolUsageResource) Metadata(ctx context.Context, req resource.Meta func (r *CheckToolUsageResource) Schema(ctx context.Context, req resource.SchemaRequest, resp *resource.SchemaResponse) { resp.Schema = schema.Schema{ + Version: 1, // This description is used by the documentation generator and the language server. MarkdownDescription: "Check Tool Usage Resource", @@ -135,6 +136,30 @@ func (r *CheckToolUsageResource) Schema(ctx context.Context, req resource.Schema } } +func (r *CheckToolUsageResource) UpgradeState(ctx context.Context) map[int64]resource.StateUpgrader { + return map[int64]resource.StateUpgrader{ + // State upgrade implementation from 0 (prior state version) to 1 (Schema.Version) + 0: { + PriorSchema: &schema.Schema{ + Attributes: CheckBaseAttributes(map[string]schema.Attribute{ + "tool_category": schema.StringAttribute{ + Description: fmt.Sprintf( + "The category that the tool belongs to. One of `%s`", + strings.Join(opslevel.AllToolCategory, "`, `"), + ), + Required: true, + Validators: []validator.String{stringvalidator.OneOf(opslevel.AllToolCategory...)}, + }, + "environment_predicate": PredicateSchema(), + "tool_name_predicate": PredicateSchema(), + "tool_url_predicate": PredicateSchema(), + }), + }, + StateUpgrader: CheckUpgradeFunc[CheckToolUsageResourceModel](), + }, + } +} + func (r *CheckToolUsageResource) ValidateConfig(ctx context.Context, req resource.ValidateConfigRequest, resp *resource.ValidateConfigResponse) { var configModel CheckToolUsageResourceModel resp.Diagnostics.Append(req.Config.Get(ctx, &configModel)...) diff --git a/submodules/opslevel-go b/submodules/opslevel-go index cf8155fc..c7a61b5b 160000 --- a/submodules/opslevel-go +++ b/submodules/opslevel-go @@ -1 +1 @@ -Subproject commit cf8155fc865c66f8cbbee54ac018049156c8973c +Subproject commit c7a61b5ba417a173cf4e0e1465834cc0f4b8c097