├── .gitignore ├── LICENSE ├── Makefile ├── README.md ├── adminlb.tf ├── adminlb ├── Makefile ├── adminlb.conf ├── main.tf ├── output.tf └── variables.tf ├── dns.tf ├── dns ├── Makefile ├── main.tf └── variables.tf ├── elb.tf ├── elb ├── Makefile └── main.tf ├── firewall.tf ├── lb.tf ├── lb ├── Makefile ├── lb.conf ├── main.tf ├── output.tf └── variables.tf ├── master.tf ├── mesos_master ├── Makefile ├── main.tf ├── master.conf ├── output.tf └── variables.tf ├── mesos_slave ├── Makefile ├── main.tf ├── slave.conf └── variables.tf ├── output.tf ├── slave.tf └── variables.tf /.gitignore: -------------------------------------------------------------------------------- 1 | .idea/ 2 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "{}" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright {yyyy} {name of copyright owner} 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | 203 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | true 3 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Terraform AWS Mesos 2 | 3 | ## Module to set up a Mesos cluster on AWS using Terraform 4 | 5 | See my blog post for more detailed information / walkthrough: http://bobtfish.github.io/blog/2015/04/06/diy-scalable-paas-with-terraform/ 6 | 7 | ## Example Use 8 | 9 | Create a file `mesos.tf` containing something like this: 10 | 11 | module "mesos" { 12 | source = "github.com/bobtfish/tf_aws_mesos" 13 | slaves = "5" 14 | region = "${var.region}" 15 | admin_iprange = "${var.admin_iprange}" 16 | admin_key_name = "${aws_key_pair.admin.key_name}" 17 | private_subnet_ids = "${module.vpc.primary-az-ephemeralsubnet}" 18 | public_subnet_ids = "${module.vpc.primary-az-frontsubnet}" 19 | domain = "${var.domain}" 20 | vpc_id = "${module.vpc.id}" 21 | vpc_iprange = "${module.vpc.iprange}" 22 | discovery_instance_profile = "describe-instances" 23 | } 24 | 25 | See the `variables.tf` file for the available variables and their defaults 26 | 27 | ## Outputs 28 | 29 | * mesos_elb_dns_name - The DNS name of the externally facing ELB 30 | * mesos_elb_id - The AWS id of the externally facing ELB 31 | * marathon_api - The full URI for the marathon web interface / API 32 | * mesos_api - The full URI for the mesos web interface 33 | * domain - The domain under which applications can be requested 34 | 35 | ## Visit the web interfaces 36 | 37 | When the cluster is set up, you need to [retrieve the NS server records for your _domain_ from route53, and add delegations 38 | to this new subdomain from the domain you own (wherever that is managed): 39 | 40 | ![Route53 console](https://raw.githubusercontent.com/bobtfish/terraform-example-mesos-cluster/master/route53.png) 41 | 42 | After which, you should be able to visit the admin interfaces at: 43 | 44 | * mesos.admin.yoursubdomain 45 | * marathon.admin.yoursubdomain 46 | 47 | You can launch marathon apps using the API (or the web interface) as per [this guide](https://www.digitalocean.com/community/tutorials/how-to-configure-a-production-ready-mesosphere-cluster-on-ubuntu-14-04), and each app's PORT will be made available via HTTP at the name of the app. For example the marathon app named _/www_ becomes _www.yoursubdomain_ 48 | 49 | ## To do 50 | 51 | * Currently no way to retrieve the address of the DNS servers for the Route53 zone through Terraform. Use the Console to retrieve the addresses. 52 | * Cannot reach the log files of the Mesos slave nodes from the web interface 53 | * Whilst the cluster we build is redundant, currently all the machines are allocated in a single availability zone. 54 | * The machines have no configuration management (no puppet/chef), which means that making any changes to them (or getting any security updates) involves rebuilding the instances. 55 | 56 | ## Credits 57 | 58 | This module is based on the code from ContainerSolutions, and their excellent GCE howto: 59 | 60 | 61 | -------------------------------------------------------------------------------- /adminlb.tf: -------------------------------------------------------------------------------- 1 | 2 | module "adminlb" { 3 | source = "adminlb" 4 | security_group_http = "${aws_security_group.mesos_http_admin.id}" 5 | security_group_ssh = "${aws_security_group.mesos_ssh.id}" 6 | security_group_internal = "${aws_security_group.mesos_internal.id}" 7 | discovery_instance_profile = "${var.discovery_instance_profile}" 8 | count = "${var.adminlbs}" 9 | instance_type = "${var.adminlb_instance_type}" 10 | subnet_ids = "${var.public_subnet_ids}" 11 | admin_key_name = "${var.admin_key_name}" 12 | domain = "${var.domain}" 13 | region = "${var.region}" 14 | } 15 | 16 | -------------------------------------------------------------------------------- /adminlb/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | true 3 | -------------------------------------------------------------------------------- /adminlb/adminlb.conf: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | apt_sources: 3 | - source: "deb http://apt.puppetlabs.com trusty main" 4 | keyid: 1054b7a24bd6ec30 5 | - source: "deb http://repos.mesosphere.io/ubuntu trusty main" 6 | keyid: E56151BF 7 | apt_upgrade: true 8 | locale: en_US.UTF-8 9 | packages: 10 | - facter 11 | - mesosphere 12 | - python-pip 13 | - python-dev 14 | - nginx 15 | write_files: 16 | - path: /var/www/status 17 | permissions: '0644' 18 | content: "OK" 19 | - path: /root/install-zk_flock 20 | permissions: '0700' 21 | content: | 22 | #!/bin/sh 23 | cd /root 24 | git clone https://github.com/noxiouz/python-flock.git 25 | cd python-flock 26 | python setup.py install 27 | - path: /etc/cron.d/confnginx 28 | permissions: '0644' 29 | content: "*/5 * * * * root /root/confnginx.rb\n" 30 | - path: /etc/nginx/conf.d/mesos.conf 31 | permissions: '0644' 32 | content: "" 33 | - path: /etc/nginx/sites-available/default 34 | permissions: '0644' 35 | content: | 36 | server { 37 | listen 80 default_server; 38 | root /var/www/; 39 | allow all; 40 | rewrite ^/$ http://mesos.admin.__DOMAIN__/ redirect; 41 | } 42 | - path: /root/confnginx.rb 43 | permissions: '0700' 44 | content: | 45 | #!/usr/bin/ruby 46 | require 'json' 47 | exit 0 unless File.exists? '/etc/mesos/zk' 48 | 49 | exit 0 unless File.exists? '/etc/nginx_domain' 50 | 51 | domain = IO.read('/etc/nginx_domain').chomp 52 | 53 | az = `facter ec2_placement_availability_zone`.chomp 54 | region = az[0..-2] 55 | 56 | marathon_servers = JSON.parse(`/usr/local/bin/aws ec2 describe-instances --region #{region} --filters "Name=tag-key,Values=role" "Name=tag-value,Values=mesos-master" --query 'Reservations[].Instances[].[PrivateIpAddress][]'`).sort 57 | if !marathon_servers or marathon_servers.size == 0 58 | puts "Could not find any marathon servers" 59 | exit 0 60 | end 61 | 62 | mesos_master = `mesos-resolve zk://#{marathon_servers.map {|m| "#{m}:2181"}.join(",")}/mesos`.chomp 63 | if mesos_master == '' 64 | puts "Could not find mesos master" 65 | exit 0 66 | end 67 | 68 | File.open('/tmp/nginx-mesos.conf', 'w') do |f| 69 | f.puts 'upstream mesos_master {' 70 | f.puts " server #{mesos_master};" 71 | f.puts '}' 72 | f.puts 'server {' 73 | f.puts ' listen 80;' 74 | f.puts " server_name mesos.admin.#{domain};" 75 | f.puts ' location / {' 76 | f.puts ' allow all;' 77 | f.puts ' proxy_pass http://mesos_master;' 78 | f.puts ' }' 79 | f.puts '}' 80 | f.puts 'upstream marathon {' 81 | marathon_servers.each { |server| f.puts " server #{server}:8080;" } 82 | f.puts '}' 83 | f.puts 'server {' 84 | f.puts ' listen 80;' 85 | f.puts " server_name marathon.admin.#{domain};" 86 | f.puts ' location / {' 87 | f.puts ' allow all;' 88 | f.puts ' proxy_pass http://marathon;' 89 | f.puts ' }' 90 | f.puts '}' 91 | end 92 | if !system 'diff -u /etc/nginx/conf.d/mesos.conf /tmp/nginx-mesos.conf' 93 | File.rename '/tmp/nginx-mesos.conf', '/etc/nginx/conf.d/mesos.conf' 94 | 95 | system '/etc/init.d/nginx reload' 96 | else 97 | File.unlink '/tmp/nginx-mesos.conf' 98 | end 99 | runcmd: 100 | - [ mkdir, -p, /var/www ] 101 | - [ echo, manual, ">", /etc/init/mesos-slave.override ] 102 | - [ echo, manual, ">", /etc/init/zookeeper.override ] 103 | - [ echo, manual, ">", /etc/init/mesos-master.override ] 104 | - [ echo, manual, ">", /etc/init/marathon.override ] 105 | - [ /usr/bin/pip, install, awscli ] 106 | - [ /usr/bin/pip, install, zk_shell ] 107 | - [ /root/install-zk_flock ] 108 | - [ sh, -c, "echo __DOMAIN__ > /etc/nginx_domain" ] 109 | - [ sh, -c, "echo __CLUSTER_SIZE__ > /etc/zookeeper/conf/cluster_size" ] 110 | - [ stop, mesos-slave ] 111 | - [ stop, zookeeper ] 112 | - [ stop, mesos-master ] 113 | - [ stop, marathon ] 114 | - [ /etc/init.d/nginx, restart ] 115 | - [ /root/confnginx.rb ] 116 | 117 | -------------------------------------------------------------------------------- /adminlb/main.tf: -------------------------------------------------------------------------------- 1 | module "ami" { 2 | source = "github.com/terraform-community-modules/tf_aws_ubuntu_ami/ebs" 3 | region = "${var.region}" 4 | distribution = "trusty" 5 | instance_type = "${var.instance_type}" 6 | } 7 | 8 | resource "aws_instance" "adminlb" { 9 | associate_public_ip_address = true 10 | iam_instance_profile = "${var.discovery_instance_profile}" 11 | count = "${var.count}" 12 | ami = "${module.ami.ami_id}" 13 | instance_type = "${var.instance_type}" 14 | security_groups = [ "${var.security_group_http}", "${var.security_group_ssh}", "${var.security_group_internal}" ] 15 | subnet_id = "${element(split(\",\", var.subnet_ids), count.index)}" 16 | key_name = "${var.admin_key_name}" 17 | tags { 18 | Name = "adminlb-${count.index+1}" 19 | role = "adminlb" 20 | } 21 | user_data = "${replace(replace(file(\"${path.module}/adminlb.conf\"), \"__CLUSTER_SIZE__\", \"${var.count}\"), \"__DOMAIN__\", \"${var.domain}\")}" 22 | } 23 | 24 | -------------------------------------------------------------------------------- /adminlb/output.tf: -------------------------------------------------------------------------------- 1 | output "public_ips" { 2 | value = "${join(\",\", aws_instance.adminlb.*.public_ip)}" 3 | } 4 | output "instance_ids" { 5 | value = "${join(\",\", aws_instance.adminlb.*.id)}" 6 | } 7 | 8 | -------------------------------------------------------------------------------- /adminlb/variables.tf: -------------------------------------------------------------------------------- 1 | ## credential stuff 2 | variable "admin_key_name" {} 3 | variable "region" {} 4 | variable "instance_type" { 5 | default = "t2.micro" 6 | } 7 | variable "discovery_instance_profile" {} 8 | variable "subnet_ids" {} 9 | # domain name used by nginx 10 | variable "domain" {} 11 | 12 | variable "count" { 13 | default = "1" 14 | } 15 | variable "security_group_http" {} 16 | variable "security_group_ssh" {} 17 | variable "security_group_internal" {} 18 | 19 | -------------------------------------------------------------------------------- /dns.tf: -------------------------------------------------------------------------------- 1 | module "dns" { 2 | source = "dns/" 3 | domain = "${var.domain}" 4 | elb_name = "${module.elb.dns_name}" 5 | adminlb_public_ips = "${module.adminlb.public_ips}" 6 | } 7 | 8 | -------------------------------------------------------------------------------- /dns/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | true 3 | -------------------------------------------------------------------------------- /dns/main.tf: -------------------------------------------------------------------------------- 1 | resource "aws_route53_zone" "mesos" { 2 | name = "${var.domain}" 3 | } 4 | 5 | resource "aws_route53_record" "star" { 6 | zone_id = "${aws_route53_zone.mesos.zone_id}" 7 | name = "*.${var.domain}" 8 | type = "CNAME" 9 | ttl = "300" 10 | records = ["${var.elb_name}"] 11 | } 12 | 13 | resource "aws_route53_record" "mesos" { 14 | zone_id = "${aws_route53_zone.mesos.zone_id}" 15 | name = "mesos.admin.${var.domain}" 16 | type = "A" 17 | ttl = "300" 18 | records = ["${split(\",\", var.adminlb_public_ips)}"] 19 | } 20 | 21 | resource "aws_route53_record" "marathon" { 22 | zone_id = "${aws_route53_zone.mesos.zone_id}" 23 | name = "marathon.admin.${var.domain}" 24 | type = "A" 25 | ttl = "300" 26 | records = ["${split(\",\", var.adminlb_public_ips)}"] 27 | } 28 | 29 | -------------------------------------------------------------------------------- /dns/variables.tf: -------------------------------------------------------------------------------- 1 | variable "elb_name" {} 2 | variable "domain" {} 3 | variable "adminlb_public_ips" {} 4 | 5 | -------------------------------------------------------------------------------- /elb.tf: -------------------------------------------------------------------------------- 1 | module "elb" { 2 | source = "elb/" 3 | instance_ids = "${module.lb.instance_ids}" 4 | subnet_ids = "${var.public_subnet_ids}" 5 | security_group_ids = "${aws_security_group.mesos_http_all.id}" 6 | } 7 | 8 | -------------------------------------------------------------------------------- /elb/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | true 3 | -------------------------------------------------------------------------------- /elb/main.tf: -------------------------------------------------------------------------------- 1 | variable "instance_ids" {} 2 | variable "subnet_ids" {} 3 | variable "security_group_ids" {} 4 | 5 | resource "aws_elb" "mesos" { 6 | name = "mesos-elb" 7 | internal = false 8 | subnets = [ "${split(\",\", var.subnet_ids)}" ] 9 | security_groups = [ "${split(\",\", var.security_group_ids)}" ] 10 | listener { 11 | instance_port = 80 12 | instance_protocol = "http" 13 | lb_port = 80 14 | lb_protocol = "http" 15 | } 16 | 17 | health_check { 18 | healthy_threshold = 2 19 | unhealthy_threshold = 2 20 | timeout = 3 21 | target = "HTTP:80/status" 22 | interval = 30 23 | } 24 | 25 | instances = ["${split(\",\", var.instance_ids)}"] 26 | cross_zone_load_balancing = true 27 | } 28 | 29 | output "dns_name" { 30 | value = "${aws_elb.mesos.dns_name}" 31 | } 32 | 33 | output "id" { 34 | value = "${aws_elb.mesos.id}" 35 | } 36 | 37 | -------------------------------------------------------------------------------- /firewall.tf: -------------------------------------------------------------------------------- 1 | resource "aws_security_group" "mesos_internal" { 2 | name = "mesos-${var.domain}-internal_allow_all" 3 | description = "Allow all inbound traffic" 4 | vpc_id = "${var.vpc_id}" 5 | ingress { 6 | from_port = 0 7 | to_port = 65535 8 | protocol = "-1" 9 | self = true 10 | } 11 | 12 | tags { 13 | Name = "mesos-${var.domain}-internal_allow_all" 14 | } 15 | } 16 | 17 | resource "aws_security_group" "mesos_http_all" { 18 | name = "mesos-${var.domain}-http_all" 19 | description = "Allow all inbound HTTP traffic" 20 | vpc_id = "${var.vpc_id}" 21 | ingress { 22 | from_port = 80 23 | to_port = 80 24 | protocol = "tcp" 25 | cidr_blocks = ["0.0.0.0/0"] 26 | } 27 | 28 | tags { 29 | Name = "mesos-${var.domain}-http_all" 30 | } 31 | } 32 | 33 | resource "aws_security_group" "mesos_http_admin" { 34 | name = "mesos-${var.domain}-http_admin" 35 | description = "Allow inbound HTTP traffic from admin IP range" 36 | vpc_id = "${var.vpc_id}" 37 | ingress { 38 | from_port = 80 39 | to_port = 80 40 | protocol = "tcp" 41 | cidr_blocks = ["${var.admin_iprange}"] 42 | } 43 | 44 | tags { 45 | Name = "mesos-${var.domain}-http_admin" 46 | } 47 | } 48 | 49 | 50 | resource "aws_security_group" "mesos_ssh" { 51 | name = "mesos-${var.domain}-ssh" 52 | description = "Allow all inbound SSH traffic" 53 | vpc_id = "${var.vpc_id}" 54 | ingress { 55 | from_port = 22 56 | to_port = 22 57 | protocol = "tcp" 58 | cidr_blocks = ["${var.admin_iprange}", "${var.vpc_iprange}"] 59 | } 60 | 61 | tags { 62 | Name = "mesos-${var.domain}-ssh" 63 | } 64 | } 65 | 66 | -------------------------------------------------------------------------------- /lb.tf: -------------------------------------------------------------------------------- 1 | 2 | module "lb" { 3 | source = "lb" 4 | security_group_http = "${aws_security_group.mesos_http_all.id}" 5 | security_group_ssh = "${aws_security_group.mesos_ssh.id}" 6 | security_group_internal = "${aws_security_group.mesos_internal.id}" 7 | subnet_ids = "${var.private_subnet_ids}" 8 | discovery_instance_profile = "${var.discovery_instance_profile}" 9 | count = "${var.lbs}" 10 | instance_type = "${var.lb_instance_type}" 11 | admin_key_name = "${var.admin_key_name}" 12 | domain = "${var.domain}" 13 | region = "${var.region}" 14 | } 15 | 16 | -------------------------------------------------------------------------------- /lb/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | true 3 | -------------------------------------------------------------------------------- /lb/lb.conf: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | apt_sources: 3 | - source: "deb http://apt.puppetlabs.com trusty main" 4 | keyid: 1054b7a24bd6ec30 5 | - source: "deb http://repos.mesosphere.io/ubuntu trusty main" 6 | keyid: E56151BF 7 | apt_upgrade: true 8 | locale: en_US.UTF-8 9 | packages: 10 | - facter 11 | - mesosphere 12 | - python-pip 13 | - python-dev 14 | - nginx 15 | write_files: 16 | - path: /var/www/status 17 | permissions: '0644' 18 | content: "OK" 19 | - path: /root/install-zk_flock 20 | permissions: '0700' 21 | content: | 22 | #!/bin/sh 23 | cd /root 24 | git clone https://github.com/noxiouz/python-flock.git 25 | cd python-flock 26 | python setup.py install 27 | - path: /etc/cron.d/confnginx 28 | permissions: '0644' 29 | content: "* * * * * root /root/confnginx.rb\n" 30 | - path: /etc/nginx/conf.d/mesos.conf 31 | permissions: '0644' 32 | content: "" 33 | - path: /etc/nginx/sites-available/default 34 | permissions: '0644' 35 | content: | 36 | server { 37 | listen 80 default_server; 38 | root /var/www/; 39 | allow all; 40 | rewrite ^/$ http://www.__DOMAIN__/ redirect; 41 | } 42 | - path: /root/confnginx.rb 43 | permissions: '0700' 44 | content: | 45 | #!/usr/bin/ruby 46 | require 'json' 47 | exit 0 unless File.exists? '/etc/mesos/zk' 48 | 49 | exit 0 unless File.exists? '/etc/nginx_domain' 50 | 51 | domain = IO.read('/etc/nginx_domain').chomp 52 | 53 | az = `facter ec2_placement_availability_zone`.chomp 54 | region = az[0..-2] 55 | 56 | marathon_servers = JSON.parse(`/usr/local/bin/aws ec2 describe-instances --region #{region} --filters "Name=tag-key,Values=role" "Name=tag-value,Values=mesos-master" --query 'Reservations[].Instances[].[PrivateIpAddress][]'`).sort 57 | if !marathon_servers or marathon_servers.size == 0 58 | puts "Could not find any marathon servers" 59 | exit 0 60 | end 61 | 62 | app_upstreams = {} 63 | apps = JSON.parse(`curl http://#{marathon_servers[0]}:8080/v2/apps/ 2>/dev/null`)['apps'].map { |app| app['id'].gsub('/', '') } 64 | apps.each do |app| 65 | next if app == 'mesos_master' 66 | next if app == 'marathon' 67 | next if app == 'admin' 68 | next unless app.match /^(\w+)$/ 69 | backends = `curl http://#{marathon_servers[0]}:8080/v2/apps/#{app}/tasks 2>/dev/null`.split(/\s+/)[2..-1] 70 | app_upstreams[app] = backends.sort 71 | end 72 | 73 | File.open('/tmp/nginx-mesos.conf', 'w') do |f| 74 | app_upstreams.keys.sort.each do |app| 75 | next if app_upstreams[app].size == 0 76 | f.puts "upstream #{app} {" 77 | app_upstreams[app].each { |server| f.puts " server #{server};" } 78 | f.puts '}' 79 | f.puts 'server {' 80 | f.puts ' listen 80;' 81 | f.puts " server_name #{app}.#{domain};" 82 | f.puts ' location / {' 83 | f.puts ' allow all;' 84 | f.puts " proxy_pass http://#{app};" 85 | f.puts ' }' 86 | f.puts '}' 87 | end 88 | end 89 | if !system 'diff -u /etc/nginx/conf.d/mesos.conf /tmp/nginx-mesos.conf' 90 | File.rename '/tmp/nginx-mesos.conf', '/etc/nginx/conf.d/mesos.conf' 91 | 92 | system '/etc/init.d/nginx reload' 93 | else 94 | File.unlink '/tmp/nginx-mesos.conf' 95 | end 96 | - path: /root/setupzkclient.rb 97 | permissions: '0700' 98 | content: | 99 | #!/usr/bin/ruby 100 | require 'json' 101 | 102 | cluster_size = 0 103 | File.open('/etc/zookeeper/conf/cluster_size', 'r') { |f| cluster_size = f.read.chomp.to_i } 104 | 105 | zk_servers = [] 106 | while zk_servers.size < cluster_size 107 | zk_servers = JSON.parse(`/usr/local/bin/aws ec2 describe-instances --region eu-central-1 --filters "Name=tag-key,Values=role" "Name=tag-value,Values=mesos-master" --query 'Reservations[].Instances[].[PrivateIpAddress][]'`).sort 108 | end 109 | 110 | myip = `facter ipaddress_eth0`.chomp 111 | 112 | zk_servers = zk_servers.map { |s| "#{s}:2181" } 113 | 114 | File.open('/etc/mesos/zk', 'w') do |f| 115 | f.puts "zk://#{zk_servers.join(',')}/mesos" 116 | end 117 | runcmd: 118 | - [ mkdir, -p, /var/www ] 119 | - [ echo, manual, ">", /etc/init/mesos-slave.override ] 120 | - [ echo, manual, ">", /etc/init/mesos-master.override ] 121 | - [ echo, manual, ">", /etc/init/zookeeper.override ] 122 | - [ echo, manual, ">", /etc/init/marathon.override ] 123 | - [ /usr/bin/pip, install, awscli ] 124 | - [ /usr/bin/pip, install, zk_shell ] 125 | - [ /root/install-zk_flock ] 126 | - [ sh, -c, "echo __ZOOKEEPER_CLUSTER_SIZE__ > /etc/zookeeper/conf/cluster_size" ] 127 | - [ sh, -c, "echo __DOMAIN__ > /etc/nginx_domain" ] 128 | - [ /root/setupzkclient.rb ] 129 | - [ stop, mesos-slave ] 130 | - [ stop, zookeeper ] 131 | - [ stop, mesos-master ] 132 | - [ stop, marathon ] 133 | - [ /etc/init.d/nginx, restart ] 134 | 135 | -------------------------------------------------------------------------------- /lb/main.tf: -------------------------------------------------------------------------------- 1 | module "ami" { 2 | source = "github.com/terraform-community-modules/tf_aws_ubuntu_ami/ebs" 3 | region = "${var.region}" 4 | distribution = "trusty" 5 | instance_type = "${var.instance_type}" 6 | } 7 | 8 | resource "aws_instance" "lb" { 9 | associate_public_ip_address = false 10 | iam_instance_profile = "${var.discovery_instance_profile}" 11 | count = "${var.count}" 12 | ami = "${module.ami.ami_id}" 13 | instance_type = "${var.instance_type}" 14 | security_groups = [ "${var.security_group_http}", "${var.security_group_ssh}", "${var.security_group_internal}" ] 15 | subnet_id = "${element(split(\",\", var.subnet_ids), count.index)}" 16 | key_name = "${var.admin_key_name}" 17 | tags { 18 | Name = "lb-${count.index+1}" 19 | role = "lb" 20 | } 21 | user_data = "${replace(replace(file(\"${path.module}/lb.conf\"), \"__CLUSTER_SIZE__\", \"${var.count}\"), \"__DOMAIN__\", \"${var.domain}\")}" 22 | } 23 | 24 | -------------------------------------------------------------------------------- /lb/output.tf: -------------------------------------------------------------------------------- 1 | output "instance_ids" { 2 | value = "${join(\",\", aws_instance.lb.*.id)}" 3 | } 4 | 5 | -------------------------------------------------------------------------------- /lb/variables.tf: -------------------------------------------------------------------------------- 1 | ## credential stuff 2 | variable "admin_key_name" {} 3 | variable "region" {} 4 | variable "instance_type" { 5 | default = "m3.large" 6 | } 7 | variable "discovery_instance_profile" {} 8 | variable "subnet_ids" {} 9 | variable "domain" {} 10 | variable "count" { 11 | default = "2" 12 | } 13 | variable "security_group_http" {} 14 | variable "security_group_ssh" {} 15 | variable "security_group_internal" {} 16 | 17 | -------------------------------------------------------------------------------- /master.tf: -------------------------------------------------------------------------------- 1 | 2 | module "mesos_master" { 3 | source = "mesos_master" 4 | security_group_ssh = "${aws_security_group.mesos_ssh.id}" 5 | security_group_internal = "${aws_security_group.mesos_internal.id}" 6 | discovery_instance_profile = "${var.discovery_instance_profile}" 7 | subnet_ids = "${var.private_subnet_ids}" 8 | count = "${var.masters}" 9 | instance_type = "${var.master_instance_type}" 10 | admin_key_name = "${var.admin_key_name}" 11 | region = "${var.region}" 12 | } 13 | 14 | -------------------------------------------------------------------------------- /mesos_master/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | true 3 | -------------------------------------------------------------------------------- /mesos_master/main.tf: -------------------------------------------------------------------------------- 1 | module "ami" { 2 | source = "github.com/terraform-community-modules/tf_aws_ubuntu_ami/ebs" 3 | region = "${var.region}" 4 | distribution = "trusty" 5 | instance_type = "${var.instance_type}" 6 | } 7 | 8 | resource "aws_instance" "mesos_master" { 9 | associate_public_ip_address = false 10 | iam_instance_profile = "${var.discovery_instance_profile}" 11 | count = "${var.count}" 12 | ami = "${module.ami.ami_id}" 13 | instance_type = "${var.instance_type}" 14 | security_groups = [ "${var.security_group_ssh}", "${var.security_group_internal}" ] 15 | subnet_id = "${element(split(\",\", var.subnet_ids), count.index)}" 16 | key_name = "${var.admin_key_name}" 17 | tags { 18 | Name = "mesos-master-${count.index+1}" 19 | role = "mesos-master" 20 | } 21 | user_data = "${replace(file(\"${path.module}/master.conf\"), \"__CLUSTER_SIZE__\", \"${var.count}\")}" 22 | } 23 | 24 | -------------------------------------------------------------------------------- /mesos_master/master.conf: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | apt_sources: 3 | - source: "deb http://apt.puppetlabs.com trusty main" 4 | keyid: 1054b7a24bd6ec30 5 | - source: "deb http://repos.mesosphere.io/ubuntu trusty main" 6 | keyid: E56151BF 7 | apt_upgrade: true 8 | locale: en_US.UTF-8 9 | packages: 10 | - facter 11 | - mesosphere 12 | - python-pip 13 | - python-dev 14 | write_files: 15 | - path: /root/install-zk_flock 16 | permissions: '0700' 17 | content: | 18 | #!/bin/sh 19 | cd /root 20 | git clone https://github.com/noxiouz/python-flock.git 21 | cd python-flock 22 | python setup.py install 23 | - path: /etc/default/marathon 24 | permissions: '0644' 25 | content: "MARATHON_TASK_LAUNCH_TIMEOUT=300000\n" 26 | - path: /root/setupmaster.rb 27 | permissions: '0700' 28 | content: | 29 | #!/usr/bin/ruby 30 | require 'json' 31 | 32 | cluster_size = 0 33 | File.open('/etc/zookeeper/conf/cluster_size', 'r') { |f| cluster_size = f.read.chomp.to_i } 34 | 35 | zk_servers = [] 36 | while zk_servers.size < cluster_size 37 | zk_servers = JSON.parse(`/usr/local/bin/aws ec2 describe-instances --region eu-central-1 --filters "Name=tag-key,Values=role" "Name=tag-value,Values=mesos-master" --query 'Reservations[].Instances[].[PrivateIpAddress][]'`).sort 38 | end 39 | 40 | myip = `facter ipaddress_eth0`.chomp 41 | 42 | File.open('/etc/zookeeper/conf/zoo.cfg', 'a') do |f| 43 | count = 1 44 | zk_servers.each do |server| 45 | f.puts "server.#{count}=#{server}:2888:3888" 46 | if server.match(myip) 47 | File.open('/etc/zookeeper/conf/myid', 'w') { |z| z.puts count } 48 | end 49 | count = count +1 50 | end 51 | end 52 | 53 | zk_servers = zk_servers.map { |s| "#{s}:2181" } 54 | 55 | File.open('/etc/mesos/zk', 'w') do |f| 56 | f.puts "zk://#{zk_servers.join(',')}/mesos" 57 | end 58 | File.open('/etc/marathon/conf/zk', 'w') do |f| 59 | f.puts "zk://#{zk_servers.join(',')}/marathon" 60 | end 61 | 62 | File.open('/etc/mesos-master/quorum', 'w') do |f| 63 | f.puts (cluster_size / 2).to_int + 1 64 | end 65 | runcmd: 66 | - [ echo, manual, ">", /etc/init/mesos-slave.override ] 67 | - [ /usr/bin/pip, install, awscli ] 68 | - [ /usr/bin/pip, install, zk_shell ] 69 | - [ /root/install-zk_flock ] 70 | - [ sh, -c, "echo __CLUSTER_SIZE__ > /etc/zookeeper/conf/cluster_size" ] 71 | - [ mkdir, -p, /etc/marathon/store ] 72 | - [ mkdir, -p, /etc/marathon/conf ] 73 | - [ sh, -c, "echo file:///etc/marathon/store > /etc/marathon/conf/artifact_store" ] 74 | - [ /root/setupmaster.rb ] 75 | - [ stop, mesos-slave ] 76 | - [ restart, zookeeper ] 77 | - [ start, mesos-master ] 78 | - [ start, marathon ] 79 | 80 | -------------------------------------------------------------------------------- /mesos_master/output.tf: -------------------------------------------------------------------------------- 1 | output "public_ips" { 2 | value = "${join(\",\", aws_instance.mesos_master.*.public_ip)}" 3 | } 4 | output "instance_ids" { 5 | value = "${join(\",\", aws_instance.mesos_master.*.id)}" 6 | } 7 | 8 | -------------------------------------------------------------------------------- /mesos_master/variables.tf: -------------------------------------------------------------------------------- 1 | ## credential stuff 2 | variable "admin_key_name" {} 3 | variable "region" {} 4 | variable "instance_type" { 5 | default = "m3.large" 6 | } 7 | variable "discovery_instance_profile" {} 8 | variable "subnet_ids" {} 9 | 10 | ## mesos stuff 11 | # the name of the cluster 12 | # number of master nodes to install 13 | variable "count" { 14 | default = "3" 15 | } 16 | variable "security_group_ssh" {} 17 | variable "security_group_internal" {} 18 | 19 | -------------------------------------------------------------------------------- /mesos_slave/Makefile: -------------------------------------------------------------------------------- 1 | all: 2 | true 3 | -------------------------------------------------------------------------------- /mesos_slave/main.tf: -------------------------------------------------------------------------------- 1 | module "ami" { 2 | source = "github.com/terraform-community-modules/tf_aws_ubuntu_ami/ebs" 3 | region = "${var.region}" 4 | distribution = "trusty" 5 | instance_type = "${var.instance_type}" 6 | } 7 | 8 | resource "aws_instance" "mesos_slave" { 9 | associate_public_ip_address = false 10 | iam_instance_profile = "${var.discovery_instance_profile}" 11 | count = "${var.count}" 12 | ami = "${module.ami.ami_id}" 13 | instance_type = "${var.instance_type}" 14 | security_groups = [ "${var.security_group_ssh}", "${var.security_group_internal}" ] 15 | subnet_id = "${element(split(\",\", var.subnet_ids), count.index)}" 16 | key_name = "${var.admin_key_name}" 17 | # FIXME - disk size here! 18 | tags { 19 | Name = "mesos-slave-${count.index+1}" 20 | role = "mesos-slave" 21 | } 22 | user_data = "${replace(file(\"${path.module}/slave.conf\"), \"__ZOOKEEPER_CLUSTER_SIZE__\", \"${var.zookeeper_cluster_size}\")}" 23 | } 24 | -------------------------------------------------------------------------------- /mesos_slave/slave.conf: -------------------------------------------------------------------------------- 1 | #cloud-config 2 | apt_sources: 3 | - source: "deb https://get.docker.io/ubuntu docker main" 4 | keyid: 36A1D7869245C8950F966E92D8576A8BA88D21E9 5 | - source: "deb http://apt.puppetlabs.com trusty main" 6 | keyid: 1054b7a24bd6ec30 7 | - source: "deb http://repos.mesosphere.io/ubuntu trusty main" 8 | keyid: E56151BF 9 | apt_upgrade: true 10 | locale: en_US.UTF-8 11 | packages: 12 | - lxc-docker 13 | - facter 14 | - mesos 15 | - git 16 | - python-pip 17 | - unzip 18 | - python-dev 19 | write_files: 20 | - path: /tmp/install-zk_flock 21 | permissions: '0700' 22 | content: | 23 | #!/bin/sh 24 | set -e 25 | cd /tmp 26 | git clone https://github.com/noxiouz/python-flock.git 27 | cd python-flock 28 | python setup.py install 29 | cd / 30 | rm -rf /tmp/install-zk_flock /tmp/python-flock 31 | - path: /etc/cron.d/check_masters 32 | permissions: '0644' 33 | content: "*/5 * * * * /root/setupslave.rb cron\n" 34 | - path: /root/setupslave.rb 35 | permissions: '0700' 36 | content: | 37 | #!/usr/bin/ruby 38 | require 'json' 39 | 40 | mode = ARGV[0] 41 | raise("Unknown mode '#{mode}'") if mode != 'cron' and mode != 'boot' 42 | 43 | cluster_size = 0 44 | File.open('/etc/zookeeper/conf/cluster_size', 'r') { |f| cluster_size = f.read.chomp.to_i } 45 | quorum = (cluster_size/2).to_int + 1 46 | 47 | wait_size = cluster_size 48 | if mode == 'cron' 49 | wait_size = quorum 50 | end 51 | 52 | zk_servers = [] 53 | while zk_servers.size < wait_size 54 | zk_servers = begin 55 | JSON.parse(`/usr/local/bin/aws ec2 describe-instances --region eu-central-1 --filters "Name=tag-key,Values=role" "Name=tag-value,Values=mesos-master" --query 'Reservations[].Instances[].[PrivateIpAddress][]'`).sort.map { |s| "#{s}:2181" } 56 | rescue 57 | end 58 | sleep 10 if zk_servers.size < wait_size 59 | end 60 | 61 | File.open('/tmp/zk', 'w') do |f| 62 | f.puts "zk://#{zk_servers.join(',')}/mesos" 63 | end 64 | zk_flock_conf = { 65 | "host" => zk_servers, 66 | "timeout" => 120, 67 | "app_id" => "zk_flock", 68 | "sleep" => "OFF", 69 | "logger" => { "path" => "/tmp/zkflock.log", "level" => "INFO","zklevel" => "ERROR" } 70 | } 71 | File.open('/tmp/distributed-flock.json', 'w') do |f| 72 | f.puts JSON.pretty_generate zk_flock_conf 73 | end 74 | if mode == 'boot' 75 | File.rename '/tmp/zk', '/etc/mesos/zk' 76 | else 77 | if !system 'diff -u /etc/mesos/zk /tmp/zk' 78 | File.rename '/tmp/distributed-flock.json', '/etc/distributed-flock.json' 79 | File.rename '/tmp/zk', '/etc/mesos/zk' 80 | system 'zk-flock mesos-slave-restart "sh -c \'/sbin/initctl restart mesos-slave;sleep 120\'"' 81 | end 82 | end 83 | runcmd: 84 | - [ /usr/bin/pip, install, awscli ] 85 | - [ /usr/bin/pip, install, zk_shell ] 86 | - [ /tmp/install-zk_flock ] 87 | - [ stop, zookeeper ] 88 | - [ stop, mesos-master ] 89 | - [ mkdir, -p, /etc/zookeeper/conf/ ] 90 | - [ sh, -c, "echo __ZOOKEEPER_CLUSTER_SIZE__ > /etc/zookeeper/conf/cluster_size" ] 91 | - [ sh, -c, "echo manual > /etc/init/zookeeper.override" ] 92 | - [ sh, -c, "echo manual > /etc/init/mesos-master.override" ] 93 | - [ /root/setupslave.rb, boot ] 94 | - [ sh, -c, "echo 'docker,mesos' > /etc/mesos-slave/containerizers" ] 95 | - [ sh, -c, "echo '5mins' > /etc/mesos-slave/executor_registration_timeout" ] 96 | - [ sh, -c, "echo $(facter ipaddress_eth0) > /etc/mesos-slave/hostname" ] 97 | - [ sh, -c, "echo $(facter ipaddress_eth0) > /etc/mesos-slave/ip" ] 98 | - [ start, mesos-slave ] 99 | 100 | -------------------------------------------------------------------------------- /mesos_slave/variables.tf: -------------------------------------------------------------------------------- 1 | ## credential stuff 2 | variable "security_group_internal" {} 3 | variable "security_group_ssh" {} 4 | variable "zookeeper_cluster_size" {} 5 | variable "admin_key_name" {} 6 | variable "region" {} 7 | variable "discovery_instance_profile" {} 8 | variable "instance_type" { 9 | default = "m3.medium" 10 | } 11 | variable "subnet_ids" {} 12 | 13 | # number of slaves to install 14 | variable "count" { 15 | default = "3" 16 | } 17 | variable "zookeeper_cluster_size" {} 18 | 19 | -------------------------------------------------------------------------------- /output.tf: -------------------------------------------------------------------------------- 1 | output "mesos_elb_dns_name" { 2 | value = "${module.elb.dns_name}" 3 | } 4 | output "mesos_elb_id" { 5 | value = "${module.elb.id}" 6 | } 7 | output "marathon_api" { 8 | value = "http://marathon.admin.${var.domain}" 9 | } 10 | output "mesos_api" { 11 | value = "http://mesos.admin.${var.domain}" 12 | } 13 | output "domain" { 14 | value = "${var.domain}" 15 | } 16 | 17 | -------------------------------------------------------------------------------- /slave.tf: -------------------------------------------------------------------------------- 1 | module "mesos_slave" { 2 | source = "mesos_slave" 3 | discovery_instance_profile = "${var.discovery_instance_profile}" 4 | count = "${var.slaves}" 5 | instance_type = "${var.slave_instance_type}" 6 | subnet_ids = "${var.private_subnet_ids}" 7 | security_group_ssh = "${aws_security_group.mesos_ssh.id}" 8 | security_group_internal = "${aws_security_group.mesos_internal.id}" 9 | admin_key_name = "${var.admin_key_name}" 10 | zookeeper_cluster_size = "${var.masters}" 11 | region = "${var.region}" 12 | } 13 | 14 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | ## credential stuff 2 | variable "domain" {} 3 | variable "admin_key_name" {} 4 | variable "region" {} 5 | variable "vpc_id" {} 6 | variable "admin_iprange" {} 7 | variable "vpc_iprange" { 8 | default = "0.0.0.0/0" 9 | } 10 | variable "adminlb_instance_type" { 11 | default = "t2.micro" 12 | } 13 | variable "lb_instance_type" { 14 | default = "t2.micro" 15 | } 16 | variable "master_instance_type" { 17 | default = "t2.micro" 18 | } 19 | variable "discovery_instance_profile" {} 20 | variable "slave_instance_type" { 21 | default = "t2.micro" 22 | } 23 | variable "private_subnet_ids" {} 24 | variable "public_subnet_ids" {} 25 | variable "domain" {} 26 | variable "adminlbs" { 27 | default = "1" 28 | } 29 | variable "lbs" { 30 | default = "2" 31 | } 32 | variable "masters" { 33 | default = "3" 34 | } 35 | # number of slaves to install 36 | variable "slaves" { 37 | default = "3" 38 | } 39 | 40 | 41 | --------------------------------------------------------------------------------