Reputation: 45
I have a outputs.tf
file under my module directory. And I have a Main.tf
file. When I create a resource and Terraform Apply, the outputs does not display. However, if I don't use modules and create my resources strictly from the Main.tf
file, the outputs shows fine. Is there any different I need to do for my outputs to display when using modules and a separate outputs.tf
file?
Terraform v0.11.14
+ provider.aws v2.19.0
However, if I don't use modules and create my resources strictly from the Main.tf
file, the outputs shows fine.
module "identity-provider" {
source = "./modules/identity-provider"
}
module "saml-role1" {
source = "./modules/saml-roles/"
}
===============
resource "aws_iam_role" "role1" {
name = "saml-role1"
description = "Blah Blah"
path = "/"
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
permissions_boundary = ""
max_session_duration = 43200
resource "aws_iam_role_policy_attachment" "Read-Only" {
role = "${aws_iam_role.role1.name}"
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
=================
output "Role1-ARN" {
value = "${module.saml-role1.arn}"
}
Upvotes: 2
Views: 4163
Reputation: 634
You also need an another output.tf file along with your main.tf file to capture the output from your module.
Below is the content of the output.tf file.
output "Role1-ARN" {
value = "${module.saml-role1.Role1-ARN}"
}
Upvotes: 0
Reputation: 1619
When you are keeping 'count' variable in your module, then you need to use * in outputs.tf file.
Example:
output "Role1-ARN" {
value = "${module.saml-role1.*.Role1-ARN}"
}
Upvotes: 0
Reputation: 1103
Only the outputs of the root module are captured and displayed by Terraform. If you need to pass outputs from a module to the root module you have to do it explicitly (e.g. you do not have access to all the resources created by a module from the root ONLY the values specified as outputs). If you include an output in your module file like this:
resource "aws_iam_role" "role1" {
name = "saml-role1"
description = "Blah Blah"
path = "/"
assume_role_policy = "${data.aws_iam_policy_document.assume_role.json}"
permissions_boundary = ""
max_session_duration = 43200
resource "aws_iam_role_policy_attachment" "Read-Only" {
role = "${aws_iam_role.role1.name}"
policy_arn = "arn:aws:iam::aws:policy/ReadOnlyAccess"
}
output "saml-role1-arn" {
value = "aws_iam_role.role1.arn"
}
Then from within the root module you can access the output:
module "saml-role1" {
source = "./modules/saml-roles/"
}
output "saml-role1-arn" {
value = "${module.saml-role1.saml-role1-arn}"
}
Upvotes: 6