<commit_before>locals {
  worker_groups = [
    {
      instance_type         = "${var.worker_instance_type}"
      root_volume_size      = "${var.worker_root_volume_size}"
      asg_desired_capacity  = 1
      asg_max_size          = 6
      autoscaling_enabled   = true
      protect_from_scale_in = true
      subnets               = "${aws_subnet.jenkins_workers_c.id}"
    },
    },
  ]

  # recent versions of eks are creating a gp2 sc by default; attempting to
  # declare our own causes an error.
  k8s_storage_class = "gp2"
}

module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "3.0.0"

  cluster_name    = "${local.k8s_cluster_name}"
  cluster_version = "1.12"

  subnets = [
    "${aws_subnet.jenkins-demo.id}",
    "${aws_subnet.jenkins_workers_c.id}",
    "${aws_subnet.jenkins_workers_d.id}",
  ]

  tags = {
    Name     = "${local.k8s_cluster_name}"
    env_name = "${var.env_name}"
  }

  vpc_id = "${aws_vpc.jenkins-demo.id}"

  worker_groups      = "${local.worker_groups}"
  worker_group_count = "1"

  # allow communication between worker nodes and jenkins master ec2 instance
  cluster_security_group_id = "${aws_security_group.jenkins-demo-internal.id}"
  worker_security_group_id  = "${aws_security_group.jenkins-demo-internal.id}"

  #worker_additional_security_group_ids = [
  #  "${aws_security_group.jenkins-demo-internal.id}",
  #]

  write_kubeconfig = true
  cluster_enabled_log_types = [
    "api",
    "audit",
    "authenticator",
    "controllerManager",
    "scheduler",
  ]
}

# if vpc networking related resources are destroyed down before k8s resources,
# eks might break...
# And the k8s api seems to like to timeout right after eks comes up
resource "null_resource" "eks_ready" {
  depends_on = [
    #"module.eks",
    "aws_key_pair.jenkins-demo",
    "aws_vpc.jenkins-demo",
    "aws_internet_gateway.jenkins-demo",
    "aws_vpc_dhcp_options.jenkins",
    "aws_vpc_dhcp_options_association.jenkins",
    "aws_route53_zone.jenkins-internal",
    "aws_route53_record.jenkins-master-internal",
    "aws_subnet.jenkins-demo",
    "aws_subnet.jenkins_workers_c",
    "aws_subnet.jenkins_workers_d",
    "aws_route_table.jenkins-demo",
    "aws_main_route_table_association.jenkins-demo",
    "aws_network_acl.jenkins-demo",<commit_msg>add "agent" label to worker ASG + new "admin" ASG<commit_after>locals {
  worker_groups = [
    {
      name                  = "agents"
      instance_type         = "${var.worker_instance_type}"
      root_volume_size      = "${var.worker_root_volume_size}"
      asg_desired_capacity  = 1
      asg_max_size          = 6
      autoscaling_enabled   = true
      protect_from_scale_in = true
      subnets               = "${aws_subnet.jenkins_workers_c.id}"
      kubelet_extra_args    = "--node-labels=nodegroup=agent"
    },
    {
      name                  = "admin"
      instance_type         = "t3.medium"
      root_volume_size      = "32"
      asg_desired_capacity  = 1
      asg_max_size          = 2
      autoscaling_enabled   = true
      protect_from_scale_in = true
      subnets               = "${aws_subnet.jenkins_workers_c.id}"
      kubelet_extra_args    = "--node-labels=nodegroup=admin"
    },
  ]

  # recent versions of eks are creating a gp2 sc by default; attempting to
  # declare our own causes an error.
  k8s_storage_class = "gp2"
}

module "eks" {
  source  = "terraform-aws-modules/eks/aws"
  version = "3.0.0"

  cluster_name    = "${local.k8s_cluster_name}"
  cluster_version = "1.12"

  subnets = [
    "${aws_subnet.jenkins-demo.id}",
    "${aws_subnet.jenkins_workers_c.id}",
    "${aws_subnet.jenkins_workers_d.id}",
  ]

  tags = {
    Name     = "${local.k8s_cluster_name}"
    env_name = "${var.env_name}"
  }

  vpc_id = "${aws_vpc.jenkins-demo.id}"

  worker_groups      = "${local.worker_groups}"
  worker_group_count = "${length(local.worker_groups)}"

  # allow communication between worker nodes and jenkins master ec2 instance
  cluster_security_group_id = "${aws_security_group.jenkins-demo-internal.id}"
  worker_security_group_id  = "${aws_security_group.jenkins-demo-internal.id}"

  #worker_additional_security_group_ids = [
  #  "${aws_security_group.jenkins-demo-internal.id}",
  #]

  write_kubeconfig = true
  cluster_enabled_log_types = [
    "api",
    "audit",
    "authenticator",
    "controllerManager",
    "scheduler",
  ]
}

# if vpc networking related resources are destroyed down before k8s resources,
# eks might break...
# And the k8s api seems to like to timeout right after eks comes up
resource "null_resource" "eks_ready" {
  depends_on = [
    #"module.eks",
    "aws_key_pair.jenkins-demo",

    "aws_vpc.jenkins-demo",
    "aws_internet_gateway.jenkins-demo",
    "aws_vpc_dhcp_options.jenkins",
    "aws_vpc_dhcp_options_association.jenkins",
    "aws_route53_zone.jenkins-internal",
    "aws_route53_record.jenkins-master-internal",
    "aws_subnet.jenkins-demo",
    "aws_subnet.jenkins_workers_c",
    "aws_subnet.jenkins_workers_d",
    "aws_route_table.jenkins-demo",
    "aws_main_route_table_association.jenkins-demo",
    "aws_network_acl.jenkins-demo",
{'fraction_non_alphanumeric': 0.11699435468172086, 'fraction_numerical': 0.008954642787619232, 'mean_word_length': 3.1636952998379253, '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': '1907563', 'n_tokens_mistral': 1849, 'n_tokens_neox': 1811, 'n_words': 293}