├── .gitignore ├── LICENSE.md ├── NOTICE ├── README.md ├── bosh-init-tf ├── README.md ├── destroy_openstack_env.sh ├── generate_ssh_keypair.sh ├── network-outputs.tf ├── network-vars.tf ├── network.tf ├── provider-vars.tf ├── provider.tf ├── resources-outputs.tf ├── resources-vars.tf ├── resources.tf └── terraform.tfvars.template └── cf-deployment-tf ├── README.md ├── cf.tf └── terraform.tfvars.template /.gitignore: -------------------------------------------------------------------------------- 1 | terraform.tfvars 2 | *.tfstate 3 | *.tfstate.backup 4 | .idea -------------------------------------------------------------------------------- /LICENSE.md: -------------------------------------------------------------------------------- 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 | -------------------------------------------------------------------------------- /NOTICE: -------------------------------------------------------------------------------- 1 | bosh-openstack-environment-templates 2 | 3 | Copyright (c) 2016-Present CloudFoundry.org Foundation, Inc. All Rights Reserved. 4 | 5 | Licensed under the Apache License, Version 2.0 (the "License"); 6 | you may not use this file except in compliance with the License. 7 | You may obtain a copy of the License at 8 | 9 | http://www.apache.org/licenses/LICENSE-2.0 10 | 11 | Unless required by applicable law or agreed to in writing, software 12 | distributed under the License is distributed on an "AS IS" BASIS, 13 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 14 | See the License for the specific language governing permissions and 15 | limitations under the License. 16 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # bosh-openstack-environment-templates 2 | 3 | - [Terraform template](bosh-init-tf) to automate the manual steps described at [bosh.io](http://bosh.io/docs/init-openstack.html#prepare-openstack) 4 | -------------------------------------------------------------------------------- /bosh-init-tf/README.md: -------------------------------------------------------------------------------- 1 | ### Prepare an OpenStack environment 2 | 3 | Prerequisite: Install [terraform](https://www.terraform.io/intro/getting-started/install.html) >= 0.8.7 4 | 5 | 1. Clone `git clone https://github.com/cloudfoundry-incubator/bosh-openstack-environment-templates.git` 6 | 1. Create a working directory 7 | 1. Copy `bosh-init-tf/terraform.tfvars.template` to `/terraform.tfvars` 8 | 1. Execute `bosh-init-tf/generate_ssh_keypair.sh` to generate a key pair. 9 | 1. Move the generated key pairs to `` 10 | 1. Navigate to `` 11 | 1. Configure `terraform.tfvars` 12 | 1. Execute `terraform init /bosh-init-tf` 13 | 1. Execute `terraform apply /bosh-init-tf` 14 | 15 | The terraform scripts will output the OpenStack resource information required for the BOSH manifest. 16 | Make sure to treat the created `terraform.tfstate` files with care. 17 | 18 | ### Delete the OpenStack environment 19 | 20 | If you have the `terraform.tfstate` file available `destroy_openstack_env.sh` will 21 | destroy the created resources. 22 | 23 | *NOTE:* The template uses Keystone V3 24 | -------------------------------------------------------------------------------- /bosh-init-tf/destroy_openstack_env.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eu 3 | 4 | terraform destroy 5 | 6 | echo Should the key pair be deleted? 7 | select yn in "Yes" "No"; do 8 | case $yn in 9 | Yes ) rm bosh.pem bosh.pub ; break;; 10 | No ) exit 0;; 11 | esac 12 | done 13 | -------------------------------------------------------------------------------- /bosh-init-tf/generate_ssh_keypair.sh: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | set -eu 3 | 4 | green() { 5 | echo -e "\033[0;32m${@}\033[0m" 6 | } 7 | 8 | red() { 9 | echo -e "\033[0;31m${@}\033[0m" 10 | } 11 | 12 | # abort if a key pair already exists 13 | [[ -e "bosh.pem" ]] && red "Found key. Aborting!" && exit 1 14 | [[ -e "bosh.pub" ]] && red "Found key. Aborting!" && exit 1 15 | 16 | # create new key pair 17 | ssh-keygen -t rsa -b 4096 -C "bosh" -N "" -f "bosh.pem" 18 | mv bosh.pem.pub bosh.pub 19 | 20 | # finally inform user about successful completion 21 | green "Key pair created successfully." -------------------------------------------------------------------------------- /bosh-init-tf/network-outputs.tf: -------------------------------------------------------------------------------- 1 | output "internal_cidr" { 2 | value = "${openstack_networking_subnet_v2.bosh_subnet.cidr}" 3 | } 4 | 5 | output "internal_gw" { 6 | value = "${openstack_networking_subnet_v2.bosh_subnet.gateway_ip}" 7 | } 8 | 9 | output "net_id" { 10 | value = "${openstack_networking_network_v2.bosh.id}" 11 | } 12 | 13 | output "internal_ip" { 14 | value = "${cidrhost(openstack_networking_subnet_v2.bosh_subnet.cidr, 10)}" 15 | } 16 | 17 | output "router_id" { 18 | value = "${openstack_networking_router_v2.bosh_router.id}" 19 | } 20 | 21 | output "default_security_groups" { 22 | value = "[${openstack_networking_secgroup_v2.secgroup.name}]" 23 | } 24 | -------------------------------------------------------------------------------- /bosh-init-tf/network-vars.tf: -------------------------------------------------------------------------------- 1 | # input variables 2 | 3 | variable "ext_net_id" { 4 | description = "OpenStack external network id to create router interface port" 5 | } 6 | 7 | variable "availability_zone" { 8 | description = "OpenStack availability zone name" 9 | } 10 | 11 | variable "dns_nameservers" { 12 | description = "List of DNS server IPs" 13 | default = ["8.8.8.8"] 14 | type = "list" 15 | } 16 | -------------------------------------------------------------------------------- /bosh-init-tf/network.tf: -------------------------------------------------------------------------------- 1 | # networks 2 | resource "openstack_networking_network_v2" "bosh" { 3 | region = "${var.region_name}" 4 | name = "bosh" 5 | admin_state_up = "true" 6 | } 7 | 8 | resource "openstack_networking_subnet_v2" "bosh_subnet" { 9 | region = "${var.region_name}" 10 | network_id = "${openstack_networking_network_v2.bosh.id}" 11 | cidr = "10.0.1.0/24" 12 | ip_version = 4 13 | name = "bosh_sub" 14 | allocation_pools = { 15 | start = "10.0.1.200" 16 | end = "10.0.1.254" 17 | } 18 | gateway_ip = "10.0.1.1" 19 | enable_dhcp = "true" 20 | dns_nameservers = "${var.dns_nameservers}" 21 | } 22 | 23 | # router 24 | 25 | resource "openstack_networking_router_v2" "bosh_router" { 26 | region = "${var.region_name}" 27 | name = "bosh-router" 28 | admin_state_up = "true" 29 | external_network_id = "${var.ext_net_id}" 30 | } 31 | 32 | resource "openstack_networking_router_interface_v2" "bosh_port" { 33 | region = "${var.region_name}" 34 | router_id = "${openstack_networking_router_v2.bosh_router.id}" 35 | subnet_id = "${openstack_networking_subnet_v2.bosh_subnet.id}" 36 | } 37 | -------------------------------------------------------------------------------- /bosh-init-tf/provider-vars.tf: -------------------------------------------------------------------------------- 1 | 2 | # access coordinates/credentials 3 | variable "auth_url" { 4 | description = "Authentication endpoint URL for OpenStack provider (only scheme+host+port, but without path!)" 5 | } 6 | 7 | variable "user_name" { 8 | description = "OpenStack pipeline technical user name" 9 | } 10 | 11 | variable "password" { 12 | description = "OpenStack user password" 13 | } 14 | 15 | variable "domain_name" { 16 | description = "OpenStack domain name" 17 | } 18 | 19 | variable "tenant_name" { 20 | description = "OpenStack project/tenant name" 21 | } 22 | 23 | variable "insecure" { 24 | description = "Skip SSL verification" 25 | default = "false" 26 | } 27 | 28 | variable "cacert_file" { 29 | description = "Custom CA certificate" 30 | default = "" 31 | } 32 | 33 | # external network coordinates 34 | variable "ext_net_name" { 35 | description = "OpenStack external network name to register floating IP" 36 | } 37 | 38 | # region/zone coordinates 39 | variable "region_name" { 40 | description = "OpenStack region name" 41 | } -------------------------------------------------------------------------------- /bosh-init-tf/provider.tf: -------------------------------------------------------------------------------- 1 | 2 | provider "openstack" { 3 | auth_url = "${var.auth_url}" 4 | user_name = "${var.user_name}" 5 | password = "${var.password}" 6 | tenant_name = "${var.tenant_name}" 7 | domain_name = "${var.domain_name}" 8 | insecure = "${var.insecure}" 9 | cacert_file = "${var.cacert_file}" 10 | } -------------------------------------------------------------------------------- /bosh-init-tf/resources-outputs.tf: -------------------------------------------------------------------------------- 1 | output "default_key_name" { 2 | value = "${openstack_compute_keypair_v2.bosh.name}" 3 | } 4 | 5 | output "external_ip" { 6 | value = "${openstack_networking_floatingip_v2.bosh.address}" 7 | } 8 | -------------------------------------------------------------------------------- /bosh-init-tf/resources-vars.tf: -------------------------------------------------------------------------------- 1 | # input variables 2 | 3 | # key pair 4 | variable "keypair_suffix" { 5 | description = "Disambiguate keypairs with this suffix" 6 | default = "" 7 | } 8 | 9 | 10 | # security group 11 | variable "security_group_suffix" { 12 | description = "Disambiguate security groups with this suffix" 13 | default = "" 14 | } 15 | -------------------------------------------------------------------------------- /bosh-init-tf/resources.tf: -------------------------------------------------------------------------------- 1 | 2 | 3 | # key pairs 4 | resource "openstack_compute_keypair_v2" "bosh" { 5 | region = "${var.region_name}" 6 | name = "bosh${var.keypair_suffix}" 7 | public_key = "${replace("${file("bosh.pub")}","\n","")}" 8 | } 9 | 10 | # security group 11 | resource "openstack_networking_secgroup_v2" "secgroup" { 12 | region = "${var.region_name}" 13 | name = "bosh${var.security_group_suffix}" 14 | description = "BOSH Security Group" 15 | } 16 | 17 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_4" { 18 | region = "${var.region_name}" 19 | direction = "ingress" 20 | ethertype = "IPv4" 21 | protocol = "tcp" 22 | port_range_min = 22 23 | port_range_max = 22 24 | remote_ip_prefix = "0.0.0.0/0" 25 | security_group_id = "${openstack_networking_secgroup_v2.secgroup.id}" 26 | } 27 | 28 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_6" { 29 | region = "${var.region_name}" 30 | direction = "ingress" 31 | ethertype = "IPv4" 32 | protocol = "tcp" 33 | port_range_min = 6868 34 | port_range_max = 6868 35 | remote_ip_prefix = "0.0.0.0/0" 36 | security_group_id = "${openstack_networking_secgroup_v2.secgroup.id}" 37 | } 38 | 39 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_5" { 40 | region = "${var.region_name}" 41 | direction = "ingress" 42 | ethertype = "IPv4" 43 | protocol = "tcp" 44 | port_range_min = 25555 45 | port_range_max = 25555 46 | remote_ip_prefix = "0.0.0.0/0" 47 | security_group_id = "${openstack_networking_secgroup_v2.secgroup.id}" 48 | } 49 | 50 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_1" { 51 | region = "${var.region_name}" 52 | direction = "ingress" 53 | ethertype = "IPv4" 54 | protocol = "tcp" 55 | remote_group_id = "${openstack_networking_secgroup_v2.secgroup.id}" 56 | security_group_id = "${openstack_networking_secgroup_v2.secgroup.id}" 57 | } 58 | 59 | # floating ips 60 | resource "openstack_networking_floatingip_v2" "bosh" { 61 | region = "${var.region_name}" 62 | pool = "${var.ext_net_name}" 63 | } 64 | -------------------------------------------------------------------------------- /bosh-init-tf/terraform.tfvars.template: -------------------------------------------------------------------------------- 1 | auth_url = "" 2 | domain_name = "" 3 | user_name = "" 4 | password = "" 5 | tenant_name = "" 6 | region_name = "" 7 | availability_zone = "" 8 | 9 | ext_net_name = "" 10 | ext_net_id = "" 11 | 12 | # in case your OpenStack needs custom nameservers 13 | # dns_nameservers = ["8.8.8.8"] 14 | 15 | # Disambiguate keypairs with this suffix 16 | # keypair_suffix = "" 17 | 18 | # Disambiguate security groups with this suffix 19 | # security_group_suffix = "" 20 | 21 | # in case of self signed certificate select one of the following options 22 | # cacert_file = "" 23 | # insecure = "true" 24 | -------------------------------------------------------------------------------- /cf-deployment-tf/README.md: -------------------------------------------------------------------------------- 1 | ## Prerequisites 2 | * terraform >=v0.10.0 3 | * terraform-openstack-provider >=v0.2.2 4 | -------------------------------------------------------------------------------- /cf-deployment-tf/cf.tf: -------------------------------------------------------------------------------- 1 | provider "openstack" { 2 | auth_url = "${var.auth_url}" 3 | user_name = "${var.user_name}" 4 | password = "${var.password}" 5 | tenant_name = "${var.project_name}" 6 | domain_name = "${var.domain_name}" 7 | insecure = "${var.insecure}" 8 | cacert_file = "${var.cacert_file}" 9 | } 10 | 11 | variable "auth_url" { 12 | description = "Authentication endpoint URL for OpenStack provider (only scheme+host+port, but without path!)" 13 | } 14 | 15 | variable "domain_name" { 16 | description = "OpenStack domain name" 17 | } 18 | 19 | variable "user_name" { 20 | description = "OpenStack pipeline technical user name" 21 | } 22 | 23 | variable "password" { 24 | description = "OpenStack user password" 25 | } 26 | 27 | variable "project_name" { 28 | description = "OpenStack project/tenant name" 29 | } 30 | 31 | variable "insecure" { 32 | default = "false" 33 | description = "SSL certificate validation" 34 | } 35 | 36 | variable "cacert_file" { 37 | default = "" 38 | description = "Path to trusted CA certificate for OpenStack in PEM format" 39 | } 40 | 41 | variable "region_name" { 42 | description = "OpenStack region name" 43 | } 44 | 45 | variable "dns_nameservers" { 46 | type = "list" 47 | description = "DNS server IPs" 48 | } 49 | 50 | variable "availability_zones" { 51 | type = "list" 52 | } 53 | 54 | variable "use_local_blobstore" { 55 | default = "true" 56 | } 57 | 58 | variable "use_tcp_router" { 59 | default = "true" 60 | description = "OpenStack external network name to register floating IP" 61 | } 62 | 63 | variable "ext_net_name" { 64 | description = "OpenStack external network name to register floating IP" 65 | } 66 | 67 | variable "bosh_router_id" { 68 | description = "ID of the router, which has an interface to the BOSH network" 69 | } 70 | 71 | variable "num_tcp_ports" { 72 | default = 100 73 | description = "Number of tcp ports, created for tcp routing in Cloud Foundry. Creates required listeners, pools and security rules." 74 | } 75 | 76 | resource "openstack_networking_network_v2" "cf_net" { 77 | count = "${length(var.availability_zones)}" 78 | region = "${var.region_name}" 79 | name = "cf-z${count.index}" 80 | admin_state_up = "true" 81 | } 82 | 83 | resource "openstack_networking_subnet_v2" "cf_subnet" { 84 | count = "${length(var.availability_zones)}" 85 | region = "${var.region_name}" 86 | network_id = "${element(openstack_networking_network_v2.cf_net.*.id, count.index)}" 87 | cidr = "${cidrsubnet("10.0.0.0/16", 4, count.index+1)}" 88 | ip_version = 4 89 | name = "cf-z${count.index}-sub" 90 | allocation_pools = { 91 | start = "${cidrhost(cidrsubnet("10.0.0.0/16", 4, count.index+1), 2)}" 92 | end = "${cidrhost(cidrsubnet("10.0.0.0/16", 4, count.index+1), 50)}" 93 | } 94 | gateway_ip = "${cidrhost(cidrsubnet("10.0.0.0/16", 4, count.index+1), 1)}" 95 | enable_dhcp = "true" 96 | dns_nameservers = "${var.dns_nameservers}" 97 | } 98 | 99 | resource "openstack_networking_secgroup_v2" "cf_sec_group" { 100 | region = "${var.region_name}" 101 | name = "cf" 102 | description = "cloud foundry security group" 103 | } 104 | 105 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_udp" { 106 | direction = "ingress" 107 | ethertype = "IPv4" 108 | protocol = "udp" 109 | remote_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 110 | security_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 111 | region = "${var.region_name}" 112 | } 113 | 114 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_icmp" { 115 | direction = "ingress" 116 | ethertype = "IPv4" 117 | protocol = "icmp" 118 | remote_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 119 | security_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 120 | region = "${var.region_name}" 121 | } 122 | 123 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_self" { 124 | direction = "ingress" 125 | ethertype = "IPv4" 126 | protocol = "tcp" 127 | remote_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 128 | security_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 129 | region = "${var.region_name}" 130 | } 131 | 132 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_22" { 133 | direction = "ingress" 134 | ethertype = "IPv4" 135 | protocol = "tcp" 136 | port_range_min = 22 137 | port_range_max = 22 138 | remote_group_id = "${openstack_networking_secgroup_v2.bosh_sec_group.id}" 139 | security_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 140 | region = "${var.region_name}" 141 | } 142 | 143 | resource "openstack_networking_secgroup_v2" "bosh_sec_group" { 144 | region = "${var.region_name}" 145 | name = "cf-deployment-for-bosh" 146 | description = "Security group must be assigned to BOSH director VM. This enables NATS communication and allows the CF VMs to download compiled packages from the local blobstore" 147 | } 148 | 149 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_nats_cf" { 150 | direction = "ingress" 151 | ethertype = "IPv4" 152 | protocol = "tcp" 153 | port_range_min = 4222 154 | port_range_max = 4222 155 | remote_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 156 | security_group_id = "${openstack_networking_secgroup_v2.bosh_sec_group.id}" 157 | region = "${var.region_name}" 158 | } 159 | 160 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_local_blobstore_cf" { 161 | count = "${var.use_local_blobstore == "true" ? 1 : 0}" 162 | direction = "ingress" 163 | ethertype = "IPv4" 164 | protocol = "tcp" 165 | port_range_min = 25250 166 | port_range_max = 25250 167 | remote_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 168 | security_group_id = "${openstack_networking_secgroup_v2.bosh_sec_group.id}" 169 | region = "${var.region_name}" 170 | } 171 | 172 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_registry_cf" { 173 | direction = "ingress" 174 | ethertype = "IPv4" 175 | protocol = "tcp" 176 | port_range_min = 25777 177 | port_range_max = 25777 178 | remote_group_id = "${openstack_networking_secgroup_v2.cf_sec_group.id}" 179 | security_group_id = "${openstack_networking_secgroup_v2.bosh_sec_group.id}" 180 | region = "${var.region_name}" 181 | } 182 | 183 | resource "openstack_networking_secgroup_v2" "cf_https_router_sec_group" { 184 | region = "${var.region_name}" 185 | name = "cf-lb-https-router" 186 | description = "Security group which will be assigned to the cloud foundry router VM to receive TCP traffic from the load balancer on port 443" 187 | } 188 | 189 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_443_cf_https_router" { 190 | count = "${length(var.availability_zones)}" 191 | direction = "ingress" 192 | ethertype = "IPv4" 193 | protocol = "tcp" 194 | port_range_min = 443 195 | port_range_max = 443 196 | remote_ip_prefix = "${element(openstack_networking_subnet_v2.cf_subnet.*.cidr, count.index)}" 197 | security_group_id = "${openstack_networking_secgroup_v2.cf_https_router_sec_group.id}" 198 | region = "${var.region_name}" 199 | } 200 | 201 | resource "openstack_networking_secgroup_v2" "cf_diego_brain_sec_group" { 202 | region = "${var.region_name}" 203 | name = "cf-lb-ssh-diego-brain" 204 | description = "Security group which will be assigned to the cloud foundry diego brain VM to receive TCP traffic from the load balancer on port 2222" 205 | } 206 | 207 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_2222_cf_diego_brain" { 208 | count = "${length(var.availability_zones)}" 209 | direction = "ingress" 210 | ethertype = "IPv4" 211 | protocol = "tcp" 212 | port_range_min = 2222 213 | port_range_max = 2222 214 | remote_ip_prefix = "${element(openstack_networking_subnet_v2.cf_subnet.*.cidr, count.index)}" 215 | security_group_id = "${openstack_networking_secgroup_v2.cf_diego_brain_sec_group.id}" 216 | region = "${var.region_name}" 217 | } 218 | 219 | resource "openstack_networking_secgroup_v2" "cf_lb_sec_group" { 220 | region = "${var.region_name}" 221 | name = "cf-lb" 222 | description = "Security group which will be assigned to the cf load balancer" 223 | } 224 | 225 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_443_cf_lb" { 226 | direction = "ingress" 227 | ethertype = "IPv4" 228 | protocol = "tcp" 229 | port_range_min = 443 230 | port_range_max = 443 231 | remote_ip_prefix = "0.0.0.0/0" 232 | security_group_id = "${openstack_networking_secgroup_v2.cf_lb_sec_group.id}" 233 | region = "${var.region_name}" 234 | } 235 | 236 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_2222_cf_lb" { 237 | direction = "ingress" 238 | ethertype = "IPv4" 239 | protocol = "tcp" 240 | port_range_min = 2222 241 | port_range_max = 2222 242 | remote_ip_prefix = "0.0.0.0/0" 243 | security_group_id = "${openstack_networking_secgroup_v2.cf_lb_sec_group.id}" 244 | region = "${var.region_name}" 245 | } 246 | 247 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_ports_cf_lb" { 248 | direction = "ingress" 249 | ethertype = "IPv4" 250 | protocol = "tcp" 251 | port_range_min = 1024 252 | port_range_max = "${1024 + var.num_tcp_ports - 1}" 253 | remote_ip_prefix = "0.0.0.0/0" 254 | security_group_id = "${openstack_networking_secgroup_v2.cf_lb_sec_group.id}" 255 | region = "${var.region_name}" 256 | } 257 | 258 | resource "openstack_lb_loadbalancer_v2" "cf-lb" { 259 | name = "cf-lb" 260 | vip_subnet_id = "${openstack_networking_subnet_v2.cf_subnet.0.id}" 261 | security_group_ids = ["${openstack_networking_secgroup_v2.cf_lb_sec_group.id}"] 262 | region = "${var.region_name}" 263 | } 264 | 265 | resource "openstack_networking_floatingip_v2" "lb_floating" { 266 | pool = "${var.ext_net_name}" 267 | port_id = "${openstack_lb_loadbalancer_v2.cf-lb.vip_port_id}" 268 | region = "${var.region_name}" 269 | } 270 | 271 | resource "openstack_lb_listener_v2" "cf_https_listener" { 272 | region = "${var.region_name}" 273 | protocol = "TCP" 274 | protocol_port = 443 275 | name = "cf-https-listener" 276 | loadbalancer_id = "${openstack_lb_loadbalancer_v2.cf-lb.id}" 277 | } 278 | 279 | resource "openstack_lb_pool_v2" "cf_https_pool" { 280 | region = "${var.region_name}" 281 | protocol = "TCP" 282 | lb_method = "ROUND_ROBIN" 283 | name = "cf-https-pool" 284 | listener_id = "${openstack_lb_listener_v2.cf_https_listener.id}" 285 | } 286 | 287 | resource "openstack_lb_listener_v2" "cf_ssh_listener" { 288 | region = "${var.region_name}" 289 | protocol = "TCP" 290 | protocol_port = 2222 291 | name = "cf-ssh-listener" 292 | loadbalancer_id = "${openstack_lb_loadbalancer_v2.cf-lb.id}" 293 | } 294 | 295 | resource "openstack_lb_pool_v2" "cf_ssh_pool" { 296 | region = "${var.region_name}" 297 | protocol = "TCP" 298 | lb_method = "ROUND_ROBIN" 299 | name = "cf-ssh-pool" 300 | listener_id = "${openstack_lb_listener_v2.cf_ssh_listener.id}" 301 | } 302 | 303 | resource "openstack_lb_listener_v2" "cf_tcp_listener" { 304 | count = "${var.use_tcp_router == "true" ? var.num_tcp_ports : 0}" 305 | region = "${var.region_name}" 306 | protocol = "TCP" 307 | protocol_port = "${1024 + count.index}" 308 | name = "cf-tcp-listener-${1024 + count.index}" 309 | loadbalancer_id = "${openstack_lb_loadbalancer_v2.cf-lb.id}" 310 | } 311 | 312 | resource "openstack_lb_pool_v2" "cf_tcp_pool" { 313 | count = "${var.use_tcp_router == "true" ? var.num_tcp_ports : 0}" 314 | region = "${var.region_name}" 315 | protocol = "TCP" 316 | lb_method = "ROUND_ROBIN" 317 | name = "cf-tcp-pool-${1024 + count.index}" 318 | listener_id = "${element(openstack_lb_listener_v2.cf_tcp_listener.*.id, count.index)}" 319 | } 320 | 321 | resource "openstack_networking_secgroup_v2" "cf_lb_tcp_router_sec_group" { 322 | count = "${var.use_tcp_router == "true" ? 1 : 0}" 323 | region = "${var.region_name}" 324 | name = "cf-lb-tcp-router" 325 | description = "Security group which will be assigned to the cloud foundry tcp router VM to receive TCP traffic from the load balancer on port 1024-${1024 + var.num_tcp_ports - 1}" 326 | } 327 | 328 | resource "openstack_networking_secgroup_rule_v2" "secgroup_rule_tcp_ports_cf_tcp_router" { 329 | count = "${var.use_tcp_router == "true" ? length(var.availability_zones) : 0}" 330 | direction = "ingress" 331 | ethertype = "IPv4" 332 | protocol = "tcp" 333 | port_range_min = 1024 334 | port_range_max = "${1024 + var.num_tcp_ports - 1}" 335 | remote_ip_prefix = "${element(openstack_networking_subnet_v2.cf_subnet.*.cidr, count.index)}" 336 | security_group_id = "${openstack_networking_secgroup_v2.cf_lb_tcp_router_sec_group.id}" 337 | region = "${var.region_name}" 338 | } 339 | 340 | resource "openstack_networking_router_interface_v2" "cf_router_interface" { 341 | count = "${length(var.availability_zones)}" 342 | router_id = "${var.bosh_router_id}" 343 | subnet_id = "${element(openstack_networking_subnet_v2.cf_subnet.*.id, count.index)}" 344 | region = "${var.region_name}" 345 | } 346 | 347 | output "network_id" { 348 | value = "${openstack_networking_network_v2.cf_net.*.id}" 349 | } 350 | 351 | output "security group to be assigned to BOSH vm" { 352 | value = "${openstack_networking_secgroup_v2.bosh_sec_group.name}" 353 | } 354 | 355 | output "Load balancer floating ip" { 356 | value = "${openstack_networking_floatingip_v2.lb_floating.address}" 357 | } 358 | -------------------------------------------------------------------------------- /cf-deployment-tf/terraform.tfvars.template: -------------------------------------------------------------------------------- 1 | auth_url = "" 2 | domain_name = "" 3 | user_name = "" 4 | password = "" 5 | project_name = "" 6 | region_name = "" 7 | availability_zones = ["","",""] 8 | ext_net_name = "" 9 | 10 | # the OpenStack router id which can be used to access the BOSH network 11 | bosh_router_id = "" 12 | 13 | # in case Openstack has its own DNS servers 14 | dns_nameservers = ["",""] 15 | 16 | # does BOSH use a local blobstore? Set to 'false', if your BOSH Director uses e.g. S3 to store its blobs 17 | use_local_blobstore = "" #default is true 18 | 19 | # enable TCP routing setup 20 | use_tcp_router = "" #default is true 21 | num_tcp_ports = #default is 100, needs to be > 0 22 | 23 | # in case of self signed certificate select one of the following options 24 | # cacert_file = "" 25 | # insecure = "true" 26 | --------------------------------------------------------------------------------