Skip to content

Commit 6d00406

Browse files
committed
fix: because terraform validates too early we are forced to put known/unknown validation in ModifyPlan
1 parent ed856c1 commit 6d00406

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

internal/fwkprovider/path_exists.go

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@ package fwkprovider
33
import (
44
"context"
55
"os"
6-
"strconv"
76

87
"github.com/pseudo-dynamic/terraform-provider-value/internal/fwkproviderconfig"
98
"github.com/pseudo-dynamic/terraform-provider-value/internal/goproviderconfig"
@@ -63,9 +62,6 @@ func (r pathExistsResource) GetSchema(_ context.Context) (tfsdk.Schema, diag.Dia
6362
Type: types.StringType,
6463
Required: true,
6564
Description: goproviderconfig.GetGuidSeedAttributeDescription(pathExistsResourceName),
66-
Validators: []tfsdk.AttributeValidator{
67-
&fwkproviderconfig.PlanKnownValidator{},
68-
},
6965
},
7066
"exists": {
7167
Type: types.BoolType,
@@ -105,6 +101,10 @@ func (r *pathExistsResource) ModifyPlan(ctx context.Context, req resource.Modify
105101
suppliedGuidSeed := config.GuidSeed.Value
106102
isPlanPhase := config.ProposedUnknown.IsUnknown()
107103

104+
if !fwkproviderconfig.ValidatePlanKnownString(config.GuidSeed, "guid_seed", &resp.Diagnostics) {
105+
return
106+
}
107+
108108
var providerMetaSeedAddition string
109109
var isSuccessful bool
110110
if providerMetaSeedAddition, _, isSuccessful = goproviderconfig.TryUnmarshalValueThenExtractGuidSeedAddition(&req.ProviderMeta.Raw); !isSuccessful {
@@ -139,8 +139,6 @@ func (r *pathExistsResource) ModifyPlan(ctx context.Context, req resource.Modify
139139
return
140140
}
141141

142-
resp.Diagnostics.AddWarning("Exists (cached) is unknown: "+strconv.FormatBool(cachedExists.Unknown), "")
143-
144142
config.Exists = cachedExists
145143
resp.Plan.Set(ctx, &config)
146144
}

internal/fwkproviderconfig/attribute_validator_plan_known.go

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,11 +3,25 @@ package fwkproviderconfig
33
import (
44
"context"
55

6+
"github.com/hashicorp/terraform-plugin-framework/diag"
67
"github.com/hashicorp/terraform-plugin-framework/tfsdk"
8+
"github.com/hashicorp/terraform-plugin-framework/types"
79
)
810

911
type PlanKnownValidator struct{}
1012

13+
func ValidatePlanKnownString(value types.String, attributeName string, diags *diag.Diagnostics) bool {
14+
if value.IsUnknown() {
15+
diags.AddError(
16+
attributeName+" is unknown",
17+
attributeName+" must be fully known at plan-time. For further informations take a look into the documentation.")
18+
19+
return false
20+
}
21+
22+
return true
23+
}
24+
1125
func (v *PlanKnownValidator) Validate(ctx context.Context, req tfsdk.ValidateAttributeRequest, resp *tfsdk.ValidateAttributeResponse) {
1226
if req.AttributeConfig != nil && req.AttributeConfig.IsUnknown() {
1327
resp.Diagnostics.AddError(

0 commit comments

Comments
 (0)