Created
October 9, 2015 16:31
-
-
Save adamenger/9ea845f113637d5d4c61 to your computer and use it in GitHub Desktop.
terraform staging example
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
variable "user_home" {} | |
variable "db_pass" {} | |
provider "aws" { | |
region = "us-east-1" | |
} | |
resource "aws_elb" "example" { | |
name = "example" | |
listener { | |
instance_port = 80 | |
instance_protocol = "http" | |
lb_port = 80 | |
lb_protocol = "http" | |
} | |
listener { | |
instance_port = 8080 | |
instance_protocol = "http" | |
lb_port = 443 | |
lb_protocol = "https" | |
ssl_certificate_id = "arn:aws:iam::123456:server-certificate/WildCardCert" | |
} | |
health_check { | |
healthy_threshold = 2 | |
unhealthy_threshold = 2 | |
timeout = 3 | |
target = "HTTP:8080/" | |
interval = 5 | |
} | |
internal = true | |
subnets = ["subnet-123456"] | |
instances = ["${aws_instance.example.*.id}"] | |
cross_zone_load_balancing = true | |
idle_timeout = 400 | |
connection_draining = true | |
connection_draining_timeout = 400 | |
security_groups = ["sg-12345"] | |
tags { | |
Name = "example" | |
} | |
} | |
resource "aws_route53_record" "example" { | |
zone_id = "your-zone-here" | |
name = "example.reverb.com" | |
type = "CNAME" | |
ttl = "300" | |
records = ["${aws_elb.example.dns_name}"] | |
} | |
resource "aws_instance" "example" { | |
count = 1 | |
ami = "ami-123456" | |
availability_zone = "us-east-1a" | |
instance_type = "m3.large" | |
vpc_security_group_ids = ["sg-123456"] | |
subnet_id = "subnet-123456" | |
key_name = "staging" | |
iam_instance_profile = "staging" | |
root_block_device { | |
volume_size = "100" | |
} | |
tags { | |
Name = "example" | |
} | |
provisioner "chef" { | |
connection { | |
user = "reverb" | |
key_file = "${var.user_home}/.ssh/id_rsa" | |
} | |
attributes { | |
"reverb-core" { | |
"config" { | |
"database_host" = "${aws_db_instance.example.address}" | |
"database_password" = "${var.db_pass}" | |
"redis_host" = "${aws_elasticache_cluster.example.cache_nodes.0.address}" | |
} | |
} | |
} | |
environment = "example" | |
run_list = ["role[base]", "role[nginx]", "role[core]", "role[elasticsearch]", "role[worker]"] | |
node_name = "example" | |
secret_key_path = "/etc/chef/encrypted_data_bag_secret" | |
server_url = "https://your-chef-server.com" | |
validation_client_name = "chef-validator" | |
validation_key_path = "~/.chef/chef-validator.pem" | |
version = "11.16.4" | |
} | |
} | |
resource "aws_elasticache_cluster" "example" { | |
cluster_id = "example" | |
engine = "redis" | |
subnet_group_name = "staging" | |
security_group_ids = ["sg-123456"] | |
node_type = "cache.m1.small" | |
port = 6379 | |
num_cache_nodes = 1 | |
parameter_group_name = "default.redis2.8" | |
} | |
resource "aws_db_instance" "example" { | |
identifier = "example" | |
allocated_storage = 10 | |
engine = "postgres" | |
engine_version = "9.3.6" | |
instance_class = "db.t2.medium" | |
name = "staging" | |
username = "reverb" | |
password = "${var.db_pass}" | |
db_subnet_group_name = "staging-rds" | |
parameter_group_name = "default.postgres9.3" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment