mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-25 08:21:07 -06:00
terraform: Test provisioner apply
This commit is contained in:
parent
03a20f072e
commit
cfc7b69bb1
@ -339,6 +339,48 @@ func TestContextApply_compute(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextApply_Provisioner_compute(t *testing.T) {
|
||||
c := testConfig(t, "apply-provisioner-compute")
|
||||
p := testProvider("aws")
|
||||
pr := testProvisioner()
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
pr.ApplyFn = func(rs *ResourceState, c *ResourceConfig) (*ResourceState, error) {
|
||||
return rs, nil
|
||||
}
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Config: c,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
Provisioners: map[string]ResourceProvisionerFactory{
|
||||
"shell": testProvisionerFuncFixed(pr),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(nil); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
ctx.variables = map[string]string{"value": "1"}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
expected := strings.TrimSpace(testTerraformApplyProvisionerStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
|
||||
// Verify apply was invoked
|
||||
if !pr.ApplyCalled {
|
||||
t.Fatalf("provisioner not invoked")
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextApply_destroy(t *testing.T) {
|
||||
c := testConfig(t, "apply-destroy")
|
||||
h := new(HookRecordApplyOrder)
|
||||
|
@ -120,6 +120,16 @@ aws_instance.foo:
|
||||
ID = foo
|
||||
`
|
||||
|
||||
const testTerraformApplyProvisionerStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
aws_instance.foo:
|
||||
ID = foo
|
||||
dynamical = computed_dynamical
|
||||
num = 2
|
||||
type = aws_instance
|
||||
`
|
||||
|
||||
const testTerraformApplyDestroyStr = `
|
||||
<no state>
|
||||
`
|
||||
|
11
terraform/test-fixtures/apply-provisioner-compute/main.tf
Normal file
11
terraform/test-fixtures/apply-provisioner-compute/main.tf
Normal file
@ -0,0 +1,11 @@
|
||||
resource "aws_instance" "foo" {
|
||||
num = "2"
|
||||
compute = "dynamical"
|
||||
compute_value = "${var.value}"
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
provisioner "shell" {
|
||||
foo = "${aws_instance.foo.dynamical}"
|
||||
}
|
||||
}
|
Loading…
Reference in New Issue
Block a user