Skip to content

Commit 8e19a30

Browse files
Fix: retentionPolicyValidator on isUnknown state (#37)
* remove unused function * skip lifecycle validation if IsUnknown() --------- Co-authored-by: Tiago Carreira <[email protected]>
1 parent cc1c90d commit 8e19a30

File tree

2 files changed

+4
-14
lines changed

2 files changed

+4
-14
lines changed

octopusdeploy_framework/resource_lifecycle.go

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -187,17 +187,6 @@ func resourceConfiguration(req resource.ConfigureRequest, resp *resource.Configu
187187

188188
return p
189189
}
190-
func setDefaultRetentionPolicies(data *lifecycleTypeResourceModel) {
191-
defaultPolicy := flattenRetentionPeriod(core.NewRetentionPeriod(30, "Days", false))
192-
193-
if data.ReleaseRetentionPolicy.IsNull() || len(data.ReleaseRetentionPolicy.Elements()) == 0 {
194-
data.ReleaseRetentionPolicy = defaultPolicy
195-
}
196-
197-
if data.TentacleRetentionPolicy.IsNull() || len(data.TentacleRetentionPolicy.Elements()) == 0 {
198-
data.TentacleRetentionPolicy = defaultPolicy
199-
}
200-
}
201190

202191
func flattenLifecycleResource(lifecycle *lifecycles.Lifecycle) *lifecycleTypeResourceModel {
203192
flattenedLifecycle := &lifecycleTypeResourceModel{

octopusdeploy_framework/schemas/lifecycle.go

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,8 @@ package schemas
22

33
import (
44
"context"
5+
"strings"
6+
57
"github.com/OctopusDeploy/terraform-provider-octopusdeploy/octopusdeploy_framework/util"
68
"github.com/hashicorp/terraform-plugin-framework-validators/int64validator"
79
datasourceSchema "github.com/hashicorp/terraform-plugin-framework/datasource/schema"
@@ -16,7 +18,6 @@ import (
1618
"github.com/hashicorp/terraform-plugin-framework/schema/validator"
1719
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
1820
"github.com/hashicorp/terraform-plugin-framework/types"
19-
"strings"
2021
)
2122

2223
var _ EntitySchema = LifecycleSchema{}
@@ -205,7 +206,7 @@ func (v retentionPolicyValidator) ValidateObject(ctx context.Context, req valida
205206
return
206207
}
207208

208-
if !retentionPolicy.QuantityToKeep.IsNull() && !retentionPolicy.ShouldKeepForever.IsNull() {
209+
if !retentionPolicy.QuantityToKeep.IsNull() && !retentionPolicy.QuantityToKeep.IsUnknown() && !retentionPolicy.ShouldKeepForever.IsNull() && !retentionPolicy.ShouldKeepForever.IsUnknown() {
209210
quantityToKeep := retentionPolicy.QuantityToKeep.ValueInt64()
210211
shouldKeepForever := retentionPolicy.ShouldKeepForever.ValueBool()
211212

@@ -224,7 +225,7 @@ func (v retentionPolicyValidator) ValidateObject(ctx context.Context, req valida
224225
}
225226
}
226227

227-
if !retentionPolicy.Unit.IsNull() {
228+
if !retentionPolicy.Unit.IsNull() && !retentionPolicy.Unit.IsUnknown() {
228229
unit := retentionPolicy.Unit.ValueString()
229230
if !strings.EqualFold(unit, "Days") && !strings.EqualFold(unit, "Items") {
230231
resp.Diagnostics.AddAttributeError(

0 commit comments

Comments
 (0)