Skip to content

Commit

Permalink
address comments
Browse files Browse the repository at this point in the history
  • Loading branch information
dsa0x committed Jan 8, 2025
1 parent 12ace9d commit d29ae92
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 9 deletions.
12 changes: 4 additions & 8 deletions internal/configs/mock_provider.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,9 @@ type MockData struct {
MockDataSources map[string]*MockResource
Overrides addrs.Map[addrs.Targetable, *Override]

useForPlan *bool // If true, the mock data can be used for planning.
}

// UseForPlan returns true if the provider-level setting for overrideComputed
// is true, meaning that computed values can be overridden with the mocked values.
func (data *MockData) UseForPlan() bool {
return data.useForPlan != nil && *data.useForPlan
// UseForPlan returns true if the provider-level setting for overrideComputed
// is true, meaning that computed values can be overridden with the mocked values during planning.
UseForPlan bool
}

// Merge will merge the target MockData object into the current MockData.
Expand Down Expand Up @@ -242,7 +238,7 @@ func decodeMockDataBody(body hcl.Body, source OverrideSource) (*MockData, hcl.Di
MockResources: make(map[string]*MockResource),
MockDataSources: make(map[string]*MockResource),
Overrides: addrs.MakeMap[addrs.Targetable, *Override](),
useForPlan: &useForPlan,
UseForPlan: useForPlan,
}

for _, block := range content.Blocks {
Expand Down
2 changes: 1 addition & 1 deletion internal/providers/mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,7 @@ func (m *Mock) PlanResourceChange(request PlanResourceChangeRequest) PlanResourc
ComputedAsUnknown: true,
}
// if we are allowed to use the mock defaults for plan, we can populate the computed fields with the mock defaults.
if mockedResource, exists := m.Data.MockResources[request.TypeName]; exists && m.Data.UseForPlan() {
if mockedResource, exists := m.Data.MockResources[request.TypeName]; exists && m.Data.UseForPlan {
replacement.Value = mockedResource.Defaults
replacement.Range = mockedResource.DefaultsRange
replacement.ComputedAsUnknown = false
Expand Down

0 comments on commit d29ae92

Please sign in to comment.