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

Use variable component tag in the introspection mixin #624

Open
rusowyler opened this issue Apr 4, 2023 · 0 comments
Open

Use variable component tag in the introspection mixin #624

rusowyler opened this issue Apr 4, 2023 · 0 comments

Comments

@rusowyler
Copy link

Describe the Feature

Instead of a fixed value, set the component name tag using a variable.

Expected Behavior

By setting

component_tag="IacComponent" 

Obtain:

      + tags                  = {
          + "Iac"          = "Terraform"
          + "IacComponent" = "ecs-service"
          + "Stage"        = "dev"

Use Case

Some companies may have different patterns for the component name tag. By using this solution, they may change it.

Code suggestion

locals {
  # Throw an error if lookup fails
  check_required_tags = module.this.enabled ? [
    for k in var.required_tags :
    lookup(module.this.tags, k)
  ] : []
}

variable "required_tags" {
  type        = list(string)
  description = "List of required tag names"
  default     = []
}

variable "component_tag" {
  type        = string
  description = "The name of the tag that will be used to identify the component"
  default     = "IacComponent"
}

# `introspection` module will contain the additional tags
module "introspection" {
  source  = "cloudposse/label/null"
  version = "0.25.0"

  tags = merge(var.tags, {
    format("%s", var.component_tag) = basename(abspath(path.module))
  })

  context = module.this.context
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant