├── .github ├── actions │ └── integration_tests │ │ └── action.yml └── workflows │ ├── integration.yml │ ├── lint.yml │ └── ok-to-test.yml ├── .gitignore ├── CHANGELOG.md ├── CODE_OF_CONDUCT ├── LICENSE ├── README.md ├── examples └── prereqs_quickstart │ ├── README.md │ ├── aws-vpc │ ├── main.tf │ ├── outputs.tf │ └── variables.tf │ ├── main.tf │ ├── outputs.tf │ ├── secrets │ ├── acm.tf │ ├── main.tf │ ├── outputs.tf │ ├── tls.tf │ └── variables.tf │ ├── variables.tf │ └── versions.tf ├── main.tf ├── modules ├── iam │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── kms │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── load_balancer │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── networking │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── user_data │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ ├── templates │ │ └── install_vault.sh.tpl │ └── variables.tf └── vm │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ └── variables.tf ├── outputs.tf ├── test ├── .gitignore ├── .terraform-version ├── README.md ├── deployment_test.go ├── go.mod ├── go.sum ├── main.tf ├── test.tf ├── utils.go └── variables.tf ├── variables.tf └── versions.tf /.github/actions/integration_tests/action.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2014-2022 HashiCorp, Inc. 2 | # 3 | # This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | 6 | name: Run integration tests 7 | description: Deploy infrastructure, test it, and destroy it 8 | inputs: 9 | env_suffix: 10 | description: 'Environment suffix' 11 | required: true 12 | runs: 13 | using: "composite" 14 | steps: 15 | - run: echo "Installing dependencies" 16 | shell: bash 17 | - name: Install dependencies 18 | run: | 19 | TFENV_DL_TMP=$(mktemp -d) 20 | curl -Lo $TFENV_DL_TMP/tfenv.zip https://github.com/tfutils/tfenv/archive/2989f1a5560e313f70f7711be592ddb68418862b.zip 21 | unzip $TFENV_DL_TMP/tfenv.zip -d $TFENV_DL_TMP 22 | mv $TFENV_DL_TMP/tfenv-2989f1a5560e313f70f7711be592ddb68418862b ~/.tfenv 23 | echo "$HOME/.tfenv/bin" >> $GITHUB_PATH 24 | shell: bash 25 | - run: echo "Deploying and running tests" 26 | shell: bash 27 | - name: Deploy and run tests 28 | run: tfenv install && DEPLOY_ENV=inttest${{ inputs.env_suffix }} go test -v -timeout 120m 29 | working-directory: ./test 30 | shell: bash 31 | - run: echo "Integration tests succeeded" 32 | shell: bash 33 | -------------------------------------------------------------------------------- /.github/workflows/integration.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2014-2022 HashiCorp, Inc. 2 | # 3 | # This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | 6 | name: Integration tests 7 | concurrency: integration_tests 8 | 9 | on: 10 | pull_request: 11 | paths-ignore: 12 | - '**/README.md' 13 | - '**/CHANGELOG.md' 14 | repository_dispatch: 15 | types: [ok-to-test-command] 16 | 17 | jobs: 18 | # Branch-based pull request 19 | integration-trusted: 20 | runs-on: ubuntu-latest 21 | if: github.event_name == 'pull_request' && github.event.pull_request.head.repo.full_name == github.repository 22 | env: 23 | AWS_DEFAULT_REGION: us-east-2 24 | AWS_PERMISSIONS_BOUNDARY: ${{ secrets.AWS_PERMISSIONS_BOUNDARY }} 25 | TF_TOKEN_app_terraform_io: ${{ secrets.TF_TOKEN_app_terraform_io }} 26 | steps: 27 | - name: Branch based PR checkout 28 | uses: actions/checkout@v2 29 | - name: Configure AWS Credentials 30 | uses: aws-actions/configure-aws-credentials@v1 31 | with: 32 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 33 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 34 | aws-region: us-east-2 35 | role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} 36 | role-duration-seconds: 7200 37 | role-session-name: githubactionsuser 38 | - id: integration-test 39 | uses: ./.github/actions/integration_tests 40 | with: 41 | env_suffix: ${{ github.event.pull_request.number }} 42 | 43 | # Repo owner has commented /ok-to-test on a (fork-based) pull request 44 | integration-fork: 45 | runs-on: ubuntu-latest 46 | if: 47 | github.event_name == 'repository_dispatch' && 48 | github.event.client_payload.slash_command.sha != '' && 49 | contains(github.event.client_payload.pull_request.head.sha, github.event.client_payload.slash_command.sha) 50 | env: 51 | AWS_DEFAULT_REGION: us-east-2 52 | AWS_PERMISSIONS_BOUNDARY: ${{ secrets.AWS_PERMISSIONS_BOUNDARY }} 53 | TF_TOKEN_app_terraform_io: ${{ secrets.TF_TOKEN_app_terraform_io }} 54 | steps: 55 | # Check out merge commit 56 | - name: Fork based /ok-to-test checkout 57 | uses: actions/checkout@v2 58 | with: 59 | ref: 'refs/pull/${{ github.event.client_payload.pull_request.number }}/merge' 60 | - name: Configure AWS Credentials 61 | uses: aws-actions/configure-aws-credentials@v1 62 | with: 63 | aws-access-key-id: ${{ secrets.AWS_ACCESS_KEY_ID }} 64 | aws-secret-access-key: ${{ secrets.AWS_SECRET_ACCESS_KEY }} 65 | aws-region: us-east-2 66 | role-to-assume: ${{ secrets.AWS_ROLE_TO_ASSUME }} 67 | role-duration-seconds: 7200 68 | role-session-name: githubactionsuser 69 | - id: integration-test 70 | uses: ./.github/actions/integration_tests 71 | with: 72 | env_suffix: ${{ github.event.client_payload.pull_request.number }} 73 | 74 | # Update check run called "integration-fork" 75 | - uses: actions/github-script@v1 76 | id: update-check-run 77 | if: ${{ always() }} 78 | env: 79 | number: ${{ github.event.client_payload.pull_request.number }} 80 | job: ${{ github.job }} 81 | # Conveniently, job.status maps to https://developer.github.com/v3/checks/runs/#update-a-check-run 82 | conclusion: ${{ job.status }} 83 | with: 84 | github-token: ${{ secrets.GITHUB_TOKEN }} 85 | script: | 86 | const { data: pull } = await github.pulls.get({ 87 | ...context.repo, 88 | pull_number: process.env.number 89 | }); 90 | const ref = pull.head.sha; 91 | 92 | const { data: checks } = await github.checks.listForRef({ 93 | ...context.repo, 94 | ref 95 | }); 96 | 97 | const check = checks.check_runs.filter(c => c.name === process.env.job); 98 | 99 | const { data: result } = await github.checks.update({ 100 | ...context.repo, 101 | check_run_id: check[0].id, 102 | status: 'completed', 103 | conclusion: process.env.conclusion 104 | }); 105 | 106 | return result; 107 | -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2014-2022 HashiCorp, Inc. 2 | # 3 | # This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | 6 | name: Lint 7 | 8 | on: 9 | push: 10 | branches: 11 | - main 12 | paths-ignore: 13 | - '**/CHANGELOG.md' 14 | - '**/README.md' 15 | pull_request: 16 | paths-ignore: 17 | - '**/CHANGELOG.md' 18 | - '**/README.md' 19 | 20 | jobs: 21 | test: 22 | name: Lint 23 | runs-on: ubuntu-latest 24 | steps: 25 | - name: Checkout code 26 | uses: actions/checkout@v2 27 | - name: Setup tfenv 28 | run: | 29 | TFENV_DL_TMP=$(mktemp -d) 30 | curl -Lo $TFENV_DL_TMP/tfenv.zip https://github.com/tfutils/tfenv/archive/2989f1a5560e313f70f7711be592ddb68418862b.zip 31 | unzip $TFENV_DL_TMP/tfenv.zip -d $TFENV_DL_TMP 32 | mv $TFENV_DL_TMP/tfenv-2989f1a5560e313f70f7711be592ddb68418862b ~/.tfenv 33 | echo "$HOME/.tfenv/bin" >> $GITHUB_PATH 34 | echo "latest:^1.0" > .terraform-version 35 | - name: Check Terraform formatting 36 | run: tfenv install && terraform fmt -check -recursive 37 | -------------------------------------------------------------------------------- /.github/workflows/ok-to-test.yml: -------------------------------------------------------------------------------- 1 | # Copyright © 2014-2022 HashiCorp, Inc. 2 | # 3 | # This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 4 | # 5 | 6 | # If someone with write access comments "/ok-to-test" on a pull request, emit a repository_dispatch event 7 | name: Ok To Test 8 | 9 | on: 10 | issue_comment: 11 | types: [created] 12 | 13 | jobs: 14 | ok-to-test: 15 | runs-on: ubuntu-latest 16 | # Only run for PRs, not issue comments 17 | if: ${{ github.event.issue.pull_request }} 18 | steps: 19 | # Generate a GitHub App installation access token from an App ID and private key 20 | # To create a new GitHub App: 21 | # https://developer.github.com/apps/building-github-apps/creating-a-github-app/ 22 | # See app.yml for an example app manifest 23 | - name: Generate token 24 | id: generate_token 25 | uses: tibdex/github-app-token@cdb5bfda87db263e4be5c6f570c4c39611ee952a # v1.4.0 26 | with: 27 | app_id: ${{ secrets.APP_ID }} 28 | private_key: ${{ secrets.PRIVATE_KEY }} 29 | 30 | - name: Slash Command Dispatch 31 | uses: peter-evans/slash-command-dispatch@fc430081ad51bb37d160fa3a3ee718c121e6b90d # v2.2.1 32 | env: 33 | TOKEN: ${{ steps.generate_token.outputs.token }} 34 | with: 35 | token: ${{ env.TOKEN }} # GitHub App installation access token 36 | # token: ${{ secrets.PERSONAL_ACCESS_TOKEN }} # PAT or OAuth token will also work 37 | reaction-token: ${{ secrets.GITHUB_TOKEN }} 38 | issue-type: pull-request 39 | commands: ok-to-test 40 | named-args: true 41 | permission: write 42 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Local .terraform directories 2 | **/.terraform/* 3 | 4 | # .tfstate files 5 | *.tfstate 6 | *.tfstate.* 7 | 8 | # Crash log files 9 | crash.log 10 | 11 | # Ignore any .tfvars files that are generated automatically for each Terraform run. Most 12 | # .tfvars files are managed as part of configuration and so should be included in 13 | # version control. 14 | # 15 | # example.tfvars 16 | 17 | # Ignore override files as they are usually used to override resources locally and so 18 | # are not checked in 19 | override.tf 20 | override.tf.json 21 | *_override.tf 22 | *_override.tf.json 23 | 24 | # Include override files you do wish to add to version control using negated pattern 25 | # 26 | # !example_override.tf 27 | 28 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan 29 | # example: *tfplan* 30 | -------------------------------------------------------------------------------- /CHANGELOG.md: -------------------------------------------------------------------------------- 1 | ## Unreleased 2 | 3 | IMPROVEMENTS: 4 | 5 | * Update package name syntax in userdata script to prevent breakage when installing latest versions of Vault enterprise. 6 | * Update examples directory with quickstart file that reduces number of steps to 7 | provision pre-reqs 8 | * Remove data sources for AWS subnets and allow user to explicitly specify 9 | private subnet IDs in main module 10 | * Update main module outputs 11 | * Update default Vault version 12 | * Update Terraform version pin 13 | * Add `permissions_boundary` variable to support creating the IAM Role with a permissions boundary 14 | 15 | ## 1.0.0 (September 22, 2021) 16 | 17 | IMPROVEMENTS: 18 | 19 | * Updated README 20 | * Break code into submodules and add submodule READMEs 21 | * Deploy Vault nodes into private subnets for better security 22 | * Better reflect Vault reference architecture and deployment guide 23 | * Require TLS certs on nodes and load balancers 24 | * Remove lambda functions and use autopilot features for server cleanup 25 | * Tighten file/folder permissions created in userdata script 26 | * Add AWS Session Manager capability for logging into nodes 27 | 28 | ## 0.2.3 (February 04, 2021) 29 | 30 | IMPROVEMENTS: 31 | 32 | * Clarify README 33 | 34 | ## 0.2.2 (February 04, 2021) 35 | 36 | IMPROVEMENTS: 37 | 38 | * Increased `wait_for_capacity_timeout` in ASG to make sure `terraform apply` doesn't time out 39 | 40 | ## 0.2.1 (August 19, 2020) 41 | 42 | IMPROVEMENTS: 43 | 44 | * security: 45 | - added security group rule to expose API/UI to allowed CIDR blocks 46 | - exposed `elb_internal` variable to user 47 | * documentation: updated README 48 | 49 | ## 0.2.0 (August 13, 2020) 50 | 51 | IMPROVEMENTS: 52 | 53 | * Upgrading terraform block syntax for TF version 0.13.0+ 54 | * Pinning version number for `aws`, `random`, and `template` providers 55 | 56 | ## 0.1.2 (July 09, 2020) 57 | 58 | IMPROVEMENTS: 59 | 60 | * security: added security group rule for inbound on port 22 and variable for 61 | approved CIDR blocks 62 | 63 | ## 0.1.1 (July 2, 2020) 64 | 65 | IMPROVEMENTS: 66 | 67 | * documentation: updated refs and corrected links 68 | * documentation: added CHANGELOG 69 | 70 | ## 0.1.0 (July 2, 2020) 71 | 72 | * Initial release 73 | -------------------------------------------------------------------------------- /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 | # Vault AWS Module 2 | 3 | This is a Terraform module for provisioning Vault with [integrated 4 | storage](https://www.vaultproject.io/docs/concepts/integrated-storage) on AWS. 5 | This module defaults to setting up a cluster with 5 Vault nodes (as recommended 6 | by the [Vault with Integrated Storage Reference 7 | Architecture](https://learn.hashicorp.com/vault/operations/raft-reference-architecture)). 8 | 9 | ## About This Module 10 | This module implements the [Vault with Integrated Storage Reference 11 | Architecture](https://learn.hashicorp.com/vault/operations/raft-reference-architecture#node) 12 | on AWS using the open source version of Vault 1.8+. 13 | 14 | ## How to Use This Module 15 | 16 | - Ensure your AWS credentials are [configured 17 | correctly](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) 18 | and have permission to use the following AWS services: 19 | - Amazon Certificate Manager (ACM) 20 | - Amazon EC2 21 | - Amazon Elastic Load Balancing (ALB) 22 | - AWS Identity & Access Management (IAM) 23 | - AWS Key Management System (KMS) 24 | - Amazon Secrets Manager 25 | - AWS Systems Manager Session Manager (optional - used to connect to EC2 26 | instances with session manager using the AWS CLI) 27 | - Amazon VPC 28 | 29 | - This module assumes you have an existing VPC along with an AWS secrets manager 30 | that contains TLS certs for the Vault nodes and load balancer. If you do not, 31 | you may use the following 32 | [quickstart](https://github.com/hashicorp/terraform-aws-vault-starter/tree/main/examples/prereqs_quickstart) 33 | to deploy these resources. 34 | 35 | - To deploy into an existing VPC, ensure the following components exist and are 36 | routed to each other correctly: 37 | - Three public subnets 38 | - Three [NAT 39 | gateways](https://docs.aws.amazon.com/vpc/latest/userguide/vpc-nat-gateway.html) (one in each public subnet) 40 | - Three private subnets 41 | 42 | - Create a Terraform configuration that pulls in the Vault module and specifies 43 | values for the required variables: 44 | 45 | ```hcl 46 | provider "aws" { 47 | # your AWS region 48 | region = "us-east-1" 49 | } 50 | 51 | module "vault" { 52 | source = "hashicorp/vault-starter/aws" 53 | version = "~> 1.0" 54 | 55 | # prefix for tagging/naming AWS resources 56 | resource_name_prefix = "test" 57 | # VPC ID you wish to deploy into 58 | vpc_id = "vpc-abc123xxx" 59 | # private subnet IDs are required and allow you to specify which 60 | # subnets you will deploy your Vault nodes into 61 | private_subnet_ids = [ 62 | "subnet-0xyz", 63 | "subnet-1xyz", 64 | "subnet-2xyz", 65 | ] 66 | # AWS Secrets Manager ARN where TLS certs are stored 67 | secrets_manager_arn = "arn:aws::secretsmanager:abc123xxx" 68 | # The shared DNS SAN of the TLS certs being used 69 | leader_tls_servername = "vault.server.com" 70 | # The cert ARN to be used on the Vault LB listener 71 | lb_certificate_arn = "arn:aws:acm:abc123xxx" 72 | } 73 | ``` 74 | 75 | - Run `terraform init` and `terraform apply` 76 | 77 | - You must 78 | [initialize](https://www.vaultproject.io/docs/commands/operator/init#operator-init) 79 | your Vault cluster after you create it. Begin by logging into your Vault 80 | cluster using one of the following methods: 81 | - Using [Session 82 | Manager](https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/session-manager.html) 83 | - SSH (you must provide the optional SSH key pair through the `key_name` 84 | variable and set a value for the `allowed_inbound_cidrs_ssh` variable. 85 | - Please note this Vault cluster is not public-facing. If you want to 86 | use SSH from outside the VPC, you are required to establish your own 87 | connection to it (VPN, etc). 88 | 89 | **Please Note**: if you are using Session Manager to connect to your nodes and 90 | will run vault commands as the default `ssm-user`, it is important you first run 91 | the following command to source the environment variables that Vault requires: 92 | 93 | ``` 94 | $ . /etc/profile 95 | ``` 96 | 97 | - To initialize the Vault cluster, run the following commands: 98 | 99 | ```bash 100 | vault operator init 101 | ``` 102 | 103 | - This should return back the following output which includes the recovery 104 | keys and initial root token (omitted here): 105 | 106 | ``` 107 | ... 108 | Success! Vault is initialized 109 | ``` 110 | 111 | - Please securely store the recovery keys and initial root token that Vault 112 | returns to you. 113 | - To check the status of your Vault cluster, export your Vault token and run 114 | the 115 | [list-peers](https://www.vaultproject.io/docs/commands/operator/raft#list-peers) 116 | command: 117 | 118 | ```bash 119 | export VAULT_TOKEN="" 120 | vault operator raft list-peers 121 | ``` 122 | 123 | - Please note that Vault does not enable [dead server 124 | cleanup](https://www.vaultproject.io/docs/concepts/integrated-storage/autopilot#dead-server-cleanup) 125 | by default. You must enable this to avoid manually managing the Raft 126 | configuration every time there is a change in the Vault ASG. To enable dead 127 | server cleanup, run the following command: 128 | 129 | ```bash 130 | vault operator raft autopilot set-config \ 131 | -cleanup-dead-servers=true \ 132 | -dead-server-last-contact-threshold=10 \ 133 | -min-quorum=3 134 | ``` 135 | 136 | - You can verify these settings after you apply them by running the following command: 137 | 138 | ```bash 139 | vault operator raft autopilot get-config 140 | ``` 141 | 142 | ## License 143 | 144 | This code is released under the Mozilla Public License 2.0. Please see 145 | [LICENSE](https://github.com/hashicorp/terraform-aws-vault-starter/blob/main/LICENSE) 146 | for more details. 147 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/README.md: -------------------------------------------------------------------------------- 1 | # EXAMPLE: Prerequisite Configuration (VPC and Secrets) 2 | 3 | ## About This Example 4 | 5 | In order to deploy the Vault module, you must have an AWS VPC that 6 | meets the requirements [listed in the main 7 | README](../../README.md#how-to-use-this-module) along with TLS certs that can be 8 | used with the Vault nodes and load balancer. If you do not already have these 9 | resources, you can use the code provided in this directory to provision them. 10 | 11 | ## How to Use This Module 12 | 13 | 1. Ensure your AWS credentials are [configured 14 | correctly](https://docs.aws.amazon.com/cli/latest/userguide/cli-configure-files.html) 15 | 2. Configure required (and optional if desired) variables 16 | 3. Run `terraform init` and `terraform apply` 17 | 18 | ## Required variables 19 | 20 | * `resource_name_prefix` - string value to use as base for resource names 21 | 22 | ## Note 23 | 24 | - The default AWS region is `us-east-1` (as specified by the `aws_region` 25 | variable). You may change this if wish to deploy Vault elsewhere, but please 26 | be sure to change the value for the `azs` variable as well and specify the 27 | appropriate availability zones for your new region. 28 | 29 | ### Security Note: 30 | - The [Terraform State](https://www.terraform.io/docs/language/state/index.html) 31 | produced by this code has sensitive data (cert private keys) stored in it. 32 | Please secure your Terraform state using the [recommendations listed 33 | here](https://www.terraform.io/docs/language/state/sensitive-data.html#recommendations). 34 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/aws-vpc/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | module "vpc" { 9 | source = "terraform-aws-modules/vpc/aws" 10 | version = "3.0.0" 11 | name = "${var.resource_name_prefix}-vault" 12 | cidr = var.vpc_cidr 13 | azs = var.azs 14 | enable_nat_gateway = true 15 | one_nat_gateway_per_az = true 16 | private_subnets = var.private_subnet_cidrs 17 | public_subnets = var.public_subnet_cidrs 18 | 19 | tags = var.common_tags 20 | } 21 | 22 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/aws-vpc/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "private_subnet_ids" { 9 | description = "Private subnet IDs" 10 | value = module.vpc.private_subnets 11 | } 12 | 13 | output "vpc_id" { 14 | description = "The ID of the VPC" 15 | value = module.vpc.vpc_id 16 | } 17 | 18 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/aws-vpc/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "azs" { 9 | description = "availability zones to use in AWS region" 10 | type = list(string) 11 | } 12 | 13 | variable "common_tags" { 14 | type = map(string) 15 | description = "Tags for VPC resources" 16 | } 17 | 18 | variable "resource_name_prefix" { 19 | description = "Prefix for resource names (e.g. \"prod\")" 20 | type = string 21 | } 22 | 23 | variable "private_subnet_cidrs" { 24 | description = "CIDR blocks for private subnets" 25 | type = list(string) 26 | default = [ 27 | "10.0.0.0/19", 28 | "10.0.32.0/19", 29 | "10.0.64.0/19", 30 | ] 31 | } 32 | 33 | variable "public_subnet_cidrs" { 34 | description = "CIDR blocks for public subnets" 35 | type = list(string) 36 | default = [ 37 | "10.0.128.0/20", 38 | "10.0.144.0/20", 39 | "10.0.160.0/20", 40 | ] 41 | } 42 | 43 | variable "vpc_cidr" { 44 | description = "CIDR block for VPC" 45 | type = string 46 | default = "10.0.0.0/16" 47 | } 48 | 49 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | provider "aws" { 9 | region = var.aws_region 10 | } 11 | 12 | module "vpc" { 13 | source = "./aws-vpc/" 14 | 15 | azs = var.azs 16 | common_tags = var.tags 17 | resource_name_prefix = var.resource_name_prefix 18 | } 19 | 20 | module "secrets" { 21 | source = "./secrets/" 22 | 23 | resource_name_prefix = var.resource_name_prefix 24 | } 25 | 26 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "lb_certificate_arn" { 9 | description = "ARN of ACM cert to use with Vault LB listener" 10 | value = module.secrets.lb_certificate_arn 11 | } 12 | 13 | output "leader_tls_servername" { 14 | description = "Shared SAN that will be given to the Vault nodes configuration for use as leader_tls_servername" 15 | value = module.secrets.leader_tls_servername 16 | } 17 | 18 | output "private_subnet_ids" { 19 | description = "Private subnet IDs" 20 | value = module.vpc.private_subnet_ids 21 | } 22 | 23 | output "secrets_manager_arn" { 24 | description = "ARN of secrets_manager secret" 25 | value = module.secrets.secrets_manager_arn 26 | } 27 | 28 | output "vpc_id" { 29 | description = "The ID of the VPC" 30 | value = module.vpc.vpc_id 31 | } 32 | 33 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/acm.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_acm_certificate" "vault" { 9 | private_key = tls_private_key.server.private_key_pem 10 | certificate_body = tls_locally_signed_cert.server.cert_pem 11 | certificate_chain = tls_self_signed_cert.ca.cert_pem 12 | } 13 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_secretsmanager_secret" "tls" { 9 | name = "${var.resource_name_prefix}-tls-secret" 10 | description = "contains TLS certs and private keys" 11 | kms_key_id = var.kms_key_id 12 | recovery_window_in_days = var.recovery_window 13 | tags = var.tags 14 | } 15 | 16 | resource "aws_secretsmanager_secret_version" "tls" { 17 | secret_id = aws_secretsmanager_secret.tls.id 18 | secret_string = local.secret 19 | } 20 | 21 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "lb_certificate_arn" { 9 | description = "ARN of ACM cert to use with Vault LB listener" 10 | value = aws_acm_certificate.vault.arn 11 | } 12 | 13 | output "leader_tls_servername" { 14 | description = "Shared SAN that will be given to the Vault nodes configuration for use as leader_tls_servername" 15 | value = var.shared_san 16 | } 17 | 18 | output "secrets_manager_arn" { 19 | description = "ARN of secrets_manager secret" 20 | value = aws_secretsmanager_secret.tls.arn 21 | } 22 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/tls.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | # Generate a private key so you can create a CA cert with it. 9 | resource "tls_private_key" "ca" { 10 | algorithm = "RSA" 11 | rsa_bits = 2048 12 | } 13 | 14 | # Create a CA cert with the private key you just generated. 15 | resource "tls_self_signed_cert" "ca" { 16 | private_key_pem = tls_private_key.ca.private_key_pem 17 | 18 | subject { 19 | common_name = "ca.vault.server.com" 20 | } 21 | 22 | validity_period_hours = 720 # 30 days 23 | 24 | allowed_uses = [ 25 | "cert_signing", 26 | "crl_signing", 27 | ] 28 | 29 | is_ca_certificate = true 30 | 31 | # provisioner "local-exec" { 32 | # command = "echo '${tls_self_signed_cert.ca.cert_pem}' > ./vault-ca.pem" 33 | # } 34 | } 35 | 36 | # Generate another private key. This one will be used 37 | # To create the certs on your Vault nodes 38 | resource "tls_private_key" "server" { 39 | algorithm = "RSA" 40 | rsa_bits = 2048 41 | 42 | # provisioner "local-exec" { 43 | # command = "echo '${tls_private_key.server.private_key_pem}' > ./vault-key.pem" 44 | # } 45 | } 46 | 47 | resource "tls_cert_request" "server" { 48 | private_key_pem = tls_private_key.server.private_key_pem 49 | 50 | subject { 51 | common_name = "vault.server.com" 52 | } 53 | 54 | dns_names = [ 55 | var.shared_san, 56 | "localhost", 57 | ] 58 | 59 | ip_addresses = [ 60 | "127.0.0.1", 61 | ] 62 | } 63 | 64 | resource "tls_locally_signed_cert" "server" { 65 | cert_request_pem = tls_cert_request.server.cert_request_pem 66 | ca_private_key_pem = tls_private_key.ca.private_key_pem 67 | ca_cert_pem = tls_self_signed_cert.ca.cert_pem 68 | 69 | validity_period_hours = 720 # 30 days 70 | 71 | allowed_uses = [ 72 | "client_auth", 73 | "digital_signature", 74 | "key_agreement", 75 | "key_encipherment", 76 | "server_auth", 77 | ] 78 | 79 | # provisioner "local-exec" { 80 | # command = "echo '${tls_locally_signed_cert.server.cert_pem}' > ./vault-crt.pem" 81 | # } 82 | } 83 | 84 | locals { 85 | tls_data = { 86 | vault_ca = base64encode(tls_self_signed_cert.ca.cert_pem) 87 | vault_cert = base64encode(tls_locally_signed_cert.server.cert_pem) 88 | vault_pk = base64encode(tls_private_key.server.private_key_pem) 89 | } 90 | } 91 | 92 | locals { 93 | secret = jsonencode(local.tls_data) 94 | } 95 | 96 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/secrets/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "kms_key_id" { 9 | type = string 10 | description = "Specifies the ARN or ID of the AWS KMS customer master key (CMK) to be used to encrypt the secret values in the versions stored in this secret. If you don't specify this value, then Secrets Manager defaults to using the AWS account's default CMK (the one named aws/secretsmanager" 11 | default = null 12 | } 13 | 14 | variable "recovery_window" { 15 | type = number 16 | description = "Specifies the number of days that AWS Secrets Manager waits before it can delete the secret" 17 | default = 0 18 | } 19 | 20 | variable "resource_name_prefix" { 21 | type = string 22 | description = "Prefix for resource names (e.g. \"prod\")" 23 | } 24 | 25 | # variable related to TLS cert generation 26 | variable "shared_san" { 27 | type = string 28 | description = "This is a shared server name that the certs for all Vault nodes contain. This is the same value you will supply as input to the Vault installation module for the leader_tls_servername variable." 29 | default = "vault.server.com" 30 | } 31 | 32 | variable "tags" { 33 | type = map(string) 34 | description = "Tags for secrets manager secret" 35 | default = { 36 | Vault = "tls-data" 37 | } 38 | } 39 | 40 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "aws_region" { 9 | description = "AWS region to deploy resources into" 10 | type = string 11 | default = "us-east-1" 12 | } 13 | 14 | variable "azs" { 15 | description = "availability zones to use in AWS region" 16 | type = list(string) 17 | default = [ 18 | "us-east-1a", 19 | "us-east-1b", 20 | "us-east-1c", 21 | ] 22 | } 23 | 24 | variable "tags" { 25 | type = map(string) 26 | description = "Tags for VPC resources" 27 | default = {} 28 | } 29 | 30 | variable "resource_name_prefix" { 31 | description = "Prefix for resource names in VPC infrastructure" 32 | } 33 | 34 | -------------------------------------------------------------------------------- /examples/prereqs_quickstart/versions.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | terraform { 9 | required_version = ">= 1.2.1" 10 | 11 | required_providers { 12 | aws = ">= 3.0.0, < 4.0.0" 13 | tls = ">= 3.0.0, < 4.0.0" 14 | } 15 | } 16 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | data "aws_region" "current" {} 9 | 10 | module "iam" { 11 | source = "./modules/iam" 12 | 13 | aws_region = data.aws_region.current.name 14 | kms_key_arn = module.kms.kms_key_arn 15 | permissions_boundary = var.permissions_boundary 16 | resource_name_prefix = var.resource_name_prefix 17 | secrets_manager_arn = var.secrets_manager_arn 18 | user_supplied_iam_role_name = var.user_supplied_iam_role_name 19 | } 20 | 21 | module "kms" { 22 | source = "./modules/kms" 23 | 24 | common_tags = var.common_tags 25 | kms_key_deletion_window = var.kms_key_deletion_window 26 | resource_name_prefix = var.resource_name_prefix 27 | user_supplied_kms_key_arn = var.user_supplied_kms_key_arn 28 | } 29 | 30 | module "loadbalancer" { 31 | source = "./modules/load_balancer" 32 | 33 | allowed_inbound_cidrs = var.allowed_inbound_cidrs_lb 34 | common_tags = var.common_tags 35 | lb_certificate_arn = var.lb_certificate_arn 36 | lb_deregistration_delay = var.lb_deregistration_delay 37 | lb_health_check_path = var.lb_health_check_path 38 | lb_subnets = var.private_subnet_ids 39 | lb_type = var.lb_type 40 | resource_name_prefix = var.resource_name_prefix 41 | ssl_policy = var.ssl_policy 42 | vault_sg_id = module.vm.vault_sg_id 43 | vpc_id = module.networking.vpc_id 44 | } 45 | 46 | module "networking" { 47 | source = "./modules/networking" 48 | 49 | vpc_id = var.vpc_id 50 | } 51 | 52 | module "user_data" { 53 | source = "./modules/user_data" 54 | 55 | aws_region = data.aws_region.current.name 56 | kms_key_arn = module.kms.kms_key_arn 57 | leader_tls_servername = var.leader_tls_servername 58 | resource_name_prefix = var.resource_name_prefix 59 | secrets_manager_arn = var.secrets_manager_arn 60 | user_supplied_userdata_path = var.user_supplied_userdata_path 61 | vault_version = var.vault_version 62 | } 63 | 64 | locals { 65 | vault_target_group_arns = concat( 66 | [module.loadbalancer.vault_target_group_arn], 67 | var.additional_lb_target_groups, 68 | ) 69 | } 70 | 71 | module "vm" { 72 | source = "./modules/vm" 73 | 74 | allowed_inbound_cidrs = var.allowed_inbound_cidrs_lb 75 | allowed_inbound_cidrs_ssh = var.allowed_inbound_cidrs_ssh 76 | aws_iam_instance_profile = module.iam.aws_iam_instance_profile 77 | common_tags = var.common_tags 78 | instance_type = var.instance_type 79 | key_name = var.key_name 80 | lb_type = var.lb_type 81 | node_count = var.node_count 82 | resource_name_prefix = var.resource_name_prefix 83 | userdata_script = module.user_data.vault_userdata_base64_encoded 84 | user_supplied_ami_id = var.user_supplied_ami_id 85 | vault_lb_sg_id = module.loadbalancer.vault_lb_sg_id 86 | vault_subnets = var.private_subnet_ids 87 | vault_target_group_arns = local.vault_target_group_arns 88 | vpc_id = module.networking.vpc_id 89 | } 90 | -------------------------------------------------------------------------------- /modules/iam/README.md: -------------------------------------------------------------------------------- 1 | # AWS IAM Module 2 | 3 | ## Required variables 4 | 5 | * `aws_region` - Specific AWS region being used 6 | * `kms_key_arn` - KMS Key ARN used for Vault auto-unseal permissions 7 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 8 | * `secrets_manager_arn` - Secrets manager ARN where TLS cert info is stored 9 | 10 | ## Example usage 11 | 12 | ```hcl 13 | module "iam" { 14 | source = "./modules/iam" 15 | 16 | aws_region = data.aws_region.current.name 17 | kms_key_arn = var.kms_key_arn 18 | resource_name_prefix = var.resource_name_prefix 19 | secrets_manager_arn = var.secrets_manager_arn 20 | } 21 | ``` 22 | -------------------------------------------------------------------------------- /modules/iam/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_iam_instance_profile" "vault" { 9 | name_prefix = "${var.resource_name_prefix}-vault" 10 | role = var.user_supplied_iam_role_name != null ? var.user_supplied_iam_role_name : aws_iam_role.instance_role[0].name 11 | } 12 | 13 | resource "aws_iam_role" "instance_role" { 14 | count = var.user_supplied_iam_role_name != null ? 0 : 1 15 | name_prefix = "${var.resource_name_prefix}-vault" 16 | permissions_boundary = var.permissions_boundary 17 | assume_role_policy = data.aws_iam_policy_document.instance_role.json 18 | } 19 | 20 | data "aws_iam_policy_document" "instance_role" { 21 | statement { 22 | effect = "Allow" 23 | actions = [ 24 | "sts:AssumeRole", 25 | ] 26 | 27 | principals { 28 | type = "Service" 29 | identifiers = ["ec2.amazonaws.com"] 30 | } 31 | } 32 | } 33 | 34 | resource "aws_iam_role_policy" "cloud_auto_join" { 35 | count = var.user_supplied_iam_role_name != null ? 0 : 1 36 | name = "${var.resource_name_prefix}-vault-auto-join" 37 | role = aws_iam_role.instance_role[0].id 38 | policy = data.aws_iam_policy_document.cloud_auto_join.json 39 | } 40 | 41 | data "aws_iam_policy_document" "cloud_auto_join" { 42 | statement { 43 | effect = "Allow" 44 | 45 | actions = [ 46 | "ec2:DescribeInstances", 47 | ] 48 | 49 | resources = ["*"] 50 | } 51 | } 52 | 53 | resource "aws_iam_role_policy" "auto_unseal" { 54 | count = var.user_supplied_iam_role_name != null ? 0 : 1 55 | name = "${var.resource_name_prefix}-vault-auto-unseal" 56 | role = aws_iam_role.instance_role[0].id 57 | policy = data.aws_iam_policy_document.auto_unseal.json 58 | } 59 | 60 | data "aws_iam_policy_document" "auto_unseal" { 61 | statement { 62 | effect = "Allow" 63 | 64 | actions = [ 65 | "kms:DescribeKey", 66 | "kms:Encrypt", 67 | "kms:Decrypt", 68 | ] 69 | 70 | resources = [ 71 | var.kms_key_arn, 72 | ] 73 | } 74 | } 75 | 76 | resource "aws_iam_role_policy" "session_manager" { 77 | count = var.user_supplied_iam_role_name != null ? 0 : 1 78 | name = "${var.resource_name_prefix}-vault-ssm" 79 | role = aws_iam_role.instance_role[0].id 80 | policy = data.aws_iam_policy_document.session_manager.json 81 | } 82 | 83 | data "aws_iam_policy_document" "session_manager" { 84 | statement { 85 | effect = "Allow" 86 | 87 | actions = [ 88 | "ssm:UpdateInstanceInformation", 89 | "ssmmessages:CreateControlChannel", 90 | "ssmmessages:CreateDataChannel", 91 | "ssmmessages:OpenControlChannel", 92 | "ssmmessages:OpenDataChannel" 93 | ] 94 | 95 | resources = [ 96 | "*", 97 | ] 98 | } 99 | } 100 | 101 | resource "aws_iam_role_policy" "secrets_manager" { 102 | count = var.user_supplied_iam_role_name != null ? 0 : 1 103 | name = "${var.resource_name_prefix}-vault-secrets-manager" 104 | role = aws_iam_role.instance_role[0].id 105 | policy = data.aws_iam_policy_document.secrets_manager.json 106 | } 107 | 108 | data "aws_iam_policy_document" "secrets_manager" { 109 | statement { 110 | effect = "Allow" 111 | 112 | actions = [ 113 | "secretsmanager:GetSecretValue", 114 | ] 115 | 116 | resources = [ 117 | var.secrets_manager_arn, 118 | ] 119 | } 120 | } 121 | -------------------------------------------------------------------------------- /modules/iam/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "aws_iam_instance_profile" { 9 | value = aws_iam_instance_profile.vault.name 10 | } 11 | -------------------------------------------------------------------------------- /modules/iam/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "aws_region" { 9 | type = string 10 | description = "Specific AWS region being used" 11 | } 12 | 13 | variable "kms_key_arn" { 14 | type = string 15 | description = "KMS Key ARN used for Vault auto-unseal permissions" 16 | } 17 | 18 | variable "permissions_boundary" { 19 | description = "(Optional) IAM Managed Policy to serve as permissions boundary for IAM Role" 20 | type = string 21 | default = null 22 | } 23 | 24 | variable "resource_name_prefix" { 25 | type = string 26 | description = "Resource name prefix used for tagging and naming AWS resources" 27 | } 28 | 29 | variable "secrets_manager_arn" { 30 | type = string 31 | description = "Secrets manager ARN where TLS cert info is stored" 32 | } 33 | 34 | variable "user_supplied_iam_role_name" { 35 | type = string 36 | description = "(OPTIONAL) User-provided IAM role name. This will be used for the instance profile provided to the AWS launch configuration. The minimum permissions must match the defaults generated by the IAM submodule for cloud auto-join and auto-unseal." 37 | default = null 38 | } 39 | -------------------------------------------------------------------------------- /modules/kms/README.md: -------------------------------------------------------------------------------- 1 | # AWS KMS Module 2 | 3 | ## Required variables 4 | 5 | * `kms_key_deletion_window` - Duration in days after which the key is deleted after destruction of the resource (must be between 7 and 30 days) 6 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 7 | 8 | ## Example usage 9 | 10 | ```hcl 11 | module "kms" { 12 | source = "./modules/kms" 13 | 14 | kms_key_deletion_window = var.kms_key_deletion_window 15 | resource_name_prefix = var.resource_name_prefix 16 | } 17 | ``` 18 | -------------------------------------------------------------------------------- /modules/kms/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_kms_key" "vault" { 9 | count = var.user_supplied_kms_key_arn != null ? 0 : 1 10 | deletion_window_in_days = var.kms_key_deletion_window 11 | description = "AWS KMS Customer-managed key used for Vault auto-unseal and encryption" 12 | enable_key_rotation = false 13 | is_enabled = true 14 | key_usage = "ENCRYPT_DECRYPT" 15 | 16 | tags = merge( 17 | { Name = "${var.resource_name_prefix}-vault-key" }, 18 | var.common_tags, 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /modules/kms/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "kms_key_arn" { 9 | value = var.user_supplied_kms_key_arn != null ? var.user_supplied_kms_key_arn : aws_kms_key.vault[0].arn 10 | } 11 | -------------------------------------------------------------------------------- /modules/kms/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "common_tags" { 9 | type = map(string) 10 | description = "(Optional) Map of common tags for all taggable AWS resources." 11 | default = {} 12 | } 13 | 14 | variable "kms_key_deletion_window" { 15 | type = number 16 | description = "Duration in days after which the key is deleted after destruction of the resource (must be between 7 and 30 days)." 17 | } 18 | 19 | variable "resource_name_prefix" { 20 | type = string 21 | description = "Resource name prefix used for tagging and naming AWS resources" 22 | } 23 | 24 | variable "user_supplied_kms_key_arn" { 25 | type = string 26 | description = "(OPTIONAL) User-provided KMS key ARN. Providing this will disable the KMS submodule from generating a KMS key used for Vault auto-unseal" 27 | default = null 28 | } 29 | -------------------------------------------------------------------------------- /modules/load_balancer/README.md: -------------------------------------------------------------------------------- 1 | # AWS Load Balancer Module 2 | 3 | ## Required variables 4 | 5 | * `lb_certificate_arn` - ARN of TLS certificate imported into ACM for use with LB listener 6 | * `lb_health_check_path` - The endpoint to check for Vault's health status 7 | * `lb_subnets` - Subnets where load balancer will be deployed 8 | * `lb_type` - The type of load balancer to provision: network or application 9 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 10 | * `ssl_policy` - SSL policy to use on LB listener 11 | * `vault_sg_id` - Security group ID of Vault cluster 12 | * `vpc_id` - VPC ID where Vault will be deployed 13 | 14 | ## Example usage 15 | 16 | ```hcl 17 | module "loadbalancer" { 18 | source = "./modules/load_balancer" 19 | 20 | lb_certificate_arn = var.lb_certificate_arn 21 | lb_health_check_path = var.lb_health_check_path 22 | lb_subnets = var.vault_subnet_ids 23 | lb_type = var.lb_type 24 | resource_name_prefix = var.resource_name_prefix 25 | ssl_policy = var.ssl_policy 26 | vault_sg_id = var.vault_sg_id 27 | vpc_id = var.vpc_id 28 | } 29 | ``` 30 | -------------------------------------------------------------------------------- /modules/load_balancer/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | resource "aws_security_group" "vault_lb" { 9 | count = var.lb_type == "application" ? 1 : 0 10 | description = "Security group for the application load balancer" 11 | name = "${var.resource_name_prefix}-vault-lb-sg" 12 | vpc_id = var.vpc_id 13 | 14 | tags = merge( 15 | { Name = "${var.resource_name_prefix}-vault-lb-sg" }, 16 | var.common_tags, 17 | ) 18 | } 19 | 20 | resource "aws_security_group_rule" "vault_lb_inbound" { 21 | count = var.lb_type == "application" && var.allowed_inbound_cidrs != null ? 1 : 0 22 | description = "Allow specified CIDRs access to load balancer on port 8200" 23 | security_group_id = aws_security_group.vault_lb[0].id 24 | type = "ingress" 25 | from_port = 8200 26 | to_port = 8200 27 | protocol = "tcp" 28 | cidr_blocks = var.allowed_inbound_cidrs 29 | } 30 | 31 | resource "aws_security_group_rule" "vault_lb_outbound" { 32 | count = var.lb_type == "application" ? 1 : 0 33 | description = "Allow outbound traffic from load balancer to Vault nodes on port 8200" 34 | security_group_id = aws_security_group.vault_lb[0].id 35 | type = "egress" 36 | from_port = 8200 37 | to_port = 8200 38 | protocol = "tcp" 39 | source_security_group_id = var.vault_sg_id 40 | } 41 | 42 | locals { 43 | lb_security_groups = var.lb_type == "network" ? null : [aws_security_group.vault_lb[0].id] 44 | lb_protocol = var.lb_type == "network" ? "TCP" : "HTTPS" 45 | } 46 | 47 | resource "aws_lb" "vault_lb" { 48 | name = "${var.resource_name_prefix}-vault-lb" 49 | internal = true 50 | load_balancer_type = var.lb_type 51 | subnets = var.lb_subnets 52 | security_groups = local.lb_security_groups 53 | drop_invalid_header_fields = var.lb_type == "application" ? true : null 54 | 55 | tags = merge( 56 | { Name = "${var.resource_name_prefix}-vault-lb" }, 57 | var.common_tags, 58 | ) 59 | } 60 | 61 | resource "aws_lb_target_group" "vault" { 62 | name = "${var.resource_name_prefix}-vault-tg" 63 | deregistration_delay = var.lb_deregistration_delay 64 | target_type = "instance" 65 | port = 8200 66 | protocol = local.lb_protocol 67 | vpc_id = var.vpc_id 68 | 69 | health_check { 70 | healthy_threshold = 3 71 | unhealthy_threshold = 3 72 | protocol = "HTTPS" 73 | port = "traffic-port" 74 | path = var.lb_health_check_path 75 | interval = 30 76 | } 77 | 78 | tags = merge( 79 | { Name = "${var.resource_name_prefix}-vault-tg" }, 80 | var.common_tags, 81 | ) 82 | } 83 | 84 | resource "aws_lb_listener" "vault" { 85 | load_balancer_arn = aws_lb.vault_lb.id 86 | port = 8200 87 | protocol = local.lb_protocol 88 | ssl_policy = local.lb_protocol == "HTTPS" ? var.ssl_policy : null 89 | certificate_arn = local.lb_protocol == "HTTPS" ? var.lb_certificate_arn : null 90 | 91 | default_action { 92 | type = "forward" 93 | target_group_arn = aws_lb_target_group.vault.arn 94 | } 95 | } 96 | -------------------------------------------------------------------------------- /modules/load_balancer/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "vault_lb_arn" { 9 | description = "ARN of Vault load balancer" 10 | value = aws_lb.vault_lb.arn 11 | } 12 | 13 | output "vault_lb_dns_name" { 14 | description = "DNS name of Vault load balancer" 15 | value = aws_lb.vault_lb.dns_name 16 | } 17 | 18 | output "vault_lb_sg_id" { 19 | description = "Security group ID of Vault load balancer" 20 | value = var.lb_type == "application" ? aws_security_group.vault_lb[0].id : null 21 | } 22 | 23 | output "vault_lb_zone_id" { 24 | description = "Zone ID of Vault load balancer" 25 | value = aws_lb.vault_lb.zone_id 26 | } 27 | 28 | output "vault_target_group_arn" { 29 | description = "Target group ARN to register Vault nodes with" 30 | value = aws_lb_target_group.vault.arn 31 | } 32 | -------------------------------------------------------------------------------- /modules/load_balancer/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "allowed_inbound_cidrs" { 9 | type = list(string) 10 | description = "List of CIDR blocks to permit inbound traffic from to load balancer" 11 | default = null 12 | } 13 | 14 | variable "common_tags" { 15 | type = map(string) 16 | description = "(Optional) Map of common tags for all taggable AWS resources." 17 | default = {} 18 | } 19 | 20 | variable "lb_certificate_arn" { 21 | type = string 22 | description = "ARN of TLS certificate imported into ACM for use with LB listener" 23 | } 24 | 25 | variable "lb_deregistration_delay" { 26 | type = string 27 | description = "Amount time, in seconds, for Vault LB target group to wait before changing the state of a deregistering target from draining to unused." 28 | default = 300 29 | } 30 | 31 | variable "lb_health_check_path" { 32 | type = string 33 | description = "The endpoint to check for Vault's health status." 34 | } 35 | 36 | variable "lb_subnets" { 37 | type = list(string) 38 | description = "Subnets where load balancer will be deployed" 39 | } 40 | 41 | variable "lb_type" { 42 | description = "The type of load balancer to provison: network or application." 43 | type = string 44 | } 45 | 46 | variable "resource_name_prefix" { 47 | type = string 48 | description = "Resource name prefix used for tagging and naming AWS resources" 49 | } 50 | 51 | variable "ssl_policy" { 52 | type = string 53 | description = "SSL policy to use on LB listener" 54 | } 55 | 56 | variable "vault_sg_id" { 57 | type = string 58 | description = "Security group ID of Vault cluster" 59 | } 60 | 61 | variable "vpc_id" { 62 | type = string 63 | description = "VPC ID where Vault will be deployed" 64 | } 65 | -------------------------------------------------------------------------------- /modules/networking/README.md: -------------------------------------------------------------------------------- 1 | # AWS Networking Module 2 | 3 | ## Required variables 4 | 5 | * `vpc_id` - VPC ID where Vault will be deployed 6 | 7 | ## Example usage 8 | 9 | ```hcl 10 | module "networking" { 11 | source = "./modules/networking" 12 | 13 | vpc_id = var.vpc_id 14 | } 15 | ``` 16 | -------------------------------------------------------------------------------- /modules/networking/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | data "aws_vpc" "selected" { 9 | id = var.vpc_id 10 | } 11 | -------------------------------------------------------------------------------- /modules/networking/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "vpc_id" { 9 | value = data.aws_vpc.selected.id 10 | } 11 | -------------------------------------------------------------------------------- /modules/networking/variables.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | variable "vpc_id" { 9 | type = string 10 | description = "VPC ID where Vault will be deployed" 11 | } 12 | -------------------------------------------------------------------------------- /modules/user_data/README.md: -------------------------------------------------------------------------------- 1 | # AWS User Data Module 2 | 3 | ## Required variables 4 | 5 | * `aws_region` - AWS region where Vault is being deployed 6 | * `kms_key_arn` - KMS Key ARN used for Vault auto-unseal 7 | * `leader_tls_servername` - One of the shared DNS SAN used to create the certs use for mTLS 8 | * `resource_name_prefix` - Resource name prefix used for tagging and naming AWS resources 9 | * `secrets_manager_arn` - Secrets manager ARN where TLS cert info is stored 10 | * `vault_version` - Vault version 11 | 12 | ## Example usage 13 | 14 | ```hcl 15 | module "user_data" { 16 | source = "./modules/user_data" 17 | 18 | aws_region = data.aws_region.current.name 19 | kms_key_arn = var.kms_key_arn 20 | leader_tls_servername = var.leader_tls_servername 21 | resource_name_prefix = var.resource_name_prefix 22 | secrets_manager_arn = var.secrets_manager_arn 23 | vault_version = var.vault_version 24 | } 25 | ``` 26 | -------------------------------------------------------------------------------- /modules/user_data/main.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | locals { 9 | vault_user_data = templatefile( 10 | var.user_supplied_userdata_path != null ? var.user_supplied_userdata_path : "${path.module}/templates/install_vault.sh.tpl", 11 | { 12 | region = var.aws_region 13 | name = var.resource_name_prefix 14 | vault_version = var.vault_version 15 | kms_key_arn = var.kms_key_arn 16 | secrets_manager_arn = var.secrets_manager_arn 17 | leader_tls_servername = var.leader_tls_servername 18 | } 19 | ) 20 | } 21 | -------------------------------------------------------------------------------- /modules/user_data/outputs.tf: -------------------------------------------------------------------------------- 1 | /** 2 | * Copyright © 2014-2022 HashiCorp, Inc. 3 | * 4 | * This Source Code is subject to the terms of the Mozilla Public License, v. 2.0. If a copy of the MPL was not distributed with this project, you can obtain one at http://mozilla.org/MPL/2.0/. 5 | * 6 | */ 7 | 8 | output "vault_userdata_base64_encoded" { 9 | value = base64encode(local.vault_user_data) 10 | } 11 | -------------------------------------------------------------------------------- /modules/user_data/templates/install_vault.sh.tpl: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env bash 2 | 3 | imds_token=$( curl -Ss -H "X-aws-ec2-metadata-token-ttl-seconds: 30" -XPUT 169.254.169.254/latest/api/token ) 4 | instance_id=$( curl -Ss -H "X-aws-ec2-metadata-token: $imds_token" 169.254.169.254/latest/meta-data/instance-id ) 5 | local_ipv4=$( curl -Ss -H "X-aws-ec2-metadata-token: $imds_token" 169.254.169.254/latest/meta-data/local-ipv4 ) 6 | 7 | # install package 8 | 9 | curl -fsSL https://apt.releases.hashicorp.com/gpg | apt-key add - 10 | apt-add-repository "deb [arch=amd64] https://apt.releases.hashicorp.com $(lsb_release -cs) main" 11 | apt-get update 12 | apt-get install -y vault=${vault_version}-* awscli jq 13 | 14 | echo "Configuring system time" 15 | timedatectl set-timezone UTC 16 | 17 | # removing any default installation files from /opt/vault/tls/ 18 | rm -rf /opt/vault/tls/* 19 | 20 | # /opt/vault/tls should be readable by all users of the system 21 | chmod 0755 /opt/vault/tls 22 | 23 | # vault-key.pem should be readable by the vault group only 24 | touch /opt/vault/tls/vault-key.pem 25 | chown root:vault /opt/vault/tls/vault-key.pem 26 | chmod 0640 /opt/vault/tls/vault-key.pem 27 | 28 | secret_result=$(aws secretsmanager get-secret-value --secret-id ${secrets_manager_arn} --region ${region} --output text --query SecretString) 29 | 30 | jq -r .vault_cert <<< "$secret_result" | base64 -d > /opt/vault/tls/vault-cert.pem 31 | 32 | jq -r .vault_ca <<< "$secret_result" | base64 -d > /opt/vault/tls/vault-ca.pem 33 | 34 | jq -r .vault_pk <<< "$secret_result" | base64 -d > /opt/vault/tls/vault-key.pem 35 | 36 | cat << EOF > /etc/vault.d/vault.hcl 37 | ui = true 38 | disable_mlock = true 39 | 40 | storage "raft" { 41 | path = "/opt/vault/data" 42 | node_id = "$instance_id" 43 | retry_join { 44 | auto_join = "provider=aws region=${region} tag_key=${name}-vault tag_value=server" 45 | auto_join_scheme = "https" 46 | leader_tls_servername = "${leader_tls_servername}" 47 | leader_ca_cert_file = "/opt/vault/tls/vault-ca.pem" 48 | leader_client_cert_file = "/opt/vault/tls/vault-cert.pem" 49 | leader_client_key_file = "/opt/vault/tls/vault-key.pem" 50 | } 51 | } 52 | 53 | cluster_addr = "https://$local_ipv4:8201" 54 | api_addr = "https://$local_ipv4:8200" 55 | 56 | listener "tcp" { 57 | address = "0.0.0.0:8200" 58 | tls_disable = false 59 | tls_cert_file = "/opt/vault/tls/vault-cert.pem" 60 | tls_key_file = "/opt/vault/tls/vault-key.pem" 61 | tls_client_ca_file = "/opt/vault/tls/vault-ca.pem" 62 | } 63 | 64 | seal "awskms" { 65 | region = "${region}" 66 | kms_key_id = "${kms_key_arn}" 67 | } 68 | 69 | EOF 70 | 71 | # vault.hcl should be readable by the vault group only 72 | chown root:root /etc/vault.d 73 | chown root:vault /etc/vault.d/vault.hcl 74 | chmod 640 /etc/vault.d/vault.hcl 75 | 76 | systemctl enable vault 77 | systemctl start vault 78 | 79 | echo "Setup Vault profile" 80 | cat <