<commit_before># Configure the Consul provider
provider "consul" {
    address    = "${var.consul}:8500"
    datacenter = "${var.region}"
}

# Consul outputs
resource "consul_keys" "dpaste" {
    datacenter = "${var.region}"
   
    # Set the CNAME of our load balancer as a key
    key {
        name  = "elb_cname"
        path  = "aws/${var.project}/url"
        value = "http://${aws_elb.dpaste.dns_name}/"
    }
    
    key {
        name  = "instance-id"
        path  = "aws/${var.project}/instance-id"
        value = "${aws_instance.dpaste.id}"
    }
}

# Consul config outputs
resource "consul_keys" "app_config" {
    datacenter = "${var.region}"

    key {
        name  = "db_name"
	path  = "${var.project}/${var.environment}/config/db_name"
	value = "${var.project}"
    }
    key {
        name  = "db_username"
	path  = "${var.project}/${var.environment}/config/db_username"
	value = "${var.project}"
    }
    key {
        name  = "app_db_server"
	path  = "${var.project}/${var.environment}/config/app_db_server"
	value = "localhost"
    }

    #XXX: Needs to be auto-generated
    key {
        name  = "db_password"
	path  = "${var.project}/${var.environment}/config/db_password"
	value = "<PASSWORD>"
    }

    #XXX: Needs to be auto-generated
    key {
        name  = "db_root_password"
	path  = "${var.project}/${var.environment}/config/db_root_password"
	value = "<PASSWORD>"
    }

    #XXX: Needs to be auto-generated
    key {
        name  = "app_secret_key"
	path  = "${var.project}/${var.environment}/config/app_secret_key"
	value = "a88385f6-<KEY>6-<KEY>"
    }
}

# Configure the AWS Provider
provider "aws" {
    access_key = "${var.aws_access_key}"
    secret_key = "${var.aws_secret_key}"
    region     = "${var.region}"
}

# Create a new load balancer
resource "aws_elb" "dpaste" {
    name = "${var.environment}-${var.project}-elb-${var.release}-${var.build}"
    availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c" ]

    listener {
        instance_port     = 8080
        instance_protocol = "http"
        lb_port           = 80
        lb_protocol       = "http"
    }

    health_check {
        healthy_threshold   = 2
        unhealthy_threshold = 2
        timeout             = 3
        target              = "HTTP:8080/"
        interval            = 30
    }

    instances = ["${aws_instance.dpaste.id}"]
    cross_zone_load_balancing = true
}

# Create a web server
resource "aws_instance" "dpaste" {
    ami = "ami-a26f27ca"
    
    depends_on = ["aws_instance.migrator"]

    tags {
        Name = "${var.project} ${var.environment} v${var.release}.${var.build}"
    }
    
    key_name = "${var.key_name}"
    
    instance_type = "m3.medium"
    
    security_groups = [
        "${aws_security_group.dpaste.name}"
    ]
    
    user_data = "CONSUL_PUBLIC=1\nCONSUL_DC=${var.region}\nCONSUL_SECRET=${var.consul_secret}\nCONSUL_JOIN=${var.consul}"
}

# Create a migration instance
resource "aws_instance" "migrator" {
    ami = "ami-d299c4ba"

    tags {
        Name = "${var.project} migrator ${var.environment} v${var.release}-${var.build}"
    }
<commit_msg>add missing dependency on consul keys to be safe<commit_after># Configure the Consul provider
provider "consul" {
    address    = "${var.consul}:8500"
    datacenter = "${var.region}"
}

# Consul outputs
resource "consul_keys" "dpaste" {
    datacenter = "${var.region}"
   
    # Set the CNAME of our load balancer as a key
    key {
        name  = "elb_cname"
        path  = "aws/${var.project}/url"
        value = "http://${aws_elb.dpaste.dns_name}/"
    }
    
    key {
        name  = "instance-id"
        path  = "aws/${var.project}/instance-id"
        value = "${aws_instance.dpaste.id}"
    }
}

# Consul config outputs
resource "consul_keys" "app_config" {
    datacenter = "${var.region}"

    key {
        name  = "db_name"
	path  = "${var.project}/${var.environment}/config/db_name"
	value = "${var.project}"
    }
    key {
        name  = "db_username"
	path  = "${var.project}/${var.environment}/config/db_username"
	value = "${var.project}"
    }
    key {
        name  = "app_db_server"
	path  = "${var.project}/${var.environment}/config/app_db_server"
	value = "localhost"
    }

    #XXX: Needs to be auto-generated
    key {
        name  = "db_password"
	path  = "${var.project}/${var.environment}/config/db_password"
	value = "<PASSWORD>"
    }

    #XXX: Needs to be auto-generated
    key {
        name  = "db_root_password"
	path  = "${var.project}/${var.environment}/config/db_root_password"
	value = "<PASSWORD>"
    }

    #XXX: Needs to be auto-generated
    key {
        name  = "app_secret_key"
	path  = "${var.project}/${var.environment}/config/app_secret_key"
	value = "a88385f6-0b75-4d46-a420-4427297f52d5"
    }
}

# Configure the AWS Provider
provider "aws" {
    access_key = "${var.aws_access_key}"
    secret_key = "${var.aws_secret_key}"
    region     = "${var.region}"
}

# Create a new load balancer
resource "aws_elb" "dpaste" {
    name = "${var.environment}-${var.project}-elb-${var.release}-${var.build}"
    availability_zones = ["us-east-1a", "us-east-1b", "us-east-1c" ]

    listener {
        instance_port     = 8080
        instance_protocol = "http"
        lb_port           = 80
        lb_protocol       = "http"
    }

    health_check {
        healthy_threshold   = 2
        unhealthy_threshold = 2
        timeout             = 3
        target              = "HTTP:8080/"
        interval            = 30
    }

    instances = ["${aws_instance.dpaste.id}"]
    cross_zone_load_balancing = true
}

# Create a web server
resource "aws_instance" "dpaste" {
    ami = "ami-a26f27ca"
    
    depends_on = ["aws_instance.migrator", "consul_keys.app_config"]

    tags {
        Name = "${var.project} ${var.environment} v${var.release}.${var.build}"
    }
    
    key_name = "${var.key_name}"
    
    instance_type = "m3.medium"
    
    security_groups = [
        "${aws_security_group.dpaste.name}"
    ]
    
    user_data = "CONSUL_PUBLIC=1\nCONSUL_DC=${var.region}\nCONSUL_SECRET=${var.consul_secret}\nCONSUL_JOIN=${var.consul}"
}

# Create a migration instance
resource "aws_instance" "migrator" {
    ami = "ami-d299c4ba"

    depends_on = ["consul_keys.app_config"]

    tags {
        Name = "${var.project} migrator ${var.environment} v${var.release}-${var.build}"
    }

{'fraction_non_alphanumeric': 0.15151040851463451, 'fraction_numerical': 0.015025825637814995, 'mean_word_length': 2.4428879310344827, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 9, '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': '6924320', 'n_tokens_mistral': 2317, 'n_tokens_neox': 2243, 'n_words': 403}