From 32beec61bc747a3ba3bbe07ccb9da49f752ca02a Mon Sep 17 00:00:00 2001 From: hc-github-team-secure-vault-core <82990506+hc-github-team-secure-vault-core@users.noreply.github.com> Date: Tue, 27 Jun 2023 12:58:02 -0400 Subject: [PATCH] backport of commit fd1683698bad3556d21e783a26ec1bca5d0de671 (#21477) Co-authored-by: Ryan Cragun --- enos/modules/target_ec2_instances/main.tf | 20 ++++++++++++++------ 1 file changed, 14 insertions(+), 6 deletions(-) diff --git a/enos/modules/target_ec2_instances/main.tf b/enos/modules/target_ec2_instances/main.tf index 7eb506a3b..7f14b7a04 100644 --- a/enos/modules/target_ec2_instances/main.tf +++ b/enos/modules/target_ec2_instances/main.tf @@ -98,7 +98,7 @@ locals { "x86_64" = var.instance_types["amd64"] } instances = toset([for idx in range(var.instance_count) : tostring(idx)]) - name_prefix = "${var.project_name}-${local.cluster_name}" + name_prefix = "${var.project_name}-${local.cluster_name}-${random_string.unique_id.result}" } resource "random_string" "cluster_name" { @@ -109,24 +109,32 @@ resource "random_string" "cluster_name" { special = false } +resource "random_string" "unique_id" { + length = 4 + lower = true + upper = false + numeric = false + special = false +} + resource "aws_iam_role" "target_instance_role" { - name = "target_instance_role-${random_string.cluster_name.result}" + name = "${local.name_prefix}-instance-role" assume_role_policy = data.aws_iam_policy_document.target_instance_role.json } resource "aws_iam_instance_profile" "target" { - name = "${local.name_prefix}-target" + name = "${local.name_prefix}-instance-profile" role = aws_iam_role.target_instance_role.name } resource "aws_iam_role_policy" "target" { - name = "${local.name_prefix}-target" + name = "${local.name_prefix}-role-policy" role = aws_iam_role.target_instance_role.id policy = data.aws_iam_policy_document.target.json } resource "aws_security_group" "target" { - name = "${local.name_prefix}-target" + name = "${local.name_prefix}-sg" description = "Target instance security group" vpc_id = var.vpc_id @@ -241,7 +249,7 @@ resource "aws_instance" "targets" { tags = merge( var.common_tags, { - Name = "${local.name_prefix}-${var.cluster_tag_key}-target" + Name = "${local.name_prefix}-${var.cluster_tag_key}-instance-target" "${var.cluster_tag_key}" = local.cluster_name }, )