Skip to content

Commit

Permalink
fix: small step template fixes
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 authored Nov 28, 2024
1 parent 7432680 commit e709e02
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 18 deletions.
43 changes: 26 additions & 17 deletions octopusdeploy_framework/resource_step_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -210,19 +210,7 @@ func mapStepTemplateResourceModelToActionTemplate(ctx context.Context, data sche
at.Packages = make([]packages.PackageReference, len(pkgs))
if len(pkgs) > 0 {
for i, val := range pkgs {
pkgProps := make(map[string]string, len(val.Properties.Attributes()))
for key, prop := range val.Properties.Attributes() {
if prop.Type(ctx) == types.StringType {
pkgProps[key] = prop.(types.String).ValueString()
} else {
// We should not get this error unless we add a field to package properties in the schema that is not a string
resp.AddError("Unexpected value type in package properties.",
fmt.Sprintf("Expected [%s] to have value of string but got [%s].", key, prop.String()))
}
}
if resp.HasError() {
return at, resp
}
pkgProps := convertAttributeStepTemplatePackageProperty(val.Properties.Attributes())
pkgRef := packages.PackageReference{
AcquisitionLocation: val.AcquisitionLocation.ValueString(),
FeedID: val.FeedID.ValueString(),
Expand Down Expand Up @@ -335,28 +323,28 @@ func convertStepTemplatePackagePropertyAttribute(atpp map[string]string) (types.
diags := diag.Diagnostics{}

// We need to manually convert the string map to ensure all fields are set.
if extract, ok := atpp["extract"]; ok {
if extract, ok := atpp["Extract"]; ok {
prop["extract"] = types.StringValue(extract)
} else {
diags.AddWarning("Package property missing value.", "extract value missing from package property")
prop["extract"] = types.StringNull()
}

if purpose, ok := atpp["purpose"]; ok {
if purpose, ok := atpp["Purpose"]; ok {
prop["purpose"] = types.StringValue(purpose)
} else {
diags.AddWarning("Package property missing value.", "purpose value missing from package property")
prop["purpose"] = types.StringNull()
}

if purpose, ok := atpp["package_parameter_name"]; ok {
if purpose, ok := atpp["PackageParameterName"]; ok {
prop["package_parameter_name"] = types.StringValue(purpose)
} else {
diags.AddWarning("Package property missing value.", "package_parameter_name value missing from package property")
prop["package_parameter_name"] = types.StringNull()
}

if selectionMode, ok := atpp["selection_mode"]; ok {
if selectionMode, ok := atpp["SelectionMode"]; ok {
prop["selection_mode"] = types.StringValue(selectionMode)
} else {
diags.AddWarning("Package property missing value.", "selection_mode value missing from package property")
Expand All @@ -370,3 +358,24 @@ func convertStepTemplatePackagePropertyAttribute(atpp map[string]string) (types.
}
return propMap, diags
}

func convertAttributeStepTemplatePackageProperty(prop map[string]attr.Value) map[string]string {
atpp := make(map[string]string)

if extract, ok := prop["extract"]; ok {
atpp["Extract"] = extract.(types.String).ValueString()
}

if purpose, ok := prop["purpose"]; ok {
atpp["Purpose"] = purpose.(types.String).ValueString()
}

if purpose, ok := prop["package_parameter_name"]; ok {
atpp["PackageParameterName"] = purpose.(types.String).ValueString()
}

if selectionMode, ok := prop["selection_mode"]; ok {
atpp["SelectionMode"] = selectionMode.(types.String).ValueString()
}
return atpp
}
3 changes: 2 additions & 1 deletion octopusdeploy_framework/schemas/step_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -163,6 +163,7 @@ func GetStepTemplateParameterResourceSchema() rs.ListNestedAttribute {
"label": rs.StringAttribute{
Description: "The label shown beside the parameter when presented in the deployment process. Example: `Server name`.",
Optional: true,
Computed: true,
PlanModifiers: []planmodifier.String{
stringplanmodifier.UseStateForUnknown(),
},
Expand Down Expand Up @@ -213,7 +214,7 @@ func GetStepTemplatePackageResourceSchema() rs.ListNestedAttribute {
Optional: true,
Computed: true,
Validators: []validator.String{
stringvalidator.RegexMatches(regexp.MustCompile("^(True|Fasle)$"), "Extract must be True or False"),
stringvalidator.RegexMatches(regexp.MustCompile("^(True|False)$"), "Extract must be True or False"),
},
},
"package_parameter_name": rs.StringAttribute{
Expand Down

0 comments on commit e709e02

Please sign in to comment.