module "default_tags" {
  source             = "git@github.com:theorchard/terraform-default-tags.git//?ref=2.0.0"
  environment        = var.environment
  application_family = var.application_family
  team_name          = var.team_name
}

provider "aws" {
  region = var.aws_region

  default_tags {
    tags = module.default_tags.tags
  }
}

terraform {
  backend "s3" {
    bucket  = "prod-infra-terraform-state"
    key     = "prod/terraform-bootstrap/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

# The attribute `${data.aws_caller_identity.current.account_id}` will be current account number.
data "aws_caller_identity" "current" {}

# Terraform backends cannot contain interpolations

data "aws_s3_bucket" "security_logs" {
  bucket = "security-${data.aws_caller_identity.current.account_id}-logs"
}

module "terraform_state_bucket" {
  source                = "git@github.com:theorchard/terraform-s3.git//modules/s3_bucket?ref=3.12.1"
  env                   = var.environment
  application_family    = var.application_family
  bucket_name           = "${var.account_group}-terraform-state"
  custom_logging_prefix = "${var.environment}-${var.account_group}-terraform-state"

  apply_server_side_encryption_by_default = {
    sse_algorithm = "AES256"
  }
}
