For a special workflow, I need to apply a specific module with terraform apply -target=module.<mymodule>. Then, I need to get the outputs from this module with terraform output -module=<mymodule>. This works correctly for outputs that are computed from a resource, but does not output anything for static strings until a general terraform apply has been run.
I have a very simple reproduction below.
Terraform v0.11.14
main.tf:
module "test" {
source = "./mod"
}
mod/main.tf
output "mod-output" {
value = "123"
}
Module output should have been displayed.
Static outputs are not shown.
$ terraform init
Initializing modules...
- module.test
Getting source "./mod"
Terraform has been successfully initialized!
You may now begin working with Terraform. Try running "terraform plan" to see
any changes that are required for your infrastructure. All Terraform commands
should now work.
If you ever set or change modules or backend configuration for Terraform,
rerun this command to reinitialize your working directory. If you forget, other
commands will detect it and remind you to do so if necessary.
$ terraform apply -target=module.test
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
$ terraform output -module=test
The module root.test could not be found. There is nothing to output.
$ terraform apply
Apply complete! Resources: 0 added, 0 changed, 0 destroyed.
$ terraform output -module=test
mod-output = 123
We face same issue... Is there any schedule when we can expect this bug to be fixed?
I encountered this on Terraform v0.12.20. It seems somewhat related to #23073. In all of these cases, I've been able to have the outputs populated (or repopulated back) into state after the apply with "-target" by running terraform refresh. That doesn't seem ideal but at least it provides a way to get the missing outputs into state without having to do a full apply (without "-target" arguments).
Still present in Terraform v0.13.4
Most helpful comment
I encountered this on Terraform v0.12.20. It seems somewhat related to #23073. In all of these cases, I've been able to have the outputs populated (or repopulated back) into state after the apply with "-target" by running
terraform refresh. That doesn't seem ideal but at least it provides a way to get the missing outputs into state without having to do a full apply (without "-target" arguments).