mirror of
https://github.com/opentofu/opentofu.git
synced 2024-12-26 00:41:27 -06:00
terraform: fix module output handling. Fixes #474
This commit is contained in:
parent
f26b8df92f
commit
a5d444b8e3
@ -523,7 +523,7 @@ func (c *walkContext) Walk() error {
|
||||
// On Apply, we prune so that we don't do outputs if we destroyed
|
||||
mod.prune()
|
||||
}
|
||||
if len(mod.Resources) == 0 {
|
||||
if len(mod.Resources) == 0 && len(conf.Resources) != 0 {
|
||||
mod.Outputs = nil
|
||||
return nil
|
||||
}
|
||||
|
@ -913,6 +913,35 @@ func TestContextApply(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextApply_emptyModule(t *testing.T) {
|
||||
m := testModule(t, "apply-empty-module")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext(t, &ContextOpts{
|
||||
Module: m,
|
||||
Providers: map[string]ResourceProviderFactory{
|
||||
"aws": testProviderFuncFixed(p),
|
||||
},
|
||||
})
|
||||
|
||||
if _, err := ctx.Plan(nil); err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
state, err := ctx.Apply()
|
||||
if err != nil {
|
||||
t.Fatalf("err: %s", err)
|
||||
}
|
||||
|
||||
actual := strings.TrimSpace(state.String())
|
||||
actual = strings.Replace(actual, " ", "", -1)
|
||||
expected := strings.TrimSpace(testTerraformApplyEmptyModuleStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s\nexpect:\n%s", actual, expected)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContextApply_createBeforeDestroy(t *testing.T) {
|
||||
m := testModule(t, "apply-good-create-before")
|
||||
p := testProvider("aws")
|
||||
|
@ -294,12 +294,12 @@ func (m *ModuleState) GoString() string {
|
||||
}
|
||||
|
||||
func (m *ModuleState) String() string {
|
||||
if len(m.Resources) == 0 {
|
||||
return "<no state>"
|
||||
}
|
||||
|
||||
var buf bytes.Buffer
|
||||
|
||||
if len(m.Resources) == 0 {
|
||||
buf.WriteString("<no state>")
|
||||
}
|
||||
|
||||
names := make([]string, 0, len(m.Resources))
|
||||
for name, _ := range m.Resources {
|
||||
names = append(names, name)
|
||||
|
@ -164,6 +164,21 @@ aws_instance.foo:
|
||||
type = aws_instance
|
||||
`
|
||||
|
||||
const testTerraformApplyEmptyModuleStr = `
|
||||
<no state>
|
||||
Outputs:
|
||||
|
||||
end = XXXX
|
||||
|
||||
module.child:
|
||||
<no state>
|
||||
Outputs:
|
||||
|
||||
aws_access_key = YYYYY
|
||||
aws_route53_zone_id = XXXX
|
||||
aws_secret_key = ZZZZ
|
||||
`
|
||||
|
||||
const testTerraformApplyDependsCreateBeforeStr = `
|
||||
aws_instance.lb:
|
||||
ID = foo
|
||||
|
11
terraform/test-fixtures/apply-empty-module/child/main.tf
Normal file
11
terraform/test-fixtures/apply-empty-module/child/main.tf
Normal file
@ -0,0 +1,11 @@
|
||||
output "aws_route53_zone_id" {
|
||||
value = "XXXX"
|
||||
}
|
||||
|
||||
output "aws_access_key" {
|
||||
value = "YYYYY"
|
||||
}
|
||||
|
||||
output "aws_secret_key" {
|
||||
value = "ZZZZ"
|
||||
}
|
7
terraform/test-fixtures/apply-empty-module/main.tf
Normal file
7
terraform/test-fixtures/apply-empty-module/main.tf
Normal file
@ -0,0 +1,7 @@
|
||||
module "child" {
|
||||
source = "./child"
|
||||
}
|
||||
|
||||
output "end" {
|
||||
value = "${module.child.aws_route53_zone_id}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user