Running a terraform output
in my root Terraform directory I get:
The module root could not be found. There is nothing to output.
I have the following files:
iam.tf
:
resource "aws_iam_user" "a_user" {
name = "a_user"
}
output.tf
:
data "aws_caller_identity" "current" {}
output "account_id" {
value = "${data.aws_caller_identity.current.account_id}"
}
This https://www.terraform.io/docs/modules/index.html says:
Root module That is the current working directory when you run terraform apply or get, holding the Terraform configuration files. It is itself a valid module.
Any idea why the error message and how to fix?
Outputs from child modules are not displayed as outputs in the main module. You need to explicitly create outputs in the main module if you want to output any child module outputs. Run your Terraform init , plan , and apply commands again. The root module outputs the results of the child modules.
A Terraform module is a set of Terraform configuration files in a single directory. Even a simple configuration consisting of a single directory with one or more .tf files is a module. When you run Terraform commands directly from such a directory, it is considered the root module.
The terraform output command by default displays in a human-readable format, which can change over time to improve clarity. For the common case of directly using a string value in a shell script, you can use -raw instead, which will print the string directly with no extra escaping or whitespace.
You can have multiple resources in a single output, but to make it work, you need to use some terraform function, or format the output depending on the type, if it is a list, string, map..
Terraform refers root module
from terraform.tfstate
file.
This file conatains all info about your last known state from .tf
files along with output variables
.
Which is generated after first execution terraform apply
command into current directory.
Simply run terraform apply
, then terraform output
will shows your output variables.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With