Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The module root could not be found. There is nothing to output

Tags:

terraform

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?

like image 770
Snowcrash Avatar asked Jun 14 '17 11:06

Snowcrash


People also ask

How do I get the output module terraform?

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.

What is a root module in terraform?

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.

How do I print in terraform output?

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.

Can terraform output have multiple values?

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..


1 Answers

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.

like image 151
deepak Avatar answered Oct 05 '22 17:10

deepak