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

Feature request: extend self variables outside of provisioners and make them lazy #17908

Closed
m4rkw opened this issue Apr 20, 2018 · 2 comments
Closed

Comments

@m4rkw
Copy link

m4rkw commented Apr 20, 2018

Consider this template for AWS tags defined as a local:

locals {
  tags = {
    "Name"          = "${var.aws_env}-${var.aws_region}-${var.product}-${var.service}"
    "owner"         = "${var.team}"
    "customer"      = "${var.customer}"
    "environment"   = "${var.aws_env}"
    "product"       = "${var.product}"
    "service"       = "${var.service}"
  }

This is similar to a tagging template that we define for our AWS resources, and can then be "inherited" by various modules built by other teams. They simply link to this template in their workspace and the tags become available as local.tags based on the vars that define that workspace.

This is fine for some modules with only one resource, but is less than ideal for modules that define multiple resources. A good example is dynamodb tables, say a module creates two tables:

staging-eu-west-1-myproduct-myservice-system1
staging-eu-west-1-myproduct-myservice-system2

Using the tagging template as defined above both of these tables will end up with the same generic Name tag which is not ideal. This can be worked around by overriding the Name tag in the module, eg:

tags  = "${merge(var.tags, map("Name", "${var.tags["Name"]}-system1"))}"

however it would be nice if this could be made simpler and be done by inference instead.

Are there any plans to extend the self variable functionality so that it works outside of provisioners?

eg

resource "aws_dynamodb_table" "system1" {
  tags  = "${merge(var.tags, map("Name", "${var.tags["Name"]}-${self.id}"))}"
}

what would also be really nice would be if self variables could be defined in locals and load lazily. so in my locals.tf i could do something like:

locals {
  tags = {
    "Name"          = "${var.aws_env}-${var.aws_region}-${var.product}-${var.service}-${self.id}"
    "owner"         = "${var.team}"
    "customer"      = "${var.customer}"
    "environment"   = "${var.aws_env}"
    "product"       = "${var.product}"
    "service"       = "${var.service}"
  }

and then have self.id only be evaluated when it's processed inside a resource block.

This would make it easy to create dynamic tagging templates that can be easily used by other teams without much effort.

@apparentlymart
Copy link
Contributor

Hi @m4rkw! Sorry we didn't respond to this sooner.

This request seems to overlap quite a lot with the one in #3267, so I'm going to close this one just to consolidate the discussion over there.

@ghost
Copy link

ghost commented Jul 25, 2019

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 Jul 25, 2019
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