# Account contacts =============================================================

# Primary contact --------------------------------------------------------------
# Used by AWS for legal, tax, and account ownership communications.

resource "aws_account_primary_contact" "this" {
  count = var.primary_contact != null ? 1 : 0

  account_id         = var.account_id
  full_name          = var.primary_contact.full_name
  company_name       = var.primary_contact.company_name
  phone_number       = var.primary_contact.phone
  website_url        = var.primary_contact.website_url
  address_line_1     = var.primary_contact.address_line_1
  address_line_2     = var.primary_contact.address_line_2
  city               = var.primary_contact.city
  state_or_region    = var.primary_contact.state_or_region
  district_or_county = var.primary_contact.district_or_county
  postal_code        = var.primary_contact.postal_code
  country_code       = var.primary_contact.country_code
}

# Alternate contacts -----------------------------------------------------------
# AWS routes account notifications to these contacts instead of the root
# account email. Each contact type is independently optional.

resource "aws_account_alternate_contact" "this" {
  for_each = var.alternate_contacts

  account_id             = var.account_id
  alternate_contact_type = upper(each.key)
  name                   = each.value.name
  title                  = each.value.title
  email_address          = each.value.email
  phone_number           = each.value.phone
}
