'Not a valid output for module' when using output variable with terraform

前端 未结 1 2005
北荒
北荒 2020-12-06 21:20

I\'m trying to setup some IaC for a new project using Hashicorp Terraform on AWS. I\'m using modules because I want to be able to reuse stuff across multiple environments (s

相关标签:
1条回答
  • 2020-12-06 22:18

    Outputs need to be passed up through each module explicitly each time.

    For example if you wanted to output a variable to the screen from a module nested below another module you would need something like this:

    child-module.tf

    output "child_foo" {
      value = "foobar"
    }
    

    parent-module.tf

    module "child" {
      source = "path/to/child"
    }
    
    output "parent_foo" {
      value = "${module.child.child_foo}"
    }
    

    main.tf

    module "parent" {
      source = "path/to/parent"
    }
    
    output "main_foo" {
      value = "${module.parent.parent_foo}"
    }
    
    0 讨论(0)
提交回复
热议问题