mirror of
https://github.com/opentofu/opentofu.git
synced 2025-01-24 15:36:26 -06:00
add e2e test with provider schema capabilities
enable destroy planning for the simple providers used in the e2e tests
This commit is contained in:
parent
6706d52832
commit
fd742cd544
@ -72,6 +72,16 @@ func TestProviderProtocols(t *testing.T) {
|
||||
}
|
||||
|
||||
if !strings.Contains(stdout, "Apply complete! Resources: 2 added, 0 changed, 0 destroyed.") {
|
||||
t.Fatalf("wrong output:\n%s", stdout)
|
||||
t.Fatalf("wrong output:\nstdout:%s\nstderr%s", stdout, stderr)
|
||||
}
|
||||
|
||||
/// DESTROY
|
||||
stdout, stderr, err = tf.Run("destroy", "-auto-approve")
|
||||
if err != nil {
|
||||
t.Fatalf("unexpected apply error: %s\nstderr:\n%s", err, stderr)
|
||||
}
|
||||
|
||||
if !strings.Contains(stdout, "Resources: 2 destroyed") {
|
||||
t.Fatalf("wrong destroy output\nstdout:%s\nstderr:%s", stdout, stderr)
|
||||
}
|
||||
}
|
||||
|
@ -59,6 +59,10 @@ func (p *provider) GetSchema(_ context.Context, req *tfplugin5.GetProviderSchema
|
||||
}
|
||||
}
|
||||
|
||||
resp.Capabilities = &tfplugin5.GetProviderSchema_Capabilities{
|
||||
PlanDestroy: p.schema.Capabilities.PlanDestroy,
|
||||
}
|
||||
|
||||
// include any diagnostics from the original GetSchema call
|
||||
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, p.schema.Diagnostics)
|
||||
|
||||
|
@ -59,6 +59,10 @@ func (p *provider6) GetProviderSchema(_ context.Context, req *tfplugin6.GetProvi
|
||||
}
|
||||
}
|
||||
|
||||
resp.Capabilities = &tfplugin6.GetProviderSchema_Capabilities{
|
||||
PlanDestroy: p.schema.Capabilities.PlanDestroy,
|
||||
}
|
||||
|
||||
// include any diagnostics from the original GetSchema call
|
||||
resp.Diagnostics = convert.AppendProtoDiag(resp.Diagnostics, p.schema.Diagnostics)
|
||||
|
||||
|
@ -3,6 +3,7 @@ package simple
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"time"
|
||||
|
||||
"github.com/hashicorp/terraform/internal/configs/configschema"
|
||||
@ -42,6 +43,9 @@ func Provider() providers.Interface {
|
||||
DataSources: map[string]providers.Schema{
|
||||
"simple_resource": simpleResource,
|
||||
},
|
||||
Capabilities: providers.Capabilities{
|
||||
PlanDestroy: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
@ -88,7 +92,10 @@ func (s simple) PlanResourceChange(req providers.PlanResourceChangeRequest) (res
|
||||
if req.ProposedNewState.IsNull() {
|
||||
// destroy op
|
||||
resp.PlannedState = req.ProposedNewState
|
||||
resp.PlannedPrivate = req.PriorPrivate
|
||||
|
||||
// signal that this resource was properly planned for destruction,
|
||||
// verifying that the schema capabilities with PlanDestroy took effect.
|
||||
resp.PlannedPrivate = []byte("destroy planned")
|
||||
return resp
|
||||
}
|
||||
|
||||
@ -104,6 +111,11 @@ func (s simple) PlanResourceChange(req providers.PlanResourceChangeRequest) (res
|
||||
|
||||
func (s simple) ApplyResourceChange(req providers.ApplyResourceChangeRequest) (resp providers.ApplyResourceChangeResponse) {
|
||||
if req.PlannedState.IsNull() {
|
||||
// make sure this was transferred from the plan action
|
||||
if string(req.PlannedPrivate) != "destroy planned" {
|
||||
resp.Diagnostics = resp.Diagnostics.Append(fmt.Errorf("resource not planned for destroy, private data %q", req.PlannedPrivate))
|
||||
}
|
||||
|
||||
resp.NewState = req.PlannedState
|
||||
return resp
|
||||
}
|
||||
|
@ -42,6 +42,9 @@ func Provider() providers.Interface {
|
||||
DataSources: map[string]providers.Schema{
|
||||
"simple_resource": simpleResource,
|
||||
},
|
||||
Capabilities: providers.Capabilities{
|
||||
PlanDestroy: true,
|
||||
},
|
||||
},
|
||||
}
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user