From d7fc15c6c8f1a69681c5da470899e0883c20df97 Mon Sep 17 00:00:00 2001 From: Isaac Calligeros <101079287+IsaacCalligeros95@users.noreply.github.com> Date: Thu, 15 Aug 2024 14:21:45 +0930 Subject: [PATCH] Chore!: fix lvs datasource unexpected changes and resource Known After Apply differences. (#739) * Fix an issue with help text and templates when empty * Fix library variable set resource and data source schema + changes * Remove template ids plan modifier --- docs/resources/library_variable_set.md | 2 +- .../schemas/library_variable_set.go | 10 +++++++--- octopusdeploy_framework/schemas/schema.go | 8 ++++++++ 3 files changed, 16 insertions(+), 4 deletions(-) diff --git a/docs/resources/library_variable_set.md b/docs/resources/library_variable_set.md index 9bff4bf78..1eac0caca 100644 --- a/docs/resources/library_variable_set.md +++ b/docs/resources/library_variable_set.md @@ -25,10 +25,10 @@ This resource manages library variable sets in Octopus Deploy. - `id` (String) The unique ID for this resource. - `space_id` (String) The space ID associated with this library variable set. - `template` (Block List) (see [below for nested schema](#nestedblock--template)) -- `template_ids` (Map of String) ### Read-Only +- `template_ids` (Map of String) - `variable_set_id` (String) diff --git a/octopusdeploy_framework/schemas/library_variable_set.go b/octopusdeploy_framework/schemas/library_variable_set.go index 76ba84d14..055db386c 100644 --- a/octopusdeploy_framework/schemas/library_variable_set.go +++ b/octopusdeploy_framework/schemas/library_variable_set.go @@ -7,6 +7,8 @@ import ( "github.com/hashicorp/terraform-plugin-framework/attr" datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema" resourceSchema "github.com/hashicorp/terraform-plugin-framework/resource/schema" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" types "github.com/hashicorp/terraform-plugin-framework/types" ) @@ -93,10 +95,12 @@ func GetLibraryVariableSetResourceSchema() resourceSchema.Schema { "template_ids": resourceSchema.MapAttribute{ ElementType: types.StringType, Computed: true, - Optional: true, }, "variable_set_id": resourceSchema.StringAttribute{ Computed: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, }, }, Description: "This resource manages library variable sets in Octopus Deploy.", @@ -135,7 +139,7 @@ func MapToLibraryVariableSet(data *LibraryVariableSetResourceModel) *variables.L func FlattenTemplates(actionTemplateParameters []actiontemplates.ActionTemplateParameter) types.List { if len(actionTemplateParameters) == 0 { - return types.ListNull(types.ObjectType{AttrTypes: TemplateObjectType()}) + return types.ListValueMust(types.ObjectType{AttrTypes: TemplateObjectType()}, []attr.Value{}) } actionTemplateList := make([]attr.Value, 0, len(actionTemplateParameters)) @@ -143,7 +147,7 @@ func FlattenTemplates(actionTemplateParameters []actiontemplates.ActionTemplateP attrs := map[string]attr.Value{ "default_value": util.Ternary(actionTemplateParams.DefaultValue.Value != "", types.StringValue(actionTemplateParams.DefaultValue.Value), types.StringNull()), "display_settings": flattenDisplaySettingsMap(actionTemplateParams.DisplaySettings), - "help_text": util.Ternary(actionTemplateParams.HelpText != "", types.StringValue(actionTemplateParams.HelpText), types.StringNull()), + "help_text": util.Ternary(actionTemplateParams.HelpText != "", types.StringValue(actionTemplateParams.HelpText), types.StringValue("")), "id": types.StringValue(actionTemplateParams.GetID()), "label": util.Ternary(actionTemplateParams.Label != "", types.StringValue(actionTemplateParams.Label), types.StringNull()), "name": types.StringValue(actionTemplateParams.Name), diff --git a/octopusdeploy_framework/schemas/schema.go b/octopusdeploy_framework/schemas/schema.go index 496dbc913..e67c11dc3 100644 --- a/octopusdeploy_framework/schemas/schema.go +++ b/octopusdeploy_framework/schemas/schema.go @@ -2,6 +2,8 @@ package schemas import ( "fmt" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/planmodifier" + "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringplanmodifier" "github.com/hashicorp/terraform-plugin-framework/resource/schema/booldefault" "github.com/hashicorp/terraform-plugin-framework/resource/schema/stringdefault" @@ -145,6 +147,9 @@ func GetIdResourceSchema() resourceSchema.Attribute { Description: "The unique ID for this resource.", Computed: true, Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, } } @@ -153,6 +158,9 @@ func GetSpaceIdResourceSchema(resourceDescription string) resourceSchema.Attribu Description: "The space ID associated with this " + resourceDescription + ".", Computed: true, Optional: true, + PlanModifiers: []planmodifier.String{ + stringplanmodifier.UseStateForUnknown(), + }, } }