Terraform version 0.8.3
Running on OSX 0.12.1
The following code in a module to output the IP address of an EIP in AWS , which was working fine in 0.7.7, has stopped working in the version above.
output "pub_ip_address" {
value = "${aws_eip.lb.public_ip}"
}
The module loads fine when you run "terraform get". Also when "terraform apply" is run , there are no errors, but the output does not get displayed.
When you try to output the variable with "Terraform output pub_ip_address" , you get the following message.
The state file has no outputs defined. Define an output
in your configuration with the "output" directive and re-run
"terraform apply" for it to become available.
However when you look at the state file, the output is clearly there.
"outputs": {
"pub_ip_address": {
"sensitive": false,
"type": "string",
"value": "192.168.1.1"
},
Hi @codfather, thanks for the issue!
Terraform outputs need to be scoped to the root module, unless the -module flag is passed to output. Documentation: https://www.terraform.io/docs/commands/output.html
See the following example config:
$ tree
.
โโโ fooModule
โย ย โโโ main.tf
โโโ main.tf
main.tf:
variable "test" { default = "test" }
module "foo" {
source = "./fooModule"
}
fooModule/main.tf:
variable "foo" { default = "bar" }
output "fooOutput" { value = "${var.foo}" }
$ terraform output fooOutput
The state file has no outputs defined. Define an output
in your configuration with the `output` directive and re-run
`terraform apply` for it to become available.
$ terraform output -module=foo fooOutput
bar
If you pass the output up to the main module like so:
# main.tf
module "foo" {
source = "./fooModule"
}
output "fooMain" { value = "${module.foo.fooOutput}" }
Then the output is correctly displayed at the root modules scope:
$ terraform output fooMain
bar
Please let me know if you're seeing different behavior though! Thanks.
Thanks for the reply. Indeed your suggestion worked perfectly.
I was not aware of the -module parameter for the output command.
I have refactored my code with your suggestion.
Cheers
I'm going to lock this issue because it has been closed for _30 days_ โณ. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.
Most helpful comment
Hi @codfather, thanks for the issue!
Terraform outputs need to be scoped to the root module, unless the
-moduleflag is passed tooutput. Documentation: https://www.terraform.io/docs/commands/output.htmlSee the following example config:
main.tf:fooModule/main.tf:If you pass the output up to the main module like so:
Then the output is correctly displayed at the root modules scope:
Please let me know if you're seeing different behavior though! Thanks.