Skip to content

Commit 9f38a53

Browse files
committed
add strategy to the lifecycle resource functions
1 parent 7a0567e commit 9f38a53

File tree

1 file changed

+16
-6
lines changed

1 file changed

+16
-6
lines changed

octopusdeploy_framework/resource_lifecycle.go

Lines changed: 16 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -235,6 +235,7 @@ func flattenRetentionPeriod(retentionPeriod *core.RetentionPeriod) types.List {
235235
types.ObjectValueMust(
236236
getRetentionPeriodAttrTypes(),
237237
map[string]attr.Value{
238+
"strategy": types.StringValue(retentionPeriod.Strategy),
238239
"quantity_to_keep": types.Int64Value(int64(retentionPeriod.QuantityToKeep)),
239240
"should_keep_forever": types.BoolValue(retentionPeriod.ShouldKeepForever),
240241
"unit": types.StringValue(retentionPeriod.Unit),
@@ -331,21 +332,30 @@ func expandRetentionPeriod(v types.List) *core.RetentionPeriod {
331332
quantityToKeep = int32(qty.ValueInt64())
332333
}
333334

334-
var shouldKeepForever bool
335-
if keep, ok := attrs["should_keep_forever"].(types.Bool); ok && !keep.IsNull() {
336-
shouldKeepForever = keep.ValueBool()
337-
}
338-
339335
var unit string
340336
if u, ok := attrs["unit"].(types.String); ok && !u.IsNull() {
341337
unit = u.ValueString()
342338
}
343339

344-
return core.NewRetentionPeriod(quantityToKeep, unit, shouldKeepForever)
340+
var strategy string
341+
if stgy, ok := attrs["strategy"].(types.String); ok && !stgy.IsNull() && !stgy.IsUnknown() {
342+
strategy = stgy.ValueString()
343+
} else if quantityToKeep > 0 {
344+
strategy = core.RetentionStrategyCount
345+
}
346+
347+
if strategy == core.RetentionStrategyForever {
348+
return core.KeepForeverRetentionPeriod()
349+
} else if strategy == core.RetentionStrategyCount {
350+
return core.CountBasedRetentionPeriod(quantityToKeep, unit)
351+
} else {
352+
return core.SpaceDefaultRetentionPeriod()
353+
}
345354
}
346355

347356
func getRetentionPeriodAttrTypes() map[string]attr.Type {
348357
return map[string]attr.Type{
358+
"strategy": types.StringType,
349359
"quantity_to_keep": types.Int64Type,
350360
"should_keep_forever": types.BoolType,
351361
"unit": types.StringType,

0 commit comments

Comments
 (0)