Skip to content

Commit

Permalink
Support to manage additional regions for account module
Browse files Browse the repository at this point in the history
  • Loading branch information
posquit0 committed Apr 17, 2024
1 parent e8e500a commit 6655c8a
Show file tree
Hide file tree
Showing 5 changed files with 73 additions and 0 deletions.
1 change: 1 addition & 0 deletions modules/account/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ This module creates following resources.
- `aws_iam_security_token_service_preferences`
- `aws_account_primary_contact` (optional)
- `aws_account_alternate_contact` (optional)
- `aws_account_region` (optional)
- `aws_s3_account_public_access_block`
- `aws_spot_datafeed_subscription` (optional)

Expand Down
8 changes: 8 additions & 0 deletions modules/account/contacts.tf
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
# Primary Contact
###################################################

# INFO: Not supported attributes
# - `account_id`
resource "aws_account_primary_contact" "this" {
count = var.primary_contact != null ? 1 : 0

Expand All @@ -26,6 +28,8 @@ resource "aws_account_primary_contact" "this" {
# Alternate Contacts
###################################################

# INFO: Not supported attributes
# - `account_id`
resource "aws_account_alternate_contact" "billing" {
count = var.billing_contact != null ? 1 : 0

Expand All @@ -37,6 +41,8 @@ resource "aws_account_alternate_contact" "billing" {
phone_number = var.billing_contact.phone
}

# INFO: Not supported attributes
# - `account_id`
resource "aws_account_alternate_contact" "operation" {
count = var.operation_contact != null ? 1 : 0

Expand All @@ -48,6 +54,8 @@ resource "aws_account_alternate_contact" "operation" {
phone_number = var.operation_contact.phone
}

# INFO: Not supported attributes
# - `account_id`
resource "aws_account_alternate_contact" "security" {
count = var.security_contact != null ? 1 : 0

Expand Down
5 changes: 5 additions & 0 deletions modules/account/outputs.tf
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ output "password_policy" {
value = aws_iam_account_password_policy.this
}

output "additional_regions" {
description = "A set of additional regions enabled in the account."
value = var.additional_regions
}

output "primary_contact" {
description = "The primary contact attached to an AWS Account."
value = try({
Expand Down
31 changes: 31 additions & 0 deletions modules/account/regions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
locals {
available_regions = [
"af-south-1",
"ap-east-1",
"ap-south-2",
"ap-southeast-3",
"ap-southeast-4",
"ca-west-1",
"eu-south-1",
"eu-south-2",
"eu-central-2",
"me-south-1",
"me-central-1",
"il-central-1",
]
}

###################################################
# Regions
###################################################

# INFO: Not supported attributes
# - `account_id`
# INFO: Not supported idempotent operation
# TODO: How to manage disabled region?
resource "aws_account_region" "this" {
for_each = var.additional_regions

region_name = each.value
enabled = true
}
28 changes: 28 additions & 0 deletions modules/account/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,34 @@ variable "password_policy" {
nullable = false
}

variable "additional_regions" {
description = "(Optional) A set of regions to enable in the account."
type = set(string)
default = []
nullable = false

validation {
condition = alltrue([
for region in var.additional_regions :
contains([
"af-south-1",
"ap-east-1",
"ap-south-2",
"ap-southeast-3",
"ap-southeast-4",
"ca-west-1",
"eu-south-1",
"eu-south-2",
"eu-central-2",
"me-south-1",
"me-central-1",
"il-central-1",
], region)
])
error_message = "Available regions for `additional_regions` are `af-south-1`, `ap-east-1`, `ap-south-2`, `ap-southeast-3`, `ap-southeast-4`, `ca-west-1`, `eu-south-1`, `eu-south-2`, `eu-central-2`, `me-south-1`, `me-central-1`, `il-central-1`."
}
}

variable "primary_contact" {
description = <<EOF
(Optional) The configuration of the primary contact for the AWS Account. `primary_contact` as defined below.
Expand Down

0 comments on commit 6655c8a

Please sign in to comment.