├── .circleci └── config.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT ├── LICENSE ├── README.md ├── main.tf ├── modules └── consul_cluster │ ├── consul_clients.tf │ ├── consul_security.tf │ ├── iam.tf │ ├── main.tf │ ├── outputs.tf │ ├── scripts │ ├── install_hashitools_consul_client.sh.tpl │ └── install_hashitools_consul_server.sh.tpl │ ├── security_groups.tf │ ├── variables.tf │ └── versions.tf ├── variables.tf └── versions.tf /.circleci/config.yml: -------------------------------------------------------------------------------- 1 | version: 2.1 2 | 3 | jobs: 4 | terraform-checks: 5 | docker: 6 | - image: hashicorp/terraform:latest 7 | steps: 8 | - checkout 9 | - run: terraform version 10 | - run: terraform init -input=false -backend=false 11 | - run: 12 | name: terraform fmt 13 | command: | 14 | if ! (terraform fmt -check -recursive -write=false); then 15 | echo "There are terraform files to format. Run `terraform fmt --recursive` to fix" 16 | exit 1 17 | fi 18 | - run: 19 | name: terraform validate 20 | environment: 21 | # `terraform validate` complains if there isn't a value specified 22 | # ref: https://github.com/terraform-providers/terraform-provider-aws/issues/9989 23 | AWS_DEFAULT_REGION: us-east-1 24 | command: | 25 | find . -type f -name "*.tf" -exec dirname {} \; | sort -u | 26 | while read dir; do 27 | terraform validate && echo "√ $dir" || exit 1 28 | done 29 | workflows: 30 | version: 2 31 | terraform: 32 | jobs: 33 | - terraform-checks 34 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | .DS_Store 9 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## 0.2.0 (August 13, 2020) 2 | 3 | IMPROVEMENTS: 4 | 5 | * Upgrading terraform block syntax for TF version 0.13.0+ 6 | * Pinning version number for `aws`, `random`, and `template` providers 7 | 8 | ## 0.1.5 (July 24, 2020) 9 | 10 | IMPROVEMENTS: 11 | 12 | * installation: added `ami_id` variable to override supplied default Ubuntu AMI if desired 13 | 14 | ## 0.1.4 (July 22, 2020) 15 | 16 | IMPROVEMENTS: 17 | 18 | * installation: updated package epoch for regenerated repository 19 | 20 | ## 0.1.3 (July 10, 2020) 21 | 22 | IMPROVEMENTS: 23 | 24 | * security: added security group rule to expose UI to allowed CIDR blocks 25 | * documentation: explained new `allowed_inbound_cidrs` 26 | * variables: renamed var to `acl_bootstrap_bool` to clarify purpose of variable 27 | 28 | ## 0.1.2 (July 08, 2020) 29 | 30 | IMPROVEMENTS: 31 | 32 | * security: added security group rule for inbound on port 22 and variable for approved CIDR blocks 33 | 34 | ## 0.1.1 (July 02, 2020) 35 | 36 | IMPROVEMENTS: 37 | 38 | * documentation: updated refs and corrected links 39 | * documentation: added CHANGELOG 40 | 41 | ## 0.1.0 (July 02, 2020) 42 | 43 | * Initial release 44 | -------------------------------------------------------------------------------- /CODE_OF_CONDUCT: -------------------------------------------------------------------------------- 1 | # Code of Conduct 2 | 3 | HashiCorp Community Guidelines apply to you when interacting with the community here on GitHub and contributing code. 4 | 5 | Please read the full text at https://www.hashicorp.com/community-guidelines 6 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Mozilla Public License Version 2.0 2 | ================================== 3 | 4 | 1. Definitions 5 | -------------- 6 | 7 | 1.1. "Contributor" 8 | means each individual or legal entity that creates, contributes to 9 | the creation of, or owns Covered Software. 10 | 11 | 1.2. "Contributor Version" 12 | means the combination of the Contributions of others (if any) used 13 | by a Contributor and that particular Contributor's Contribution. 14 | 15 | 1.3. "Contribution" 16 | means Covered Software of a particular Contributor. 17 | 18 | 1.4. "Covered Software" 19 | means Source Code Form to which the initial Contributor has attached 20 | the notice in Exhibit A, the Executable Form of such Source Code 21 | Form, and Modifications of such Source Code Form, in each case 22 | including portions thereof. 23 | 24 | 1.5. "Incompatible With Secondary Licenses" 25 | means 26 | 27 | (a) that the initial Contributor has attached the notice described 28 | in Exhibit B to the Covered Software; or 29 | 30 | (b) that the Covered Software was made available under the terms of 31 | version 1.1 or earlier of the License, but not also under the 32 | terms of a Secondary License. 33 | 34 | 1.6. "Executable Form" 35 | means any form of the work other than Source Code Form. 36 | 37 | 1.7. "Larger Work" 38 | means a work that combines Covered Software with other material, in 39 | a separate file or files, that is not Covered Software. 40 | 41 | 1.8. "License" 42 | means this document. 43 | 44 | 1.9. "Licensable" 45 | means having the right to grant, to the maximum extent possible, 46 | whether at the time of the initial grant or subsequently, any and 47 | all of the rights conveyed by this License. 48 | 49 | 1.10. "Modifications" 50 | means any of the following: 51 | 52 | (a) any file in Source Code Form that results from an addition to, 53 | deletion from, or modification of the contents of Covered 54 | Software; or 55 | 56 | (b) any new file in Source Code Form that contains any Covered 57 | Software. 58 | 59 | 1.11. "Patent Claims" of a Contributor 60 | means any patent claim(s), including without limitation, method, 61 | process, and apparatus claims, in any patent Licensable by such 62 | Contributor that would be infringed, but for the grant of the 63 | License, by the making, using, selling, offering for sale, having 64 | made, import, or transfer of either its Contributions or its 65 | Contributor Version. 66 | 67 | 1.12. "Secondary License" 68 | means either the GNU General Public License, Version 2.0, the GNU 69 | Lesser General Public License, Version 2.1, the GNU Affero General 70 | Public License, Version 3.0, or any later versions of those 71 | licenses. 72 | 73 | 1.13. "Source Code Form" 74 | means the form of the work preferred for making modifications. 75 | 76 | 1.14. "You" (or "Your") 77 | means an individual or a legal entity exercising rights under this 78 | License. For legal entities, "You" includes any entity that 79 | controls, is controlled by, or is under common control with You. For 80 | purposes of this definition, "control" means (a) the power, direct 81 | or indirect, to cause the direction or management of such entity, 82 | whether by contract or otherwise, or (b) ownership of more than 83 | fifty percent (50%) of the outstanding shares or beneficial 84 | ownership of such entity. 85 | 86 | 2. License Grants and Conditions 87 | -------------------------------- 88 | 89 | 2.1. Grants 90 | 91 | Each Contributor hereby grants You a world-wide, royalty-free, 92 | non-exclusive license: 93 | 94 | (a) under intellectual property rights (other than patent or trademark) 95 | Licensable by such Contributor to use, reproduce, make available, 96 | modify, display, perform, distribute, and otherwise exploit its 97 | Contributions, either on an unmodified basis, with Modifications, or 98 | as part of a Larger Work; and 99 | 100 | (b) under Patent Claims of such Contributor to make, use, sell, offer 101 | for sale, have made, import, and otherwise transfer either its 102 | Contributions or its Contributor Version. 103 | 104 | 2.2. Effective Date 105 | 106 | The licenses granted in Section 2.1 with respect to any Contribution 107 | become effective for each Contribution on the date the Contributor first 108 | distributes such Contribution. 109 | 110 | 2.3. Limitations on Grant Scope 111 | 112 | The licenses granted in this Section 2 are the only rights granted under 113 | this License. No additional rights or licenses will be implied from the 114 | distribution or licensing of Covered Software under this License. 115 | Notwithstanding Section 2.1(b) above, no patent license is granted by a 116 | Contributor: 117 | 118 | (a) for any code that a Contributor has removed from Covered Software; 119 | or 120 | 121 | (b) for infringements caused by: (i) Your and any other third party's 122 | modifications of Covered Software, or (ii) the combination of its 123 | Contributions with other software (except as part of its Contributor 124 | Version); or 125 | 126 | (c) under Patent Claims infringed by Covered Software in the absence of 127 | its Contributions. 128 | 129 | This License does not grant any rights in the trademarks, service marks, 130 | or logos of any Contributor (except as may be necessary to comply with 131 | the notice requirements in Section 3.4). 132 | 133 | 2.4. Subsequent Licenses 134 | 135 | No Contributor makes additional grants as a result of Your choice to 136 | distribute the Covered Software under a subsequent version of this 137 | License (see Section 10.2) or under the terms of a Secondary License (if 138 | permitted under the terms of Section 3.3). 139 | 140 | 2.5. Representation 141 | 142 | Each Contributor represents that the Contributor believes its 143 | Contributions are its original creation(s) or it has sufficient rights 144 | to grant the rights to its Contributions conveyed by this License. 145 | 146 | 2.6. Fair Use 147 | 148 | This License is not intended to limit any rights You have under 149 | applicable copyright doctrines of fair use, fair dealing, or other 150 | equivalents. 151 | 152 | 2.7. Conditions 153 | 154 | Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted 155 | in Section 2.1. 156 | 157 | 3. Responsibilities 158 | ------------------- 159 | 160 | 3.1. Distribution of Source Form 161 | 162 | All distribution of Covered Software in Source Code Form, including any 163 | Modifications that You create or to which You contribute, must be under 164 | the terms of this License. You must inform recipients that the Source 165 | Code Form of the Covered Software is governed by the terms of this 166 | License, and how they can obtain a copy of this License. You may not 167 | attempt to alter or restrict the recipients' rights in the Source Code 168 | Form. 169 | 170 | 3.2. Distribution of Executable Form 171 | 172 | If You distribute Covered Software in Executable Form then: 173 | 174 | (a) such Covered Software must also be made available in Source Code 175 | Form, as described in Section 3.1, and You must inform recipients of 176 | the Executable Form how they can obtain a copy of such Source Code 177 | Form by reasonable means in a timely manner, at a charge no more 178 | than the cost of distribution to the recipient; and 179 | 180 | (b) You may distribute such Executable Form under the terms of this 181 | License, or sublicense it under different terms, provided that the 182 | license for the Executable Form does not attempt to limit or alter 183 | the recipients' rights in the Source Code Form under this License. 184 | 185 | 3.3. Distribution of a Larger Work 186 | 187 | You may create and distribute a Larger Work under terms of Your choice, 188 | provided that You also comply with the requirements of this License for 189 | the Covered Software. If the Larger Work is a combination of Covered 190 | Software with a work governed by one or more Secondary Licenses, and the 191 | Covered Software is not Incompatible With Secondary Licenses, this 192 | License permits You to additionally distribute such Covered Software 193 | under the terms of such Secondary License(s), so that the recipient of 194 | the Larger Work may, at their option, further distribute the Covered 195 | Software under the terms of either this License or such Secondary 196 | License(s). 197 | 198 | 3.4. Notices 199 | 200 | You may not remove or alter the substance of any license notices 201 | (including copyright notices, patent notices, disclaimers of warranty, 202 | or limitations of liability) contained within the Source Code Form of 203 | the Covered Software, except that You may alter any license notices to 204 | the extent required to remedy known factual inaccuracies. 205 | 206 | 3.5. Application of Additional Terms 207 | 208 | You may choose to offer, and to charge a fee for, warranty, support, 209 | indemnity or liability obligations to one or more recipients of Covered 210 | Software. However, You may do so only on Your own behalf, and not on 211 | behalf of any Contributor. You must make it absolutely clear that any 212 | such warranty, support, indemnity, or liability obligation is offered by 213 | You alone, and You hereby agree to indemnify every Contributor for any 214 | liability incurred by such Contributor as a result of warranty, support, 215 | indemnity or liability terms You offer. You may include additional 216 | disclaimers of warranty and limitations of liability specific to any 217 | jurisdiction. 218 | 219 | 4. Inability to Comply Due to Statute or Regulation 220 | --------------------------------------------------- 221 | 222 | If it is impossible for You to comply with any of the terms of this 223 | License with respect to some or all of the Covered Software due to 224 | statute, judicial order, or regulation then You must: (a) comply with 225 | the terms of this License to the maximum extent possible; and (b) 226 | describe the limitations and the code they affect. Such description must 227 | be placed in a text file included with all distributions of the Covered 228 | Software under this License. Except to the extent prohibited by statute 229 | or regulation, such description must be sufficiently detailed for a 230 | recipient of ordinary skill to be able to understand it. 231 | 232 | 5. Termination 233 | -------------- 234 | 235 | 5.1. The rights granted under this License will terminate automatically 236 | if You fail to comply with any of its terms. However, if You become 237 | compliant, then the rights granted under this License from a particular 238 | Contributor are reinstated (a) provisionally, unless and until such 239 | Contributor explicitly and finally terminates Your grants, and (b) on an 240 | ongoing basis, if such Contributor fails to notify You of the 241 | non-compliance by some reasonable means prior to 60 days after You have 242 | come back into compliance. Moreover, Your grants from a particular 243 | Contributor are reinstated on an ongoing basis if such Contributor 244 | notifies You of the non-compliance by some reasonable means, this is the 245 | first time You have received notice of non-compliance with this License 246 | from such Contributor, and You become compliant prior to 30 days after 247 | Your receipt of the notice. 248 | 249 | 5.2. If You initiate litigation against any entity by asserting a patent 250 | infringement claim (excluding declaratory judgment actions, 251 | counter-claims, and cross-claims) alleging that a Contributor Version 252 | directly or indirectly infringes any patent, then the rights granted to 253 | You by any and all Contributors for the Covered Software under Section 254 | 2.1 of this License shall terminate. 255 | 256 | 5.3. In the event of termination under Sections 5.1 or 5.2 above, all 257 | end user license agreements (excluding distributors and resellers) which 258 | have been validly granted by You or Your distributors under this License 259 | prior to termination shall survive termination. 260 | 261 | ************************************************************************ 262 | * * 263 | * 6. Disclaimer of Warranty * 264 | * ------------------------- * 265 | * * 266 | * Covered Software is provided under this License on an "as is" * 267 | * basis, without warranty of any kind, either expressed, implied, or * 268 | * statutory, including, without limitation, warranties that the * 269 | * Covered Software is free of defects, merchantable, fit for a * 270 | * particular purpose or non-infringing. The entire risk as to the * 271 | * quality and performance of the Covered Software is with You. * 272 | * Should any Covered Software prove defective in any respect, You * 273 | * (not any Contributor) assume the cost of any necessary servicing, * 274 | * repair, or correction. This disclaimer of warranty constitutes an * 275 | * essential part of this License. No use of any Covered Software is * 276 | * authorized under this License except under this disclaimer. * 277 | * * 278 | ************************************************************************ 279 | 280 | ************************************************************************ 281 | * * 282 | * 7. Limitation of Liability * 283 | * -------------------------- * 284 | * * 285 | * Under no circumstances and under no legal theory, whether tort * 286 | * (including negligence), contract, or otherwise, shall any * 287 | * Contributor, or anyone who distributes Covered Software as * 288 | * permitted above, be liable to You for any direct, indirect, * 289 | * special, incidental, or consequential damages of any character * 290 | * including, without limitation, damages for lost profits, loss of * 291 | * goodwill, work stoppage, computer failure or malfunction, or any * 292 | * and all other commercial damages or losses, even if such party * 293 | * shall have been informed of the possibility of such damages. This * 294 | * limitation of liability shall not apply to liability for death or * 295 | * personal injury resulting from such party's negligence to the * 296 | * extent applicable law prohibits such limitation. Some * 297 | * jurisdictions do not allow the exclusion or limitation of * 298 | * incidental or consequential damages, so this exclusion and * 299 | * limitation may not apply to You. * 300 | * * 301 | ************************************************************************ 302 | 303 | 8. Litigation 304 | ------------- 305 | 306 | Any litigation relating to this License may be brought only in the 307 | courts of a jurisdiction where the defendant maintains its principal 308 | place of business and such litigation shall be governed by laws of that 309 | jurisdiction, without reference to its conflict-of-law provisions. 310 | Nothing in this Section shall prevent a party's ability to bring 311 | cross-claims or counter-claims. 312 | 313 | 9. Miscellaneous 314 | ---------------- 315 | 316 | This License represents the complete agreement concerning the subject 317 | matter hereof. If any provision of this License is held to be 318 | unenforceable, such provision shall be reformed only to the extent 319 | necessary to make it enforceable. Any law or regulation which provides 320 | that the language of a contract shall be construed against the drafter 321 | shall not be used to construe this License against a Contributor. 322 | 323 | 10. Versions of the License 324 | --------------------------- 325 | 326 | 10.1. New Versions 327 | 328 | Mozilla Foundation is the license steward. Except as provided in Section 329 | 10.3, no one other than the license steward has the right to modify or 330 | publish new versions of this License. Each version will be given a 331 | distinguishing version number. 332 | 333 | 10.2. Effect of New Versions 334 | 335 | You may distribute the Covered Software under the terms of the version 336 | of the License under which You originally received the Covered Software, 337 | or under the terms of any subsequent version published by the license 338 | steward. 339 | 340 | 10.3. Modified Versions 341 | 342 | If you create software not governed by this License, and you want to 343 | create a new license for such software, you may create and use a 344 | modified version of this License if you rename the license and remove 345 | any references to the name of the license steward (except to note that 346 | such modified license differs from this License). 347 | 348 | 10.4. Distributing Source Code Form that is Incompatible With Secondary 349 | Licenses 350 | 351 | If You choose to distribute Source Code Form that is Incompatible With 352 | Secondary Licenses under the terms of this version of the License, the 353 | notice described in Exhibit B of this License must be attached. 354 | 355 | Exhibit A - Source Code Form License Notice 356 | ------------------------------------------- 357 | 358 | This Source Code Form is subject to the terms of the Mozilla Public 359 | License, v. 2.0. If a copy of the MPL was not distributed with this 360 | file, You can obtain one at http://mozilla.org/MPL/2.0/. 361 | 362 | If it is not possible or desirable to put the notice in a particular 363 | file, then You may include the notice in a location (such as a LICENSE 364 | file in a relevant directory) where a recipient would be likely to look 365 | for such a notice. 366 | 367 | You may add additional accurate notices of copyright ownership. 368 | 369 | Exhibit B - "Incompatible With Secondary Licenses" Notice 370 | --------------------------------------------------------- 371 | 372 | This Source Code Form is "Incompatible With Secondary Licenses", as 373 | defined by the Mozilla Public License, v. 2.0. 374 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Consul AWS Module 2 | 3 | This is a Terraform module for provisioning a Consul Cluster on AWS. Consul is a distributed, highly-available service mesh solution providing a full featured control plane with service discovery, configuration, and segmentation functionality. This module will provision a fully functional Consul cluster, which defaults to consisting of 5 (five) servers and 3 (three) clients. 4 | 5 | ## About This Module 6 | 7 | This module implements the [Consul Reference Architecture](https://learn.hashicorp.com/consul/datacenter-deploy/reference-architecture?utm_source=consul.io&utm_medium=docs#datacenter-design) for a single datacenter on AWS using the Open Source version of Consul. It is created and maintained by HashiCorp to exist as a canonical implementation of a Consul cluster in the Amazon Web Services cloud, and enforces this prescriptive methodology through the use of default values corresponding to the recommendations of our Enterprise Architects. 8 | 9 | For more advanced practitioners requiring a wider variety of configurable options out of the box, please see the [Terraform AWS Consul Module](https://registry.terraform.io/modules/hashicorp/consul/aws/0.7.4). 10 | 11 | ## How to Use This Module 12 | 13 | - Create a Terraform configuration that pulls in the module and specifies values 14 | of the required variables: 15 | 16 | ```hcl 17 | provider "aws" { 18 | region = "" 19 | } 20 | 21 | module "consul_cluster" { 22 | source = "hashicorp/consul-oss/aws" 23 | version = "0.1.0" 24 | allowed_inbound_cidrs = [""] 25 | vpc_id = "" 26 | owner = "" 27 | consul_version = "" 28 | name_prefix = "" 29 | key_name = "" 30 | consul_servers = 5 31 | consul_clients = 3 32 | } 33 | ``` 34 | 35 | Notes: 36 | 1. Currently the random provider is required for this module's functionality. 37 | 2. `allowed_inbound_cidrs` must be supplied for this module's functionality; these CIDRs will be allowed for SSH and UI access. 38 | 39 | - Run `terraform init` and `terraform apply` 40 | 41 | ## License 42 | 43 | This code is released under the Mozilla Public License 2.0. Please see [LICENSE](https://github.com/hashicorp/terraform-aws-consul-oss/blob/master/LICENSE) for more details. 44 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | module "consul_cluster" { 2 | source = "./modules/consul_cluster" 3 | 4 | allowed_inbound_cidrs = var.allowed_inbound_cidrs 5 | instance_type = var.instance_type 6 | consul_version = var.consul_version 7 | consul_cluster_version = var.consul_cluster_version 8 | acl_bootstrap_bool = var.acl_bootstrap_bool 9 | key_name = var.key_name 10 | name_prefix = var.name_prefix 11 | vpc_id = var.vpc_id 12 | public_ip = var.public_ip 13 | consul_servers = var.consul_servers 14 | consul_clients = var.consul_clients 15 | consul_config = var.consul_config 16 | enable_connect = var.enable_connect 17 | owner = var.owner 18 | } 19 | -------------------------------------------------------------------------------- /modules/consul_cluster/consul_clients.tf: -------------------------------------------------------------------------------- 1 | # creates Consul autoscaling group for clients 2 | resource "aws_autoscaling_group" "consul_clients" { 3 | name = aws_launch_configuration.consul_clients.name 4 | launch_configuration = aws_launch_configuration.consul_clients.name 5 | availability_zones = data.aws_availability_zones.available.zone_ids 6 | min_size = var.consul_clients 7 | max_size = var.consul_clients 8 | desired_capacity = var.consul_clients 9 | wait_for_capacity_timeout = "480s" 10 | health_check_grace_period = 15 11 | health_check_type = "EC2" 12 | vpc_zone_identifier = data.aws_subnet_ids.default.ids 13 | 14 | tags = [ 15 | { 16 | key = "Name" 17 | value = "${var.name_prefix}-consul-client" 18 | propagate_at_launch = true 19 | }, 20 | { 21 | key = "Cluster-Version" 22 | value = var.consul_cluster_version 23 | propagate_at_launch = true 24 | }, 25 | { 26 | key = "Environment-Name" 27 | value = "${var.name_prefix}-consul" 28 | propagate_at_launch = true 29 | }, 30 | { 31 | key = "owner" 32 | value = var.owner 33 | propagate_at_launch = true 34 | }, 35 | ] 36 | 37 | depends_on = [aws_autoscaling_group.consul_servers] 38 | 39 | lifecycle { 40 | create_before_destroy = true 41 | } 42 | } 43 | 44 | # provides a resource for a new autoscaling group launch configuration 45 | resource "aws_launch_configuration" "consul_clients" { 46 | name = "${random_id.environment_name.hex}-consul-clients-${var.consul_cluster_version}" 47 | image_id = data.aws_ami.ubuntu.id 48 | instance_type = var.instance_type 49 | key_name = var.key_name 50 | security_groups = [aws_security_group.consul.id] 51 | user_data = templatefile("${path.module}/scripts/install_hashitools_consul_client.sh.tpl", 52 | { 53 | ami = data.aws_ami.ubuntu.id, 54 | environment_name = "${var.name_prefix}-consul", 55 | consul_version = var.consul_version, 56 | datacenter = data.aws_region.current.name, 57 | gossip_key = random_id.consul_gossip_encryption_key.b64_std, 58 | }) 59 | associate_public_ip_address = var.public_ip 60 | iam_instance_profile = aws_iam_instance_profile.instance_profile.name 61 | root_block_device { 62 | volume_size = 10 63 | } 64 | 65 | lifecycle { 66 | create_before_destroy = true 67 | } 68 | } 69 | -------------------------------------------------------------------------------- /modules/consul_cluster/consul_security.tf: -------------------------------------------------------------------------------- 1 | resource "random_uuid" "consul_master_token" {} 2 | resource "random_uuid" "consul_agent_server_token" {} 3 | resource "random_uuid" "consul_snapshot_token" {} 4 | 5 | resource "random_id" "consul_gossip_encryption_key" { 6 | byte_length = 32 7 | } 8 | -------------------------------------------------------------------------------- /modules/consul_cluster/iam.tf: -------------------------------------------------------------------------------- 1 | # creates new instance role profile (noted by name_prefix which forces new resource) for named instance role 2 | # uses random UUID & suffix 3 | # see: https://www.terraform.io/docs/providers/aws/r/iam_instance_profile.html 4 | resource "aws_iam_instance_profile" "instance_profile" { 5 | name_prefix = "${random_id.environment_name.hex}-consul" # TODO: transition to var 6 | role = aws_iam_role.instance_role.name 7 | } 8 | 9 | # creates IAM role for instances using supplied policy from data source below 10 | resource "aws_iam_role" "instance_role" { 11 | name_prefix = "${random_id.environment_name.hex}-consul" # TODO: transition to var 12 | assume_role_policy = data.aws_iam_policy_document.instance_role.json 13 | } 14 | 15 | # defines JSON for instance role base IAM policy 16 | data "aws_iam_policy_document" "instance_role" { 17 | statement { 18 | effect = "Allow" 19 | actions = [ 20 | "sts:AssumeRole", 21 | ] 22 | 23 | principals { 24 | type = "Service" 25 | identifiers = ["ec2.amazonaws.com"] 26 | } 27 | } 28 | } 29 | 30 | # creates IAM role policy for cluster discovery and attaches it to instance role 31 | resource "aws_iam_role_policy" "cluster_discovery" { 32 | name = "${random_id.environment_name.hex}-consul-cluster_discovery" 33 | role = aws_iam_role.instance_role.id 34 | policy = data.aws_iam_policy_document.cluster_discovery.json 35 | } 36 | 37 | # creates IAM policy document for linking to above policy as JSON 38 | data "aws_iam_policy_document" "cluster_discovery" { 39 | # allow role with this policy to do the following: list instances, list tags, autoscale 40 | statement { 41 | effect = "Allow" 42 | actions = [ 43 | "ec2:DescribeInstances", 44 | "autoscaling:CompleteLifecycleAction", 45 | "ec2:DescribeTags" 46 | ] 47 | resources = ["*"] 48 | } 49 | } 50 | -------------------------------------------------------------------------------- /modules/consul_cluster/main.tf: -------------------------------------------------------------------------------- 1 | # data source for current (working) aws region 2 | data "aws_region" "current" {} 3 | 4 | # data source for VPC id for the VPC being used 5 | data "aws_vpc" "consul_vpc" { 6 | id = var.vpc_id 7 | } 8 | 9 | # data source for subnet ids in VPC 10 | data "aws_subnet_ids" "default" { 11 | vpc_id = data.aws_vpc.consul_vpc.id 12 | } 13 | 14 | # data source for availability zones 15 | data "aws_availability_zones" "available" { 16 | state = "available" 17 | } 18 | 19 | # data source for vanilla Ubuntu AWS AMI as base image for cluster 20 | data "aws_ami" "ubuntu" { 21 | most_recent = true 22 | 23 | filter { 24 | name = "name" 25 | values = ["ubuntu/images/hvm-ssd/ubuntu-focal-20.04-amd64-server-*"] 26 | } 27 | 28 | filter { 29 | name = "virtualization-type" 30 | values = ["hvm"] 31 | } 32 | 33 | owners = ["099720109477"] # Canonical 34 | } 35 | 36 | # creates random UUID for the environment name 37 | resource "random_id" "environment_name" { 38 | byte_length = 4 39 | prefix = "${var.name_prefix}-" 40 | } 41 | 42 | # creates Consul autoscaling group for servers 43 | resource "aws_autoscaling_group" "consul_servers" { 44 | name = aws_launch_configuration.consul_servers.name 45 | launch_configuration = aws_launch_configuration.consul_servers.name 46 | availability_zones = data.aws_availability_zones.available.zone_ids 47 | min_size = var.consul_servers 48 | max_size = var.consul_servers 49 | desired_capacity = var.consul_servers 50 | wait_for_capacity_timeout = "480s" 51 | health_check_grace_period = 15 52 | health_check_type = "EC2" 53 | vpc_zone_identifier = data.aws_subnet_ids.default.ids 54 | tags = [ 55 | { 56 | key = "Name" 57 | value = "${var.name_prefix}-consul-server" 58 | propagate_at_launch = true 59 | }, 60 | { 61 | key = "Cluster-Version" 62 | value = var.consul_cluster_version 63 | propagate_at_launch = true 64 | }, 65 | { 66 | key = "Environment-Name" 67 | value = "${var.name_prefix}-consul" 68 | propagate_at_launch = true 69 | }, 70 | { 71 | key = "owner" 72 | value = var.owner 73 | propagate_at_launch = true 74 | }, 75 | ] 76 | 77 | lifecycle { 78 | create_before_destroy = true 79 | } 80 | } 81 | 82 | # provides a resource for a new autoscaling group launch configuration 83 | resource "aws_launch_configuration" "consul_servers" { 84 | name = "${random_id.environment_name.hex}-consul-servers-${var.consul_cluster_version}" 85 | image_id = var.ami_id == "" ? data.aws_ami.ubuntu.id : var.ami_id 86 | instance_type = var.instance_type 87 | key_name = var.key_name 88 | security_groups = [aws_security_group.consul.id] 89 | user_data = templatefile("${path.module}/scripts/install_hashitools_consul_server.sh.tpl", 90 | { 91 | ami = data.aws_ami.ubuntu.id, 92 | environment_name = "${var.name_prefix}-consul", 93 | consul_version = var.consul_version, 94 | datacenter = data.aws_region.current.name, 95 | bootstrap_expect = var.consul_servers, 96 | total_nodes = var.consul_servers, 97 | gossip_key = random_id.consul_gossip_encryption_key.b64_std, 98 | master_token = random_uuid.consul_master_token.result, 99 | agent_server_token = random_uuid.consul_agent_server_token.result, 100 | snapshot_token = random_uuid.consul_snapshot_token.result, 101 | consul_cluster_version = var.consul_cluster_version, 102 | acl_bootstrap_bool = var.acl_bootstrap_bool, 103 | enable_connect = var.enable_connect, 104 | consul_config = var.consul_config, 105 | }) 106 | associate_public_ip_address = var.public_ip 107 | iam_instance_profile = aws_iam_instance_profile.instance_profile.name 108 | root_block_device { 109 | volume_type = "io1" 110 | volume_size = 50 111 | iops = "2500" 112 | } 113 | 114 | lifecycle { 115 | create_before_destroy = true 116 | } 117 | } 118 | -------------------------------------------------------------------------------- /modules/consul_cluster/outputs.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/hashicorp/terraform-aws-consul-starter/ac97ed4c0567dbd5c85f0a95b458d88cf0f98ab5/modules/consul_cluster/outputs.tf -------------------------------------------------------------------------------- /modules/consul_cluster/scripts/install_hashitools_consul_client.sh.tpl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # install package 4 | 5 | curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add - 6 | apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" 7 | apt-get update 8 | apt-get install -y consul=${consul_version} 9 | 10 | echo "Configuring system time" 11 | timedatectl set-timezone UTC 12 | 13 | echo "Starting deployment from AMI: ${ami}" 14 | INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id` 15 | AVAILABILITY_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone` 16 | LOCAL_IPV4=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4` 17 | 18 | cat << EOF > /etc/consul.d/consul.hcl 19 | datacenter = "${datacenter}" 20 | server = false 21 | data_dir = "/opt/consul/data" 22 | advertise_addr = "$${LOCAL_IPV4}" 23 | client_addr = "0.0.0.0" 24 | log_level = "INFO" 25 | ui = true 26 | encrypt = "${gossip_key}" 27 | 28 | # AWS cloud join 29 | retry_join = ["provider=aws tag_key=Environment-Name tag_value=${environment_name}"] 30 | EOF 31 | 32 | chown -R consul:consul /etc/consul.d 33 | chmod -R 640 /etc/consul.d/* 34 | 35 | systemctl daemon-reload 36 | systemctl enable consul 37 | systemctl start consul 38 | -------------------------------------------------------------------------------- /modules/consul_cluster/scripts/install_hashitools_consul_server.sh.tpl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | # install package 4 | 5 | curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add - 6 | apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" 7 | apt-get update 8 | apt-get install -y consul=${consul_version} 9 | 10 | echo "Installing jq" 11 | curl --silent -Lo /bin/jq https://github.com/stedolan/jq/releases/download/jq-1.5/jq-linux64 12 | chmod +x /bin/jq 13 | 14 | echo "Configuring system time" 15 | timedatectl set-timezone UTC 16 | 17 | echo "Starting deployment from AMI: ${ami}" 18 | INSTANCE_ID=`curl -s http://169.254.169.254/latest/meta-data/instance-id` 19 | AVAILABILITY_ZONE=`curl -s http://169.254.169.254/latest/meta-data/placement/availability-zone` 20 | LOCAL_IPV4=`curl -s http://169.254.169.254/latest/meta-data/local-ipv4` 21 | 22 | cat << EOF > /etc/consul.d/consul.hcl 23 | datacenter = "${datacenter}" 24 | server = true 25 | bootstrap_expect = ${bootstrap_expect} 26 | data_dir = "/opt/consul/data" 27 | advertise_addr = "$${LOCAL_IPV4}" 28 | client_addr = "0.0.0.0" 29 | log_level = "INFO" 30 | ui = true 31 | 32 | # AWS cloud join 33 | retry_join = ["provider=aws tag_key=Environment-Name tag_value=${environment_name}"] 34 | 35 | # Max connections for the HTTP API 36 | limits { 37 | http_max_conns_per_client = 128 38 | } 39 | performance { 40 | raft_multiplier = 1 41 | } 42 | 43 | acl { 44 | enabled = true 45 | %{ if acl_bootstrap_bool }default_policy = "allow"%{ else }default_policy = "deny"%{ endif } 46 | enable_token_persistence = true 47 | tokens { 48 | master = "${master_token}"%{ if !acl_bootstrap_bool } 49 | agent = "${agent_server_token}"%{ endif } 50 | } 51 | } 52 | 53 | encrypt = "${gossip_key}" 54 | EOF 55 | 56 | cat << EOF > /etc/consul.d/autopilot.hcl 57 | autopilot { 58 | upgrade_version_tag = "consul_cluster_version" 59 | } 60 | EOF 61 | 62 | cat << EOF > /etc/consul.d/cluster_version.hcl 63 | node_meta = { 64 | consul_cluster_version = "${consul_cluster_version}" 65 | } 66 | EOF 67 | 68 | %{ if enable_connect } 69 | cat << EOF > /etc/consul.d/connect.hcl 70 | connect { 71 | enabled = true 72 | } 73 | EOF 74 | %{ endif } 75 | 76 | %{ if consul_config != {} } 77 | cat << EOF > /etc/consul.d/zz-override.json 78 | ${jsonencode(consul_config)} 79 | EOF 80 | %{ endif } 81 | 82 | 83 | %{ if acl_bootstrap_bool } 84 | cat << EOF > /tmp/bootstrap_tokens.sh 85 | #!/bin/bash 86 | export CONSUL_HTTP_TOKEN=${master_token} 87 | echo "Creating Consul ACL policies......" 88 | if ! consul kv get acl_bootstrap 2>/dev/null; then 89 | consul kv put acl_bootstrap 1 90 | 91 | echo ' 92 | node_prefix "" { 93 | policy = "write" 94 | } 95 | service_prefix "" { 96 | policy = "read" 97 | } 98 | service "consul" { 99 | policy = "write" 100 | } 101 | agent_prefix "" { 102 | policy = "write" 103 | }' | consul acl policy create -name consul-agent-server -rules - 104 | 105 | # echo ' 106 | # acl = "write" 107 | # key "consul-snapshot/lock" { 108 | # policy = "write" 109 | # } 110 | # session_prefix "" { 111 | # policy = "write" 112 | # } 113 | # service "consul-snapshot" { 114 | # policy = "write" 115 | # }' | consul acl policy create -name snapshot_agent -rules - 116 | 117 | echo ' 118 | node_prefix "" { 119 | policy = "read" 120 | } 121 | service_prefix "" { 122 | policy = "read" 123 | } 124 | session_prefix "" { 125 | policy = "read" 126 | } 127 | agent_prefix "" { 128 | policy = "read" 129 | } 130 | query_prefix "" { 131 | policy = "read" 132 | } 133 | operator = "read"' | consul acl policy create -name anonymous -rules - 134 | 135 | consul acl token create -description "consul agent server token" -policy-name consul-agent-server -secret "${agent_server_token}" 1>/dev/null 136 | # consul acl token create -description "consul snapshot agent" -policy-name snapshot_agent -secret "${snapshot_token}" 1>/dev/null 137 | consul acl token update -id anonymous -policy-name anonymous 1>/dev/null 138 | else 139 | echo "Bootstrap already completed" 140 | fi 141 | EOF 142 | 143 | chmod 700 /tmp/bootstrap_tokens.sh 144 | 145 | %{ endif } 146 | 147 | chown -R consul:consul /etc/consul.d 148 | chmod -R 640 /etc/consul.d/* 149 | 150 | systemctl daemon-reload 151 | systemctl enable consul 152 | systemctl start consul 153 | 154 | # Wait for consul-kv to come online 155 | while true; do 156 | curl -s http://127.0.0.1:8500/v1/catalog/service/consul | jq -e . && break 157 | sleep 5 158 | done 159 | 160 | # Wait until all new node versions are online 161 | until [[ $TOTAL_NEW -ge ${total_nodes} ]]; do 162 | TOTAL_NEW=`curl -s http://127.0.0.1:8500/v1/catalog/service/consul | jq -er 'map(select(.NodeMeta.consul_cluster_version == "${consul_cluster_version}")) | length'` 163 | sleep 5 164 | echo "Current New Node Count: $TOTAL_NEW" 165 | done 166 | 167 | # Wait for a leader 168 | until [[ $LEADER -eq 1 ]]; do 169 | let LEADER=0 170 | echo "Fetching new node ID's" 171 | NEW_NODE_IDS=`curl -s http://127.0.0.1:8500/v1/catalog/service/consul | jq -r 'map(select(.NodeMeta.consul_cluster_version == "${consul_cluster_version}")) | .[].ID'` 172 | # Wait until all new nodes are voting 173 | until [[ $VOTERS -eq ${bootstrap_expect} ]]; do 174 | let VOTERS=0 175 | for ID in $NEW_NODE_IDS; do 176 | echo "Checking $ID" 177 | curl -s http://127.0.0.1:8500/v1/operator/autopilot/health | jq -e ".Servers[] | select(.ID == \"$ID\" and .Voter == true)" && let "VOTERS+=1" && echo "Current Voters: $VOTERS" 178 | sleep 2 179 | done 180 | done 181 | echo "Checking Old Nodes" 182 | OLD_NODES=`curl -s http://127.0.0.1:8500/v1/catalog/service/consul | jq -er 'map(select(.NodeMeta.consul_cluster_version != "${consul_cluster_version}")) | length'` 183 | echo "Current Old Node Count: $OLD_NODES" 184 | # Wait for old nodes to drop from voting 185 | until [[ $OLD_NODES -eq 0 ]]; do 186 | OLD_NODES=`curl -s http://127.0.0.1:8500/v1/catalog/service/consul | jq -er 'map(select(.NodeMeta.consul_cluster_version != "${consul_cluster_version}")) | length'` 187 | OLD_NODE_IDS=`curl -s http://127.0.0.1:8500/v1/catalog/service/consul | jq -r 'map(select(.NodeMeta.consul_cluster_version != "${consul_cluster_version}")) | .[].ID'` 188 | for ID in $OLD_NODE_IDS; do 189 | echo "Checking Old $ID" 190 | curl -s http://127.0.0.1:8500/v1/operator/autopilot/health | jq -e ".Servers[] | select(.ID == \"$ID\" and .Voter == false)" && let "OLD_NODES-=1" && echo "Checking Old Nodes for Voters: $OLD_NODES" 191 | sleep 2 192 | done 193 | done 194 | # Check if there is a leader running the newest version 195 | LEADER_ID=`curl -s http://127.0.0.1:8500/v1/operator/autopilot/health | jq -er ".Servers[] | select(.Leader == true) | .ID"` 196 | curl -s http://127.0.0.1:8500/v1/catalog/service/consul | jq -er ".[] | select(.ID == \"$LEADER_ID\" and .NodeMeta.consul_cluster_version == \"${consul_cluster_version}\")" && let "LEADER+=1" && echo "New Leader: $LEADER_ID" 197 | sleep 2 198 | done 199 | 200 | %{ if acl_bootstrap_bool }/tmp/bootstrap_tokens.sh%{ endif } 201 | echo "$INSTANCE_ID determined all nodes to be healthy and ready to go <3" 202 | -------------------------------------------------------------------------------- /modules/consul_cluster/security_groups.tf: -------------------------------------------------------------------------------- 1 | # creates security group to group access rules under - named with a random UUId and suffix (why?) 2 | resource "aws_security_group" "consul" { 3 | name = "${random_id.environment_name.hex}-consul-sg" 4 | description = "Consul servers" 5 | vpc_id = var.vpc_id 6 | } 7 | 8 | resource "aws_security_group_rule" "consul_ssh" { 9 | security_group_id = aws_security_group.consul.id 10 | type = "ingress" 11 | from_port = 22 12 | to_port = 22 13 | protocol = "tcp" 14 | cidr_blocks = var.allowed_inbound_cidrs 15 | } 16 | 17 | # rule to allow egress from 443 to 443 externally 18 | resource "aws_security_group_rule" "consul_external_egress_https" { 19 | security_group_id = aws_security_group.consul.id 20 | type = "egress" 21 | from_port = 443 22 | to_port = 443 23 | protocol = "tcp" 24 | cidr_blocks = ["0.0.0.0/0"] 25 | } 26 | 27 | # rule to allow egress from 80 to 80 externally 28 | resource "aws_security_group_rule" "consul_external_egress_http" { 29 | security_group_id = aws_security_group.consul.id 30 | type = "egress" 31 | from_port = 80 32 | to_port = 80 33 | protocol = "tcp" 34 | cidr_blocks = ["0.0.0.0/0"] 35 | } 36 | 37 | # rule to allow internal egress from 8300 to 8600 TCP 38 | resource "aws_security_group_rule" "consul_internal_egress_tcp" { 39 | security_group_id = aws_security_group.consul.id 40 | type = "egress" 41 | from_port = 8300 42 | to_port = 8600 43 | protocol = "tcp" 44 | source_security_group_id = aws_security_group.consul.id 45 | } 46 | 47 | # rule to allow internal egress from 8300 to 8600 UDP 48 | resource "aws_security_group_rule" "consul_internal_egress_udp" { 49 | security_group_id = aws_security_group.consul.id 50 | type = "egress" 51 | from_port = 8300 52 | to_port = 8600 53 | protocol = "udp" 54 | source_security_group_id = aws_security_group.consul.id 55 | } 56 | 57 | // This rule allows Consul RPC. 58 | resource "aws_security_group_rule" "consul_rpc" { 59 | security_group_id = aws_security_group.consul.id 60 | type = "ingress" 61 | from_port = 8300 62 | to_port = 8300 63 | protocol = "tcp" 64 | source_security_group_id = aws_security_group.consul.id 65 | } 66 | 67 | // This rule allows Consul Serf TCP. 68 | resource "aws_security_group_rule" "consul_serf_tcp" { 69 | security_group_id = aws_security_group.consul.id 70 | type = "ingress" 71 | from_port = 8301 72 | to_port = 8302 73 | protocol = "tcp" 74 | source_security_group_id = aws_security_group.consul.id 75 | } 76 | 77 | // This rule allows Consul Serf UDP. 78 | resource "aws_security_group_rule" "consul_serf_udp" { 79 | security_group_id = aws_security_group.consul.id 80 | type = "ingress" 81 | from_port = 8301 82 | to_port = 8302 83 | protocol = "udp" 84 | source_security_group_id = aws_security_group.consul.id 85 | } 86 | 87 | // This rule allows Consul API. 88 | resource "aws_security_group_rule" "consul_api_tcp" { 89 | security_group_id = aws_security_group.consul.id 90 | type = "ingress" 91 | from_port = 8500 92 | to_port = 8500 93 | protocol = "tcp" 94 | source_security_group_id = aws_security_group.consul.id 95 | } 96 | 97 | // This rule exposes the Consul API for traffic from the same CIDR block as approved SSH. 98 | resource "aws_security_group_rule" "consul_ui_ingress" { 99 | security_group_id = aws_security_group.consul.id 100 | type = "ingress" 101 | from_port = 8500 102 | to_port = 8500 103 | protocol = "tcp" 104 | cidr_blocks = var.allowed_inbound_cidrs 105 | } 106 | 107 | // This rule allows Consul DNS. 108 | resource "aws_security_group_rule" "consul_dns_tcp" { 109 | security_group_id = aws_security_group.consul.id 110 | type = "ingress" 111 | from_port = 8600 112 | to_port = 8600 113 | protocol = "tcp" 114 | source_security_group_id = aws_security_group.consul.id 115 | } 116 | 117 | // This rule allows Consul DNS. 118 | resource "aws_security_group_rule" "consul_dns_udp" { 119 | security_group_id = aws_security_group.consul.id 120 | type = "ingress" 121 | from_port = 8600 122 | to_port = 8600 123 | protocol = "udp" 124 | source_security_group_id = aws_security_group.consul.id 125 | } 126 | -------------------------------------------------------------------------------- /modules/consul_cluster/variables.tf: -------------------------------------------------------------------------------- 1 | # Required Parameters 2 | variable "allowed_inbound_cidrs" { 3 | type = list(string) 4 | description = "List of CIDR blocks to permit inbound Consul access from" 5 | } 6 | 7 | variable "consul_version" { 8 | type = string 9 | description = "Consul version to install" 10 | } 11 | 12 | variable "name_prefix" { 13 | type = string 14 | description = "prefix used in resource names" 15 | } 16 | 17 | variable "owner" { 18 | type = string 19 | description = "value of owner tag on EC2 instances" 20 | } 21 | 22 | 23 | variable "vpc_id" { 24 | type = string 25 | description = "VPC ID" 26 | } 27 | 28 | # Optional Parameters 29 | variable "acl_bootstrap_bool" { 30 | type = bool 31 | default = true 32 | description = "Initial ACL Bootstrap configurations" 33 | } 34 | 35 | variable "consul_clients" { 36 | type = number 37 | default = "3" 38 | description = "number of Consul instances" 39 | } 40 | 41 | variable "consul_config" { 42 | type = map(string) 43 | default = {} 44 | description = "HCL Object with additional configuration overrides supplied to the consul servers. This is converted to JSON before rendering via the template." 45 | } 46 | 47 | variable "consul_cluster_version" { 48 | type = string 49 | default = "0.0.1" 50 | description = "Custom Version Tag for Upgrade Migrations" 51 | } 52 | 53 | variable "consul_servers" { 54 | type = number 55 | default = "5" 56 | description = "number of Consul instances" 57 | } 58 | 59 | variable "enable_connect" { 60 | type = bool 61 | default = false 62 | description = "Whether Consul Connect should be enabled on the cluster" 63 | } 64 | 65 | variable "instance_type" { 66 | type = string 67 | default = "m5.large" 68 | description = "Instance type for Consul instances" 69 | } 70 | 71 | variable "key_name" { 72 | type = string 73 | default = "default" 74 | description = "SSH key name for Consul instances" 75 | } 76 | 77 | variable "public_ip" { 78 | type = bool 79 | default = false 80 | description = "should ec2 instance have public ip?" 81 | } 82 | 83 | variable "ami_id" { 84 | type = string 85 | default = "" 86 | description = "EC2 instance AMI ID to override the default Ubuntu AMI" 87 | } -------------------------------------------------------------------------------- /modules/consul_cluster/versions.tf: -------------------------------------------------------------------------------- 1 | # names required TF version 2 | terraform { 3 | required_version = ">= 0.12" 4 | required_providers { 5 | aws = "~> 2.70.0" 6 | random = "~> 2.3.0" 7 | } 8 | } 9 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "acl_bootstrap_bool" { 2 | type = bool 3 | default = true 4 | description = "Initial ACL Bootstrap configurations" 5 | } 6 | 7 | variable "allowed_inbound_cidrs" { 8 | type = list(string) 9 | description = "List of CIDR blocks to permit inbound Consul access from" 10 | } 11 | 12 | variable "consul_clients" { 13 | default = "3" 14 | description = "number of Consul instances" 15 | } 16 | 17 | variable "consul_config" { 18 | description = "HCL Object with additional configuration overrides supplied to the consul servers. This is converted to JSON before rendering via the template." 19 | default = {} 20 | } 21 | 22 | variable "consul_cluster_version" { 23 | default = "0.0.1" 24 | description = "Custom Version Tag for Upgrade Migrations" 25 | } 26 | 27 | variable "consul_servers" { 28 | default = "5" 29 | description = "number of Consul instances" 30 | } 31 | 32 | variable "consul_version" { 33 | description = "Consul version" 34 | } 35 | 36 | variable "enable_connect" { 37 | type = bool 38 | description = "Whether Consul Connect should be enabled on the cluster" 39 | default = false 40 | } 41 | 42 | variable "instance_type" { 43 | default = "m5.large" 44 | description = "Instance type for Consul instances" 45 | } 46 | 47 | variable "key_name" { 48 | default = "default" 49 | description = "SSH key name for Consul instances" 50 | } 51 | 52 | variable "name_prefix" { 53 | description = "prefix used in resource names" 54 | } 55 | 56 | variable "owner" { 57 | description = "value of owner tag on EC2 instances" 58 | } 59 | 60 | variable "public_ip" { 61 | type = bool 62 | default = false 63 | description = "should ec2 instance have public ip?" 64 | } 65 | 66 | variable "vpc_id" { 67 | description = "VPC ID" 68 | } 69 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | # names required TF version 2 | terraform { 3 | required_version = ">= 0.13" 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = "2.70.0" 8 | } 9 | random = { 10 | source = "hashicorp/random" 11 | version = "2.3.0" 12 | } 13 | template = { 14 | source = "hashicorp/template" 15 | version = "2.1.2" 16 | } 17 | } 18 | } 19 | --------------------------------------------------------------------------------