mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
terraform: test provising fail create-before-destroy
This commit is contained in:
parent
4fe05428b3
commit
f248ae3aee
@ -880,6 +880,61 @@ func TestContextApply_provisionerFail(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextApply_provisionerFail_createBeforeDestroy(t *testing.T) {
|
||||
c := testConfig(t, "apply-provisioner-fail-create-before")
|
||||
p := testProvider("aws")
|
||||
pr := testProvisioner()
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
pr.ApplyFn = func(*InstanceState, *ResourceConfig) error {
|
||||
return fmt.Errorf("EXPLOSION")
|
||||
}
|
||||
|
||||
state := &State{
|
||||
Modules: []*ModuleState{
|
||||
&ModuleState{
|
||||
Path: rootModulePath,
|
||||
Resources: map[string]*ResourceState{
|
||||
"aws_instance.bar": &ResourceState{
|
||||
Type: "aws_instance",
|
||||
Primary: &InstanceState{
|
||||
ID: "bar",
|
||||
Attributes: map[string]string{
|
||||
"require_new": "abc",
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
},
|
||||
}
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Config: c,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ResourceProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
},
|
||||
State: state,
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(nil); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err == nil {
|
||||
t.Fatal("should error")
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
expected := strings.TrimSpace(testTerraformApplyProvisionerFailCreateBeforeDestroyStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextApply_provisionerResourceRef(t *testing.T) {
|
||||
m := testModule(t, "apply-provisioner-resource-ref")
|
||||
p := testProvider("aws")
|
||||
@ -3121,6 +3176,9 @@ func testDiffFn(
|
||||
New: v.(string),
|
||||
}
|
||||
|
||||
if k == "require_new" {
|
||||
attrDiff.RequiresNew = true
|
||||
}
|
||||
diff.Attributes[k] = attrDiff
|
||||
}
|
||||
|
||||
|
@ -218,6 +218,13 @@ aws_instance.foo:
|
||||
type = aws_instance
|
||||
`
|
||||
|
||||
const testTerraformApplyProvisionerFailCreateBeforeDestroyStr = `
|
||||
aws_instance.bar: (1 tainted)
|
||||
ID = bar
|
||||
require_new = abc
|
||||
Tainted ID 1 = foo
|
||||
`
|
||||
|
||||
const testTerraformApplyProvisionerResourceRefStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
|
@ -0,0 +1,7 @@
|
||||
resource "aws_instance" "bar" {
|
||||
require_new = "xyz"
|
||||
provisioner "shell" {}
|
||||
lifecycle {
|
||||
create_before_destroy = true
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user