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          = "devops"
}

provider "aws" {
  region = var.aws_region

  default_tags {
    tags = module.default_tags.tags
  }
}

terraform {
  backend "s3" {
    bucket  = "networking-orcd-terraform-state"
    key     = "networking/theorchard.com/terraform.tfstate"
    region  = "us-east-1"
    encrypt = "true"
  }
}

resource "aws_acm_certificate" "tls_cert" {
  # checkov:skip=CKV2_AWS_71: Ensure AWS ACM Certificate domain name does not include wildcards
  domain_name               = "*.${var.domain_name}"
  validation_method         = "DNS"

  options {
    certificate_transparency_logging_preference = "ENABLED"
    export                                      = "ENABLED"
  }

  tags = {
    environment = var.environment
    terraformed = "true"
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "cloudflare_dns_record" "star_theorchard_com" {

  zone_id = var.zone_id
  name    = "_20016cd3249f08efd8aeacc2e4906189"
  type    = "CNAME"
  content = "_2a9b3f199aa8a93987fc5d8cb23ba134.jkddzztszm.acm-validations.aws"
  ttl     = 3600
  comment = "SYS-29480"
  proxied = false
}
