Skip to content

Commit

Permalink
wip packages
Browse files Browse the repository at this point in the history
  • Loading branch information
domenicsim1 committed Oct 1, 2024
1 parent 8a573f0 commit 39a0629
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 15 deletions.
30 changes: 16 additions & 14 deletions octopusdeploy_framework/resource_step_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -204,10 +204,10 @@ func (r *stepTemplateTypeResource) Update(ctx context.Context, req resource.Upda
}
actionTemplateUpdate.Properties = templateProps
} else {
actionTemplateUpdate.Properties = make(map[string]core.PropertyValue, 0)
actionTemplateUpdate.Properties = make(map[string]core.PropertyValue)
}

actionTemplateUpdate.Packages = make([]packages.PackageReference, 0, len(pkgs))
actionTemplateUpdate.Packages = make([]packages.PackageReference, len(pkgs))
if len(pkgs) > 0 {
for i, val := range pkgs {
pkgProps := make(map[string]string, len(val.Properties.Attributes()))
Expand All @@ -223,16 +223,14 @@ func (r *stepTemplateTypeResource) Update(ctx context.Context, req resource.Upda
if resp.Diagnostics.HasError() {
return
}
if resp.Diagnostics.HasError() {
return
}
pkgRef := packages.PackageReference{
AcquisitionLocation: val.AcquisitionLocation.ValueString(),
FeedID: val.FeedID.ValueString(),
Properties: pkgProps,
Name: val.Name.ValueString(),
PackageID: val.PackageID.ValueString(),
}
pkgRef.ID = val.ID.ValueString()
actionTemplateUpdate.Packages[i] = pkgRef
}
}
Expand Down Expand Up @@ -290,13 +288,15 @@ func updateStepTemplate(data *schemas.StepTemplateTypeResourceModel, at *actiont
data.CommunityActionTemplateId = types.StringValue(at.CommunityActionTemplateID)
data.ActionType = types.StringValue(at.ActionType)

// Parameters
sParams, dg := convertStepTemplateToParameterAttributes(at.Parameters)
resp.Append(dg...)
if resp.HasError() {
return resp
}
data.Parameters = sParams

// Properties
stringProps := make(map[string]attr.Value, len(at.Properties))
for keys, value := range at.Properties {
stringProps[keys] = types.StringValue(value.Value)
Expand All @@ -308,6 +308,7 @@ func updateStepTemplate(data *schemas.StepTemplateTypeResourceModel, at *actiont
}
data.Properties = props

// Packages
pkgs, dg := convertStepTemplateToPackageAttributes(at.Packages)
resp.Append(dg...)
if resp.HasError() {
Expand Down Expand Up @@ -390,32 +391,33 @@ func convertStepTemplatePackagePropertyAttribute(atpp map[string]string) (types.
prop := make(map[string]attr.Value)
diags := diag.Diagnostics{}

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

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

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

propMap, dg := types.ObjectValue(schemas.GetStepTemplatePackagePropertiesTypeAttributes(), prop)
Expand Down
6 changes: 5 additions & 1 deletion octopusdeploy_framework/schemas/step_template.go
Original file line number Diff line number Diff line change
Expand Up @@ -120,6 +120,7 @@ func GetStepTemplatePackageSchema() rs.ListNestedAttribute {
Attributes: map[string]rs.Attribute{
"acquisition_location": rs.StringAttribute{
Default: stringdefault.StaticString("Server"),
Optional: true,
Computed: true,
},
"feed_id": rs.StringAttribute{
Expand All @@ -137,13 +138,16 @@ func GetStepTemplatePackageSchema() rs.ListNestedAttribute {
Attributes: map[string]rs.Attribute{
"extract": rs.StringAttribute{
Default: stringdefault.StaticString("True"),
Optional: true,
Computed: true,
},
"package_parameter_name": rs.StringAttribute{
Required: true,
},
"purpose": rs.StringAttribute{
Default: stringdefault.StaticString(""),
Optional: true,
Required: false,
Computed: true,
},
"selection_mode": rs.StringAttribute{
Expand Down Expand Up @@ -177,7 +181,7 @@ type StepTemplatePackageType struct {
Name types.String `tfsdk:"name"`
FeedID types.String `tfsdk:"feed_id"`
PackageID types.String `tfsdk:"package_id"`
Properties types.Object `tfsdk:"Properties"`
Properties types.Object `tfsdk:"properties"`
}

func GetStepTemplatePackageTypeAttributes() map[string]attr.Type {
Expand Down

0 comments on commit 39a0629

Please sign in to comment.