mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
Merge pull request #1017 from hashicorp/b-module-input-bool
terraform: module inputs/vars can be non-strings [GH-819]
This commit is contained in:
commit
b45701b3dd
@ -3298,6 +3298,35 @@ func TestContext2Apply_moduleVarResourceCount(t *testing.T) {
|
||||
}
|
||||
}
|
||||
|
||||
// GH-819
|
||||
func TestContext2Apply_moduleBool(t *testing.T) {
|
||||
m := testModule(t, "apply-module-bool")
|
||||
p := testProvider("aws")
|
||||
p.ApplyFn = testApplyFn
|
||||
p.DiffFn = testDiffFn
|
||||
ctx := testContext2(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())
|
||||
expected := strings.TrimSpace(testTerraformApplyModuleBoolStr)
|
||||
if actual != expected {
|
||||
t.Fatalf("bad: \n%s", actual)
|
||||
}
|
||||
}
|
||||
|
||||
func TestContext2Apply_multiProvider(t *testing.T) {
|
||||
m := testModule(t, "apply-multi-provider")
|
||||
p := testProvider("aws")
|
||||
|
@ -1,7 +1,11 @@
|
||||
package terraform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
|
||||
"github.com/hashicorp/errwrap"
|
||||
"github.com/hashicorp/terraform/config"
|
||||
"github.com/mitchellh/mapstructure"
|
||||
)
|
||||
|
||||
// EvalSetVariables is an EvalNode implementation that sets the variables
|
||||
@ -34,7 +38,13 @@ func (n *EvalVariableBlock) Eval(ctx EvalContext) (interface{}, error) {
|
||||
// Get our configuration
|
||||
rc := *n.Config
|
||||
for k, v := range rc.Config {
|
||||
n.Variables[k] = v.(string)
|
||||
var vStr string
|
||||
if err := mapstructure.WeakDecode(v, &vStr); err != nil {
|
||||
return nil, errwrap.Wrapf(fmt.Sprintf(
|
||||
"%s: error reading value: {{err}}", k), err)
|
||||
}
|
||||
|
||||
n.Variables[k] = vStr
|
||||
}
|
||||
for k, _ := range rc.Raw {
|
||||
if _, ok := n.Variables[k]; !ok {
|
||||
|
@ -231,7 +231,12 @@ func (s *State) String() string {
|
||||
|
||||
s := bufio.NewScanner(strings.NewReader(mStr))
|
||||
for s.Scan() {
|
||||
buf.WriteString(fmt.Sprintf(" %s\n", s.Text()))
|
||||
text := s.Text()
|
||||
if text != "" {
|
||||
text = " " + text
|
||||
}
|
||||
|
||||
buf.WriteString(fmt.Sprintf("%s\n", text))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -285,6 +285,22 @@ module.child:
|
||||
type = aws_instance
|
||||
`
|
||||
|
||||
const testTerraformApplyModuleBoolStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
foo = 1
|
||||
type = aws_instance
|
||||
|
||||
Dependencies:
|
||||
module.child
|
||||
|
||||
module.child:
|
||||
<no state>
|
||||
Outputs:
|
||||
|
||||
leader = 1
|
||||
`
|
||||
|
||||
const testTerraformApplyMultiProviderStr = `
|
||||
aws_instance.bar:
|
||||
ID = foo
|
||||
|
7
terraform/test-fixtures/apply-module-bool/child/main.tf
Normal file
7
terraform/test-fixtures/apply-module-bool/child/main.tf
Normal file
@ -0,0 +1,7 @@
|
||||
variable "leader" {
|
||||
default = false
|
||||
}
|
||||
|
||||
output "leader" {
|
||||
value = "${var.leader}"
|
||||
}
|
8
terraform/test-fixtures/apply-module-bool/main.tf
Normal file
8
terraform/test-fixtures/apply-module-bool/main.tf
Normal file
@ -0,0 +1,8 @@
|
||||
module "child" {
|
||||
source = "./child"
|
||||
leader = true
|
||||
}
|
||||
|
||||
resource "aws_instance" "bar" {
|
||||
foo = "${module.child.leader}"
|
||||
}
|
Loading…
Reference in New Issue
Block a user