Skip to content

Commit

Permalink
test(e2e): Add user name to AWS resources
Browse files Browse the repository at this point in the history
This change makes it easier to identify who generated these resources when looking at the AWS console
  • Loading branch information
moduli committed Oct 4, 2024
1 parent 21230e1 commit 766642e
Show file tree
Hide file tree
Showing 5 changed files with 18 additions and 7 deletions.
6 changes: 4 additions & 2 deletions enos/modules/aws_boundary/boundary-instances.tf
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
# Copyright (c) HashiCorp, Inc.
# SPDX-License-Identifier: BUSL-1.1

data "aws_caller_identity" "current" {}

resource "aws_instance" "controller" {
count = var.controller_count
ami = var.ubuntu_ami_id
Expand All @@ -24,7 +26,7 @@ resource "aws_instance" "controller" {

tags = merge(local.common_tags,
{
Name = "${local.name_prefix}-boundary-controller-${count.index}"
Name = "${local.name_prefix}-boundary-controller-${count.index}-${split(":", data.aws_caller_identity.current.user_id)[1]}"
Type = local.boundary_cluster_tag,
},
)
Expand All @@ -50,7 +52,7 @@ resource "aws_instance" "worker" {

tags = merge(local.common_tags,
{
Name = "${local.name_prefix}-boundary-worker-${count.index}",
Name = "${local.name_prefix}-boundary-worker-${count.index}-${split(":", data.aws_caller_identity.current.user_id)[1]}",
Type = local.boundary_cluster_tag,
},
)
Expand Down
9 changes: 7 additions & 2 deletions enos/modules/aws_boundary/rds.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,14 @@ resource "aws_db_subnet_group" "boundary" {
subnet_ids = data.aws_subnets.infra.ids
}

locals {
user_email = split(":", data.aws_caller_identity.current.user_id)[1]
user_name = replace(split("@", local.user_email)[0], ".", "")
}

resource "aws_db_instance" "boundary" {
count = var.db_create == true ? 1 : 0
identifier = "boundary-db-${random_string.cluster_id.result}"
identifier = "boundary-db-${random_string.cluster_id.result}-${local.user_name}"
allocated_storage = var.db_storage
storage_type = var.db_storage_type
iops = var.db_storage_iops
Expand All @@ -32,7 +37,7 @@ resource "aws_db_instance" "boundary" {
performance_insights_enabled = true
tags = merge(local.common_tags,
{
Name = "boundary-db-${random_string.cluster_id.result}"
Name = "boundary-db-${random_string.cluster_id.result}-${split(":", data.aws_caller_identity.current.user_id)[1]}"
Type = local.boundary_cluster_tag
},
)
Expand Down
4 changes: 3 additions & 1 deletion enos/modules/aws_target/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ variable "ingress_cidr" {

data "enos_environment" "current" {}

data "aws_caller_identity" "current" {}

resource "aws_security_group" "boundary_target" {
name_prefix = "boundary-target-sg"
description = "SSH and boundary Traffic"
Expand Down Expand Up @@ -70,7 +72,7 @@ resource "aws_instance" "target" {
key_name = var.aws_ssh_keypair_name

tags = merge(var.additional_tags, {
"Name" : "boundary-target-${count.index}",
"Name" : "boundary-target-${count.index}-${split(":", data.aws_caller_identity.current.user_id)[1]}",
"Type" : "target",
"Project" : "Enos",
"Project Name" : "qti-enos-boundary",
Expand Down
2 changes: 1 addition & 1 deletion enos/modules/aws_vault/vault-instances.tf
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ resource "aws_instance" "vault_instance" {
tags = merge(
var.common_tags,
{
Name = "${local.name_suffix}-vault-${var.vault_node_prefix}-${each.key}"
Name = "${local.name_suffix}-vault-${var.vault_node_prefix}-${each.key}-${split(":", data.aws_caller_identity.current.user_id)[1]}"
Type = local.vault_cluster_tag
},
)
Expand Down
4 changes: 3 additions & 1 deletion enos/modules/aws_vpc/main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,8 @@ locals {
)
}

data "aws_caller_identity" "current" {}

data "aws_availability_zones" "available" {
state = "available"

Expand Down Expand Up @@ -137,7 +139,7 @@ resource "aws_vpc" "vpc" {
tags = merge(
local.common_tags,
{
"Name" = var.name
"Name" = "${var.name}-${split(":", data.aws_caller_identity.current.user_id)[1]}"
},
)
}
Expand Down

0 comments on commit 766642e

Please sign in to comment.