Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

the destroy plan should use correct type #32988

Merged
merged 1 commit into from
Apr 6, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion internal/terraform/node_resource_abstract_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -440,7 +440,7 @@ func (n *NodeAbstractResourceInstance) planDestroy(ctx EvalContext, currentState
Change: plans.Change{
Action: plans.Delete,
Before: currentState.Value,
After: cty.NullVal(cty.DynamicPseudoType),
After: nullVal,
},
Private: resp.PlannedPrivate,
ProviderAddr: n.ResolvedProvider,
Expand Down
16 changes: 2 additions & 14 deletions internal/terraform/provider_mock.go
Original file line number Diff line number Diff line change
Expand Up @@ -435,28 +435,16 @@ func (p *MockProvider) ApplyResourceChange(r providers.ApplyResourceChangeReques
return *p.ApplyResourceChangeResponse
}

schema, ok := p.getProviderSchema().ResourceTypes[r.TypeName]
if !ok {
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("no schema found for %q", r.TypeName))
return resp
}

// if the value is nil, we return that directly to correspond to a delete
if r.PlannedState.IsNull() {
resp.NewState = cty.NullVal(schema.Block.ImpliedType())
return resp
}

val, err := schema.Block.CoerceValue(r.PlannedState)
if err != nil {
resp.Diagnostics = resp.Diagnostics.Append(err)
resp.NewState = r.PlannedState
return resp
}

// the default behavior will be to create the minimal valid apply value by
// setting unknowns (which correspond to computed attributes) to a zero
// value.
val, _ = cty.Transform(val, func(path cty.Path, v cty.Value) (cty.Value, error) {
val, _ := cty.Transform(r.PlannedState, func(path cty.Path, v cty.Value) (cty.Value, error) {
if !v.IsKnown() {
ty := v.Type()
switch {
Expand Down