From 4304ec0c1c491d1f872189e4c85a7c3bfbd825b1 Mon Sep 17 00:00:00 2001 From: Michael Li Date: Tue, 15 Apr 2025 11:31:12 -0400 Subject: [PATCH] chore(e2e): Address issue with deleting roles/policies (#5646) On destroy, there was an issue with deleting IAM roles due to the following error: DeleteConflict: Cannot delete entity, must detach all policies first This commit adds an option to force the policy detachment, preventing the error. --- enos/modules/aws_boundary/iam.tf | 5 +++-- enos/modules/aws_vault/iam.tf | 7 ++++--- enos/modules/aws_worker/iam.tf | 5 +++-- 3 files changed, 10 insertions(+), 7 deletions(-) diff --git a/enos/modules/aws_boundary/iam.tf b/enos/modules/aws_boundary/iam.tf index 3c6aea894..46f3c831e 100644 --- a/enos/modules/aws_boundary/iam.tf +++ b/enos/modules/aws_boundary/iam.tf @@ -32,8 +32,9 @@ data "aws_iam_policy_document" "boundary_profile" { } resource "aws_iam_role" "boundary_instance_role" { - name = "boundary_instance_role-${random_string.cluster_id.result}" - assume_role_policy = data.aws_iam_policy_document.boundary_instance_role.json + name = "boundary_instance_role-${random_string.cluster_id.result}" + assume_role_policy = data.aws_iam_policy_document.boundary_instance_role.json + force_detach_policies = true } resource "aws_iam_instance_profile" "boundary_profile" { diff --git a/enos/modules/aws_vault/iam.tf b/enos/modules/aws_vault/iam.tf index 32dc26112..2426490cd 100644 --- a/enos/modules/aws_vault/iam.tf +++ b/enos/modules/aws_vault/iam.tf @@ -36,9 +36,10 @@ data "aws_iam_policy_document" "vault_profile" { } resource "aws_iam_role" "vault_instance_role" { - count = var.deploy ? 1 : 0 - name = "vault_instance_role-${random_string.cluster_id.result}" - assume_role_policy = data.aws_iam_policy_document.vault_instance_role.json + count = var.deploy ? 1 : 0 + name = "vault_instance_role-${random_string.cluster_id.result}" + assume_role_policy = data.aws_iam_policy_document.vault_instance_role.json + force_detach_policies = true } resource "aws_iam_instance_profile" "vault_profile" { diff --git a/enos/modules/aws_worker/iam.tf b/enos/modules/aws_worker/iam.tf index 6bddbcd2c..2ed467d12 100644 --- a/enos/modules/aws_worker/iam.tf +++ b/enos/modules/aws_worker/iam.tf @@ -58,8 +58,9 @@ data "aws_iam_policy_document" "combined_policy_document" { } resource "aws_iam_role" "boundary_instance_role" { - name = "boundary_instance_role-${random_string.cluster_id.result}" - assume_role_policy = data.aws_iam_policy_document.boundary_instance_role.json + name = "boundary_instance_role-${random_string.cluster_id.result}" + assume_role_policy = data.aws_iam_policy_document.boundary_instance_role.json + force_detach_policies = true } resource "aws_iam_instance_profile" "boundary_profile" {