adding outputs to off-the-shelf module

254 views
Skip to first unread message

Sean Hull

unread,
Apr 23, 2018, 10:31:09 PM4/23/18
to Terraform

If I source someone elses github terraform module.  One I don't have control over.   Do I depend on outputs the AUTHOR included in their source?  Or can I add new outputs as long as I reference their names properly?


Because I keep getting this:



Error: output 'i_hate_terraform': "aws_subnet.private.id" is not a valid output for module "bastion_vpc_template"


And when I reference an output that *was* defined I still get crap:


Error: output 'i_hate_terraform': "aws_vpc.id" is not a valid output for module "bastion_vpc_template"


Please lord god, save my soul!


ja...@fpcomplete.com

unread,
Apr 24, 2018, 1:14:29 AM4/24/18
to Terraform
Hi Sean,

I can understand the frustrations, it can take a little while to get used to Terraform and HCL, but I believe it's worth it. YMMV.

No, you cannot add outputs to off-the-shelf modules, but when in that situation, you could:

1) fork and send a PR to the module maintainer, or 
2) fork, fix the issue, and use your forked module sourced by git ref
3) write your own module
4) use another module
If you would like help with errors like this, I would recommend posting a gist of your code, or referencing that in some way so people can see it and help locate the issue that way (it's harder with error messages alone).

Goodluck!

⁞ Fernando Miguel

unread,
Apr 24, 2018, 1:40:22 AM4/24/18
to terrafo...@googlegroups.com
You depend on the outputs that the module provides 

If you need to modify it, fork it (and consider upstream the improvement) 

--
Fernando Miguel

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/129c086f-e5b8-47ab-8388-34059068f8ea%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Sean Hull

unread,
Apr 24, 2018, 10:55:09 AM4/24/18
to terrafo...@googlegroups.com

Thank you Fernando.

I designed a very simple example to show my problem:

1. I create a module & commit to git. (dogstartest.git below)
2. I include the module & create an instance  (rolling_stones below)
3. I do "terraform refresh"
4. I do "terraform output" but nothing is showing.

Thoughts?


Here's my repo.  It just contains this one "test.tf"

provider "aws" {
    region = "us-east-1"
}


resource "aws_instance" "omg" {
  ami           = "ami-1853ac65"
  instance_type = "t2.micro"
  subnet_id = "subnet-1f866434"
}

output "a_working_subnet" {
  value = "aws_instance.omg.subnet_id"
}

Here's how I call it in a module:
module rolling_stones {
  source = "g...@github.com:hullsean/dogstartest.git"

}

And you can see there are no outputs:

module.rolling_stones.aws_instance.omg: Still creating... (20s elapsed)
module.rolling_stones.aws_instance.omg: Creation complete after 23s (ID: i-0821e7d9edc1d2adf)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.
levanter:tftest2 sean[seancli]$ terraform output
The state file either has no outputs defined, or all the defined
outputs are empty. Please define an output in your configuration
with the `output` keyword and run `terraform refresh` for it to
become available. If you are using interpolation, please verify
the interpolated value is not empty. You can use the 
`terraform console` command to assist.
levanter:tftest2 sean[seancli]$ terraform refresh
aws_instance.omg: Refreshing state... (ID: i-0821e7d9edc1d2adf)
levanter:tftest2 sean[seancli]$ terraform output
The state file either has no outputs defined, or all the defined
outputs are empty. Please define an output in your configuration
with the `output` keyword and run `terraform refresh` for it to
become available. If you are using interpolation, please verify
the interpolated value is not empty. You can use the 
`terraform console` command to assist.
levanter:tftest2 sean[seancli]$ terraform --version
Terraform v0.11.7
+ provider.aws v1.15.0

levanter:tftest2 sean[seancli]$ 


Sean Hull :: Devops. Data. Innovation.

⁞ Fernando Miguel

unread,
Apr 24, 2018, 11:09:30 AM4/24/18
to terrafo...@googlegroups.com
you need to create your own outputs of the outputs that exist in the module
something like

output "app_ms1_sg_security_group_id" {
description = "The ID of the security group"
value = "${module.app_ms1_sg.this_security_group_id}"
}


-- 

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/3C3146E5-A082-49EE-8426-980DAF3AB356%40gmail.com.

Sean Hull

unread,
Apr 24, 2018, 11:20:04 AM4/24/18
to terrafo...@googlegroups.com

Thx Fernando.  

I tried this:

output "mick_jagger" {
  value       = "${module.rolling_stones.a_working_subnet}"
}

And I get this error:

levanter:tftest2 sean[seancli]$ terraform refresh

Error: output 'mick_jagger': "a_working_subnet" is not a valid output for module "rolling_stones"

I tried this:

output "mick_jagger" {
  value       = "${module.rolling_stones.aws_instance.omg.subnet_id}"
}

Got this error:

levanter:tftest2 sean[seancli]$ terraform refresh

Error: output 'mick_jagger': "aws_instance.omg.subnet_id" is not a valid output for module "rolling_stones"





Sean Hull :: Devops. Data. Innovation.

⁞ Fernando Miguel

unread,
Apr 24, 2018, 11:24:19 AM4/24/18
to terrafo...@googlegroups.com
no idea why you are running refresh...
you should run `apply`

also,
module.NAME_OF_YOUR_MODULE.NAME_OF_THE_OUTPUT_INSIDE_THE_MODULE

-- 

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.

Sean Hull

unread,
Apr 24, 2018, 11:51:59 AM4/24/18
to terrafo...@googlegroups.com


When I get the module wrong I see this error:

Error: output 'mick_jagger': reference to undefined module "dogstartest"


However when I specify the module properly I get this error:

Error: output 'mick_jagger': "a_working_subnet" is not a valid output for module "rolling_stones"

You can see the output defined in the git repo here:


It looks like this:
output "a_working_subnet" {
  value = "${aws_instance.omg.subnet_id}"
}

I've been going around & around with this for 20 hours.  :( 

My *OUTPUT* of an output looks like this:

output "mick_jagger" {
  value       = "${module.rolling_stones.a_working_subnet}"
}

So I have given my output the name "mick_jagger", it references my module caled "rolling_stones" which further references the output a_working_subnet" which is clearly specified.

This is so odd!
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAM7yfUBawaFxJX1OWFG4U5xdXZvXRDARVTU54%2BkqZT5yoCQgBQ%40mail.gmail.com.

Sean Hull

unread,
Apr 24, 2018, 11:56:18 AM4/24/18
to terrafo...@googlegroups.com

And thank you for helping me Fernando.   I checked "name of module", "name of output" a hundred times.  This is so weird.

-Sean



Sean Hull :: Devops. Data. Innovation.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAM7yfUBawaFxJX1OWFG4U5xdXZvXRDARVTU54%2BkqZT5yoCQgBQ%40mail.gmail.com.

Fernando

unread,
Apr 24, 2018, 12:02:23 PM4/24/18
to Terraform
if you show us the output.tf in the module, we can more easily help you build the output in your state

Sean Hull

unread,
Apr 24, 2018, 12:07:50 PM4/24/18
to terrafo...@googlegroups.com


Here's the test.tf from the git repo.  Note I changed output to "seanoutput":
provider "aws" {
    region = "us-east-1"
}

resource "aws_instance" "omg" {
  ami           = "ami-1853ac65"
  instance_type = "t2.micro"
  subnet_id = "subnet-1f866434"
}

output "seanoutput" {
  value = "${aws_instance.omg.subnet_id}"
}
This is my main.tf that I'm trying to build:

module rolling_stones {
  source = "g...@github.com:hullsean/dogstartest.git"
}

output "mysubnet" {
  value       = "${module.rolling_stones.seanoutput}"
}


ERROR remains the same:

levanter:tftest2 sean[seancli]$ terraform plan

Error: output 'mysubnet': "seanoutput" is not a valid output for module "rolling_stones"



I also did terraform init again to make sure it had latest source from the git repo.  

Could that be the source of the problem?  Perhaps terraform has cached an *OLD* copy of this source code, before I had an output by that name?

-Sean



Sean Hull :: Devops. Data. Innovation.
On Apr 24, 2018, at 12:02 PM, Fernando <tl...@fernandomiguel.net> wrote:

if you show us the output.tf in the module, we can more easily help you build the output in your state

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

Sean Hull

unread,
Apr 24, 2018, 12:16:02 PM4/24/18
to terrafo...@googlegroups.com

I think i figured out the problem.  In my mind I wondered, *could* terraform have cached an old copy of my code?

So I investigated:
$ cd .terraform
$ cd modules
$ cd 5ab835e388189633f352c54b79446d24

cat test.tf:

provider "aws" {
    region = "us-east-1"
}


resource "aws_instance" "omg" {
  ami           = "ami-1853ac65"
  instance_type = "t2.micro"
  subnet_id = "subnet-1f866434"
}

#output "the_omg_subnet" {
#  value = "aws_instance.omg.subnet_id"
#}


It DOES have an old copy.  Why?

Even after I REDO "terraform init" it is still using this old copy of test.tf.

It doesn't match my git repo.

Why would it do this?

VERY VERY WEIRD.

-Sean



Sean Hull :: Devops. Data. Innovation.

Sean Hull

unread,
Apr 24, 2018, 12:23:04 PM4/24/18
to terrafo...@googlegroups.com

It worked (see below).

Here's what I learned:
1. only pre-defined outputs can be used with modules
2. an OUTPUT of an OUTPUT must be defined to get access (weird)
3. Terraform caches your git code *ONCE*.  Subsequent terraform init will not grab the latest.  So iterating on this stuff is *VERY* cumbersome.  You must create a whole new directory, then do terraform init again to get the latest code.

I would not have guessed any of these three facts.  Unpleasant!



module.rolling_stones.aws_instance.omg: Still creating... (20s elapsed)
module.rolling_stones.aws_instance.omg: Creation complete after 23s (ID: i-0b1836ba519057aa6)

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

mysubnet = subnet-1f866434
levanter:tftest3 sean[seancli]$ terraform output
mysubnet = subnet-1f866434
levanter:tftest3 sean[seancli]$ 






Sean Hull :: Devops. Data. Innovation.
On Apr 24, 2018, at 12:07 PM, Sean Hull <hull...@gmail.com> wrote:

⁞ Fernando Miguel

unread,
Apr 24, 2018, 12:29:14 PM4/24/18
to terrafo...@googlegroups.com
yes it caches.
anything that is external (not local storage)

use this to pull again
$ terraform init -get=true -upgrade=true

-- 

To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-tool+unsubscribe@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/77435BF2-9454-4253-938B-85023B7552E7%40gmail.com.

Sean Hull

unread,
Apr 24, 2018, 1:20:53 PM4/24/18
to terrafo...@googlegroups.com

Thank you Fernando.



Sean Hull :: Devops. Data. Innovation.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/terraform-tool/CAM7yfUCYf58VceFPUJw%3DZBu%3DxX-1qQSsGcS59YieRwc90mQzYQ%40mail.gmail.com.

ja...@fpcomplete.com

unread,
Apr 25, 2018, 6:13:34 AM4/25/18
to Terraform
Hi Sean,

I would also recommend reading (and re-reading a bunch) the sections in https://www.terraform.io/docs/configuration/, much of what you are struggling to work with in Terraform is documented in this section.

Thank you Fernando.


To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

--
This mailing list is governed under the HashiCorp Community Guidelines - https://www.hashicorp.com/community-guidelines.html. Behavior in violation of those guidelines may result in your removal from this mailing list.
 
GitHub Issues: https://github.com/hashicorp/terraform/issues
IRC: #terraform-tool on Freenode
---
You received this message because you are subscribed to the Google Groups "Terraform" group.
To unsubscribe from this group and stop receiving emails from it, send an email to terraform-too...@googlegroups.com.

Sean Hull

unread,
Apr 25, 2018, 11:06:27 AM4/25/18
to terrafo...@googlegroups.com

Thank you.  Will do.


Sean Hull :: Devops. Data. Innovation.
Reply all
Reply to author
Forward
0 new messages