Skip to content

Commit

Permalink
Chore!: fix lvs datasource unexpected changes and resource Known Afte…
Browse files Browse the repository at this point in the history
…r 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
  • Loading branch information
IsaacCalligeros95 authored Aug 15, 2024
1 parent 0678c06 commit d7fc15c
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 4 deletions.
2 changes: 1 addition & 1 deletion docs/resources/library_variable_set.md
Original file line number Diff line number Diff line change
Expand Up @@ -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)

<a id="nestedblock--template"></a>
Expand Down
10 changes: 7 additions & 3 deletions octopusdeploy_framework/schemas/library_variable_set.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
)

Expand Down Expand Up @@ -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.",
Expand Down Expand Up @@ -135,15 +139,15 @@ 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))

for _, actionTemplateParams := range actionTemplateParameters {
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),
Expand Down
8 changes: 8 additions & 0 deletions octopusdeploy_framework/schemas/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -145,6 +147,9 @@ func GetIdResourceSchema() resourceSchema.Attribute {
Description: "The unique ID for this resource.",
Computed: true,
Optional: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
}
}

Expand All @@ -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(),
},
}
}

Expand Down

0 comments on commit d7fc15c

Please sign in to comment.