Skip to content

Commit f0bfb61

Browse files
committed
some clarity improvement
1 parent c77010e commit f0bfb61

File tree

3 files changed

+38
-18
lines changed

3 files changed

+38
-18
lines changed

internal/moduletest/mocking/values.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -188,7 +188,7 @@ func makeUnknown(target *configschema.Attribute, _ cty.Value, _ cty.Path) (cty.V
188188
type MockedData struct {
189189
Value cty.Value
190190
Range hcl.Range
191-
ComputedAsUnknown bool // If true, computed values are replaced with unknown.
191+
ComputedAsUnknown bool // If true, computed values are replaced with unknown, otherwise they are replaced with generated values.
192192
}
193193

194194
// NewMockedData creates a new MockedData struct with the given value and range.

internal/terraform/node_resource_abstract_instance.go

Lines changed: 32 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -909,7 +909,11 @@ func (n *NodeAbstractResourceInstance) plan(
909909
if priorVal.IsNull() {
910910
// Then we are actually creating something, so let's populate the
911911
// computed values from our override value.
912-
override, overrideDiags := mocking.PlanComputedValuesForResource(proposedNewVal, getMockedData(n.override, true), schema)
912+
override, overrideDiags := mocking.PlanComputedValuesForResource(proposedNewVal, &mocking.MockedData{
913+
Value: n.override.Values,
914+
Range: n.override.Range,
915+
ComputedAsUnknown: n.override.IgnoreValues,
916+
}, schema)
913917
resp = providers.PlanResourceChangeResponse{
914918
PlannedState: override,
915919
Diagnostics: overrideDiags,
@@ -1090,7 +1094,11 @@ func (n *NodeAbstractResourceInstance) plan(
10901094
if n.override != nil {
10911095
// In this case, we are always creating the resource so we don't
10921096
// do any validation, and just call out to the mocking library.
1093-
override, overrideDiags := mocking.PlanComputedValuesForResource(proposedNewVal, getMockedData(n.override, true), schema)
1097+
override, overrideDiags := mocking.PlanComputedValuesForResource(proposedNewVal, &mocking.MockedData{
1098+
Value: n.override.Values,
1099+
Range: n.override.Range,
1100+
ComputedAsUnknown: n.override.IgnoreValues,
1101+
}, schema)
10941102
resp = providers.PlanResourceChangeResponse{
10951103
PlannedState: override,
10961104
Diagnostics: overrideDiags,
@@ -1242,18 +1250,18 @@ func (n *NodeAbstractResourceInstance) plan(
12421250
return plan, state, deferred, keyData, diags
12431251
}
12441252

1245-
func getMockedData(override *configs.Override, isPlan bool) *mocking.MockedData {
1246-
if override == nil {
1247-
return nil
1248-
}
1249-
return &mocking.MockedData{
1250-
Value: override.Values,
1251-
Range: override.Range,
1252-
// Apply never ignores computed values. This attribute only matters
1253-
// when we are planning.
1254-
ComputedAsUnknown: override.IgnoreValues && isPlan,
1255-
}
1256-
}
1253+
// func getMockedData(override *configs.Override, isPlan bool) *mocking.MockedData {
1254+
// if override == nil {
1255+
// return nil
1256+
// }
1257+
// return &mocking.MockedData{
1258+
// Value: override.Values,
1259+
// Range: override.Range,
1260+
// // Apply never ignores computed values. This attribute only matters
1261+
// // when we are planning.
1262+
// ComputedAsUnknown: override.IgnoreValues && isPlan,
1263+
// }
1264+
// }
12571265

12581266
func (n *NodeAbstractResource) processIgnoreChanges(prior, config cty.Value, schema *configschema.Block) (cty.Value, tfdiags.Diagnostics) {
12591267
// ignore_changes only applies when an object already exists, since we
@@ -1551,7 +1559,11 @@ func (n *NodeAbstractResourceInstance) readDataSource(ctx EvalContext, configVal
15511559

15521560
var resp providers.ReadDataSourceResponse
15531561
if n.override != nil {
1554-
override, overrideDiags := mocking.ComputedValuesForDataSource(configVal, getMockedData(n.override, false), schema)
1562+
override, overrideDiags := mocking.ComputedValuesForDataSource(configVal, &mocking.MockedData{
1563+
Value: n.override.Values,
1564+
Range: n.override.Range,
1565+
ComputedAsUnknown: false,
1566+
}, schema)
15551567
resp = providers.ReadDataSourceResponse{
15561568
State: override,
15571569
Diagnostics: overrideDiags,
@@ -2506,7 +2518,11 @@ func (n *NodeAbstractResourceInstance) apply(
25062518
// values the first time the object is created. Otherwise, we're happy
25072519
// to just apply whatever the user asked for.
25082520
if change.Action == plans.Create {
2509-
override, overrideDiags := mocking.ApplyComputedValuesForResource(unmarkedAfter, getMockedData(n.override, false), schema)
2521+
override, overrideDiags := mocking.ApplyComputedValuesForResource(unmarkedAfter, &mocking.MockedData{
2522+
Value: n.override.Values,
2523+
Range: n.override.Range,
2524+
ComputedAsUnknown: false,
2525+
}, schema)
25102526
resp = providers.ApplyResourceChangeResponse{
25112527
NewState: override,
25122528
Diagnostics: overrideDiags,

internal/terraform/node_resource_plan_instance.go

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -634,7 +634,11 @@ func (n *NodePlannableResourceInstance) importState(ctx EvalContext, addr addrs.
634634

635635
// Let's pretend we're reading the value as a data source so we
636636
// pre-compute values now as if the resource has already been created.
637-
override, overrideDiags := mocking.ComputedValuesForDataSource(configVal, getMockedData(n.override, false), schema)
637+
override, overrideDiags := mocking.ComputedValuesForDataSource(configVal, &mocking.MockedData{
638+
Value: n.override.Values,
639+
Range: n.override.Range,
640+
ComputedAsUnknown: false,
641+
}, schema)
638642
resp = providers.ImportResourceStateResponse{
639643
ImportedResources: []providers.ImportedResource{
640644
{

0 commit comments

Comments
 (0)