|
| 1 | +resource "time_offset" "expiry" { |
| 2 | + offset_days = var.expiry_days |
| 3 | +} |
| 4 | + |
| 5 | +resource "aws_cloudformation_stack" "management" { |
| 6 | + count = local.deploy_to_management ? 1 : 0 |
| 7 | + |
| 8 | + name = "AppviaAuditRole" |
| 9 | + template_body = local.template_body |
| 10 | + on_failure = "ROLLBACK" |
| 11 | + |
| 12 | + capabilities = [ |
| 13 | + "CAPABILITY_NAMED_IAM", |
| 14 | + "CAPABILITY_AUTO_EXPAND", |
| 15 | + "CAPABILITY_IAM", |
| 16 | + ] |
| 17 | + |
| 18 | + parameters = { |
| 19 | + AppviaRoleARN = var.appvia_role_arn |
| 20 | + ExternalID = var.external_id |
| 21 | + ExpiryDate = time_offset.expiry.rfc3339 |
| 22 | + } |
| 23 | + |
| 24 | + lifecycle { |
| 25 | + ignore_changes = [ |
| 26 | + capabilities, |
| 27 | + ] |
| 28 | + } |
| 29 | +} |
| 30 | + |
| 31 | +resource "aws_cloudformation_stack_set" "member_accounts" { |
| 32 | + name = "AppviaAuditRole" |
| 33 | + description = "Provisions federated IAM role allowing Appvia remote audit access" |
| 34 | + template_body = local.template_body |
| 35 | + permission_model = "SERVICE_MANAGED" |
| 36 | + |
| 37 | + capabilities = [ |
| 38 | + "CAPABILITY_NAMED_IAM", |
| 39 | + "CAPABILITY_AUTO_EXPAND", |
| 40 | + "CAPABILITY_IAM", |
| 41 | + ] |
| 42 | + |
| 43 | + parameters = { |
| 44 | + AppviaRoleARN = var.appvia_role_arn |
| 45 | + ExternalID = var.external_id |
| 46 | + ExpiryDate = time_offset.expiry.rfc3339 |
| 47 | + } |
| 48 | + |
| 49 | + auto_deployment { |
| 50 | + enabled = true |
| 51 | + retain_stacks_on_account_removal = false |
| 52 | + } |
| 53 | + |
| 54 | + lifecycle { |
| 55 | + ignore_changes = [ |
| 56 | + administration_role_arn, |
| 57 | + capabilities, |
| 58 | + ] |
| 59 | + } |
| 60 | +} |
| 61 | + |
| 62 | +resource "aws_cloudformation_stack_set_instance" "member_accounts" { |
| 63 | + count = length(var.deployment_account_ids) > 0 ? 1 : 0 |
| 64 | + |
| 65 | + stack_set_name = aws_cloudformation_stack_set.member_accounts.name |
| 66 | + |
| 67 | + deployment_targets { |
| 68 | + account_filter_type = "INTERSECTION" |
| 69 | + accounts = local.member_account_ids |
| 70 | + |
| 71 | + organizational_unit_ids = [ |
| 72 | + data.aws_organizations_organization.current.roots[0].id, |
| 73 | + ] |
| 74 | + } |
| 75 | +} |
0 commit comments