Skip to content

Custom tags where count.index is used (iteration) #1

@TinajaLabs

Description

@TinajaLabs

I'm trying to generate various FQDN names that have different conventions.

I had a highly modified (from previous version) and I used the count and count.index to determine how many iterations to make and created the names accordingly.

Here are the variations:

  • ui.system.com
  • db01.ststem.com
  • db02.system.com
  • xyz001.xx.system.com
  • ax01.xyz001.system.com
  • ax01.xyz001.system.com

For example, the db and the ax are iterated on the host_name when count is greater than 1.

Here's what my tag block looked like inside the instance resource:

resource "aws_instance" "ec2_instance" {
  count = "${var.number_of_instances}"

...

  tags {
    Environment = "${var.track_environment}"
    Name        = "${var.number_of_instances > 1 ? "${var.host_name}${format("%02d", count.index + 1)}.${var.instance_name}" : "${var.instance_name}" }"
    Track       = "${var.track_name}"
    Desc        = "Instance for: ${var.number_of_instances > 1 ? "${var.host_name}${format("%02d", count.index + 1)}.${var.instance_name}" : "${var.instance_name}" }"
    LaunchGroup = "StartEC2Group${upper(substr(var.vpc_name,0,1))}${substr(var.vpc_name,1,-1)}"
    StopGroup   = "StopEC2atNight"
  }

I'm guessing, to keep this functionality, my only option is to modify this module; the main.tf file in resource "aws_instance" "this"

Thanks for any tips,
Chris.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions