Skip to content

Error during creation of instance from scratch with a random string included in the NameΒ #456

@maksperovpm

Description

@maksperovpm

Description

Hi team, Hope you're doing well.

After upgrade to the latest version of Terraform cli and EC2 module we start experiencing an issue with EC2 instances creation.
We had no problems using the latest 5.x version.

The issue is caused by 2 factors:

  1. a new resource was added to the module, specificaly this one >>> resource "aws_ec2_tag" "spot_instance".
  2. (no issues before) we call this module from our private module and provide the calculated "name" attribute value that contains a random string

This is the name value we provide
name = join("-", [var.environment_name, var.server_name, random_string.name_suffix[0].result])

This is the error we get
on .terraform/modules/complete.ec2/main.tf line 612, in resource "aws_ec2_tag" "spot_instance":
β”‚ 612: for_each = { for k, v in local.instance_tags : k => v if local.create && var.create_spot_instance }
β”‚ β”œβ”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€β”€
β”‚ β”‚ local.create is true
β”‚ β”‚ local.instance_tags is a map of string, known only after apply
β”‚ β”‚ var.create_spot_instance is false

Versions

  • Module version [Required]:

  • Terraform version:
    1.13.2

  • Provider version(s):
    6.14.1

Reproduction Code [Required]

resource "random_string" "name_suffix" {
  length    = 2
  special   = false
  min_lower = 1
  min_upper = 1
}

module "ec2" {
  source  = "terraform-aws-modules/ec2-instance/aws"
  version = "6.1.1"
  create = var.create
  name  = join("-", ["ENV-NAME", "SERVER-NAME", random_string.name_suffix[0].result])
  ...
}

Expected behavior

Our stunning developers to find a better create condition for resource "aws_ec2_tag" "spot_instance" that will not fail the creation of instance from scratch because of a tag that includes a string from a parallel resource.

May the force be with you.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions