<commit_before>/*
 * Create VPC
 */
module "vpc" {
  source    = "github.com/silinternational/terraform-modules//aws/vpc?ref=2.2.0"
  app_name  = "${var.app_name}"
  app_env   = "${var.app_env}"
  aws_zones = "${var.aws_zones}"
}

/*
 * Security group to limit traffic to Cloudflare IPs
 */
module "cloudflare-sg" {
  source = "github.com/silinternational/terraform-modules//aws/cloudflare-sg?ref=2.2.0"
  vpc_id = "${module.vpc.id}"
}

/*
 * Determine most recent ECS optimized AMI
 */
data "aws_ami" "ecs_ami" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn-ami-*-amazon-ecs-optimized"]
  }
}

/*
 * Create auto-scaling group
 */
module "asg" {
  source                  = "github.com/silinternational/terraform-modules//aws/asg?ref=2.2.0"
  app_name                = "${var.app_name}"
  app_env                 = "${var.app_env}"
  aws_instance            = "${var.aws_instance}"
  private_subnet_ids      = ["${module.vpc.private_subnet_ids}"]
  default_sg_id           = "${module.vpc.vpc_default_sg_id}"
  ecs_instance_profile_id = "${var.ecs_instance_profile_id}"
  ecs_cluster_name        = "${var.ecs_cluster_name}"
  ami_id                  = "${data.aws_ami.ecs_ami.id}"
}

/*
 * Create ssl cert for use with listener
 */
resource "aws_acm_certificate" "wildcard" {
  domain_name       = "${var.cert_domain_name}"
  validation_method = "DNS"

  tags {
    app_name = "${var.app_name}"
    app_env  = "${var.app_env}"
  }

  lifecycle {
    create_before_destroy = true
  }
}

resource "cloudflare_record" "cert_validation_dns_record" {
  domain = "${var.cert_domain_name}"
  name   = "${aws_acm_certificate.wildcard.domain_validation_options.0.resource_record_name}"
  value  = "${aws_acm_certificate.wildcard.domain_validation_options.0.resource_record_value}"
  type   = "${aws_acm_certificate.wildcard.domain_validation_options.0.resource_record_type}"
}

resource "aws_acm_certificate_validation" "wildcard_cert_validation" {
  certificate_arn = "${aws_acm_certificate.wildcard.arn}"
  validation_record_fqdns = ["${cloudflare_record.cert_validation_dns_record.hostname}"]
}

/*
 * Create application load balancer for public access
 */
module "alb" {
  source          = "github.com/silinternational/terraform-modules//aws/alb?ref=2.2.0"
  app_name        = "${var.app_name}"
  app_env         = "${var.app_env}"
  internal        = "false"
  vpc_id          = "${module.vpc.id}"
  security_groups = ["${module.vpc.vpc_default_sg_id}", "${module.cloudflare-sg.id}"]
  subnets         = ["${module.vpc.public_subnet_ids}"]
  certificate_arn = "${aws_acm_certificate.wildcard.arn}"
}

/*
 * Create application load balancer for internal use
 */
module "internal_alb" {
  source          = "github.com/silinternational/terraform-modules//aws/alb?ref=2.2.0"
  alb_name        = "alb-${var.app_name}-${var.app_env}-int"
  app_name        = "${var.app_name}"
  app_env         = "${var.app_env}"
  internal        = "true"
  tg_name         = "tg-${var.app_name}-${var.app_env}-int-def"
  vpc_id          = "${module.vpc.id}"
  security_groups = ["${module.vpc.vpc_default_sg_id}"]
  subnets         = ["${module.vpc.private_subnet_ids}"]
  certificate_arn = "${aws_acm_certificate.wildcard.arn}"
}<commit_msg>Revert "Create/validate the ACM cert rather than just looking for it"<commit_after>/*
 * Create VPC
 */
module "vpc" {
  source    = "github.com/silinternational/terraform-modules//aws/vpc?ref=2.2.0"
  app_name  = "${var.app_name}"
  app_env   = "${var.app_env}"
  aws_zones = "${var.aws_zones}"
}

/*
 * Security group to limit traffic to Cloudflare IPs
 */
module "cloudflare-sg" {
  source = "github.com/silinternational/terraform-modules//aws/cloudflare-sg?ref=2.2.0"
  vpc_id = "${module.vpc.id}"
}

/*
 * Determine most recent ECS optimized AMI
 */
data "aws_ami" "ecs_ami" {
  most_recent = true
  owners      = ["amazon"]

  filter {
    name   = "name"
    values = ["amzn-ami-*-amazon-ecs-optimized"]
  }
}

/*
 * Create auto-scaling group
 */
module "asg" {
  source                  = "github.com/silinternational/terraform-modules//aws/asg?ref=2.2.0"
  app_name                = "${var.app_name}"
  app_env                 = "${var.app_env}"
  aws_instance            = "${var.aws_instance}"
  private_subnet_ids      = ["${module.vpc.private_subnet_ids}"]
  default_sg_id           = "${module.vpc.vpc_default_sg_id}"
  ecs_instance_profile_id = "${var.ecs_instance_profile_id}"
  ecs_cluster_name        = "${var.ecs_cluster_name}"
  ami_id                  = "${data.aws_ami.ecs_ami.id}"
}

/*
 * Get ssl cert for use with listener
 */
data "aws_acm_certificate" "wildcard" {
  domain = "${var.cert_domain_name}"
}

/*
 * Create application load balancer for public access
 */
module "alb" {
  source          = "github.com/silinternational/terraform-modules//aws/alb?ref=2.2.0"
  app_name        = "${var.app_name}"
  app_env         = "${var.app_env}"
  internal        = "false"
  vpc_id          = "${module.vpc.id}"
  security_groups = ["${module.vpc.vpc_default_sg_id}", "${module.cloudflare-sg.id}"]
  subnets         = ["${module.vpc.public_subnet_ids}"]
  certificate_arn = "${data.aws_acm_certificate.wildcard.arn}"
}

/*
 * Create application load balancer for internal use
 */
module "internal_alb" {
  source          = "github.com/silinternational/terraform-modules//aws/alb?ref=2.2.0"
  alb_name        = "alb-${var.app_name}-${var.app_env}-int"
  app_name        = "${var.app_name}"
  app_env         = "${var.app_env}"
  internal        = "true"
  tg_name         = "tg-${var.app_name}-${var.app_env}-int-def"
  vpc_id          = "${module.vpc.id}"
  security_groups = ["${module.vpc.vpc_default_sg_id}"]
  subnets         = ["${module.vpc.private_subnet_ids}"]
  certificate_arn = "${data.aws_acm_certificate.wildcard.arn}"
}
{'fraction_non_alphanumeric': 0.15566603805931767, 'fraction_numerical': 0.005657466140922339, 'mean_word_length': 3.059846903270703, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '900902', 'n_tokens_mistral': 2180, 'n_tokens_neox': 2126, 'n_words': 308}