provider "aws" {
  region = var.aws_region
}

terraform {
  backend "s3" {
    bucket  = "qa-business-solutions-terraform-state"
    key     = "qa/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.14.1"
  env                = var.environment
  application_family = var.application_family
  bucket_name        = "${var.account_group}-terraform-state"

  custom_logging_prefix = "s3/${module.terraform_state_bucket.s3_bucket_name_output}"

  apply_server_side_encryption_by_default = {
    sse_algorithm = "AES256"
  }
}
