Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to store and reuse interpolation results? #15668

Closed
anshprat opened this issue Jul 30, 2017 · 3 comments
Closed

How to store and reuse interpolation results? #15668

anshprat opened this issue Jul 30, 2017 · 3 comments

Comments

@anshprat
Copy link

anshprat commented Jul 30, 2017

Terraform version

tf --version
Terraform v0.9.11

Terraform Configuration Files

resource "aws_ebs_volume" "instance_system_volume" {
  count = "${length(var.extra_ebs_volumes) * var.count_instances }"

  type = "${lookup(var.extra_ebs_volume_type,lookup(var.tag_disk_location,var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)]),"standard")}"
  availability_zone = "${element(aws_instance.myorg_instance.*.availability_zone, count.index / length(var.extra_ebs_volumes))}"

  size = "${floor(lookup(merge(var.default_ebs_vol_sizes,var.ebs_vol_sizes),
    var.tag_disk_location[var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)]]))}"

  tags = "${merge(var.tags_basic, var.tags_extra,
    map("Name", format("%s", lower("${replace(var.tags_extra["Name"], "i_count",
      format("%02d", (count.index / length(var.extra_ebs_volumes)) + 1))}${var.txt_delimiter}
      ${var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)]}${var.txt_delimiter}
      ${lookup(var.tag_disk_location,var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)])}")),
    "tag_disk_location",lookup(var.tag_disk_location,var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)])),
    map("tag_monthly_cost", "${1.0 * lookup(merge(var.default_ebs_vol_sizes,var.ebs_vol_sizes),
      var.tag_disk_location[var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)]]) * lookup(var.ebs_cost,
      lookup(var.extra_ebs_volume_type,
        lookup(var.tag_disk_location,var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)]),"standard"))}")
    )
      }"
  lifecycle {
    ignore_changes = ["availability_zone"]
  }
}

Hi,

How do I store and reuse terraform interpolation result within resources that do not expose them as output? Inability to use self reference further adds on to this issue.

example: In aws_ebs_volume , I am calculating my volume size using:

size = "${lookup(merge(var.default_ebs_vol_sizes,var.ebs_vol_sizes), var.tag_disk_location[var.extra_ebs_volumes[count.index % length(var.extra_ebs_volumes)]])}"

Now I need to reuse the same size for calculating the cost tags in the same resource as well as in corresponding ec2 resource (in same local module).

How do I do this without copy pasting the entire formula?

PS: I have come across this use case in multiple scenarios, so the above is just one of the use cases where I need to reuse the interpolated results. Getting the interpolated result using the corresponding data source is one way out in this particular scenario but looking for a more straight forward solution and generic solution.

@apparentlymart
Copy link
Contributor

Hi @anshprat!

Right now there isn't a convenient way to do what you describe here. There are some workarounds described in the comments of #4084.

In the near future this will be possible using the feature being added in #15449. Development on that didn't complete in time before the 0.10.0 feature freeze but it should be included in an upcoming version soon.

Since we already have #4084 open discussing this problem and #15449 for the proposed solution, I'm going to close this just to consolidate the discussion there. Thanks for this question/suggestion!

@anshprat
Copy link
Author

alright, thanks!

@ghost
Copy link

ghost commented Apr 8, 2020

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.

If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@ghost ghost locked and limited conversation to collaborators Apr 8, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants