├── .github ├── ISSUE_TEMPLATE │ ├── bug_report.md │ └── feature_request.md └── pull_request_template.md ├── .gitignore ├── CODEOWNERS ├── LICENSE.txt ├── README.md ├── docker-example ├── Dockerfile └── src │ └── server.js ├── example-rails-app ├── Gemfile ├── Gemfile.lock ├── README.md ├── Rakefile ├── app │ ├── assets │ │ ├── config │ │ │ └── manifest.js │ │ ├── images │ │ │ └── rails.png │ │ ├── javascripts │ │ │ └── application.js │ │ └── stylesheets │ │ │ └── application.css │ ├── controllers │ │ └── application_controller.rb │ ├── helpers │ │ └── application_helper.rb │ ├── mailers │ │ └── .gitkeep │ ├── models │ │ └── .gitkeep │ └── views │ │ └── layouts │ │ └── application.html.erb ├── bin │ ├── bundle │ ├── rails │ ├── rake │ └── setup ├── config.ru ├── config │ ├── application.rb │ ├── boot.rb │ ├── database.yml │ ├── environment.rb │ ├── environments │ │ ├── development.rb │ │ ├── production.rb │ │ └── test.rb │ ├── initializers │ │ ├── assets.rb │ │ ├── backtrace_silencers.rb │ │ ├── cookies_serializer.rb │ │ ├── filter_parameter_logging.rb │ │ ├── inflections.rb │ │ ├── mime_types.rb │ │ ├── secret_token.rb │ │ ├── session_store.rb │ │ └── wrap_parameters.rb │ ├── locales │ │ └── en.yml │ ├── routes.rb │ └── secrets.yml ├── db │ ├── development.sqlite3 │ └── seeds.rb ├── doc │ └── README_FOR_APP ├── lib │ ├── assets │ │ └── .gitkeep │ └── tasks │ │ └── .gitkeep ├── log │ ├── .gitkeep │ └── development.log ├── public │ ├── 404.html │ ├── 422.html │ ├── 500.html │ ├── favicon.ico │ └── robots.txt ├── script │ └── rails ├── test │ ├── fixtures │ │ └── .gitkeep │ ├── functional │ │ └── .gitkeep │ ├── integration │ │ └── .gitkeep │ ├── performance │ │ └── browsing_test.rb │ ├── test_helper.rb │ └── unit │ │ └── .gitkeep ├── tmp │ └── cache │ │ └── assets │ │ ├── 404 │ │ └── FB1 │ │ │ └── sprockets%2Fv3.0%2FBl90b2W_x-luH9JpUId0e9HoWLbCr1b6Sm5ouFF3vUU │ │ ├── 456 │ │ └── 621 │ │ │ └── sprockets%2Fv3.0%2FiF87pDOFHbUvx-m34Et4rFyJc0pzK1Q1bdjoUVQzK7g │ │ ├── 49C │ │ └── BC1 │ │ │ └── sprockets%2Fv3.0%2F5eQEx6JCkKrKTqU4gDwP6WAiUuEgpSEFvrp3Vmkc_08 │ │ └── 4EE │ │ └── 7F1 │ │ └── sprockets%2Fv3.0%2F9PIO2pMXjcKtNTwGlShXht2vejB3dKZSupd8-1UWuds └── vendor │ ├── assets │ ├── javascripts │ │ └── .gitkeep │ └── stylesheets │ │ └── .gitkeep │ └── plugins │ └── .gitkeep ├── packer-example ├── README.md ├── install-rails.sh └── simple-web-server.json ├── terraform-example-basic ├── README.md └── main.tf ├── terraform-example-full ├── README.md ├── main.tf ├── outputs.tf ├── rails-module │ ├── README.md │ ├── main.tf │ ├── outputs.tf │ ├── user-data.sh │ └── vars.tf └── vars.tf └── terraform-example-s3-backend ├── main.tf └── vars.tf /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a bug report to help us improve. 4 | title: '' 5 | labels: bug 6 | assignees: '' 7 | 8 | --- 9 | 10 | 14 | 15 | **Describe the bug** 16 | A clear and concise description of what the bug is. 17 | 18 | **To Reproduce** 19 | Steps to reproduce the behavior including the relevant Terraform/Terragrunt/Packer version number and any code snippets and module inputs you used. 20 | 21 | ```hcl 22 | // paste code snippets here 23 | ``` 24 | 25 | **Expected behavior** 26 | A clear and concise description of what you expected to happen. 27 | 28 | **Nice to have** 29 | - [ ] Terminal output 30 | - [ ] Screenshots 31 | 32 | **Additional context** 33 | Add any other context about the problem here. 34 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Submit a feature request for this repo. 4 | title: '' 5 | labels: enhancement 6 | assignees: '' 7 | 8 | --- 9 | 10 | 14 | 15 | **Describe the solution you'd like** 16 | A clear and concise description of what you want to happen. 17 | 18 | **Describe alternatives you've considered** 19 | A clear and concise description of any alternative solutions or features you've considered. 20 | 21 | **Additional context** 22 | Add any other context or screenshots about the feature request here. 23 | -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | 3 | ## Description 4 | 5 | Fixes #000. 6 | 7 | 8 | 9 | ## TODOs 10 | 11 | Read the [Gruntwork contribution guidelines](https://gruntwork.notion.site/Gruntwork-Coding-Methodology-02fdcd6e4b004e818553684760bf691e). 12 | 13 | - [ ] Update the docs. 14 | - [ ] Run the relevant tests successfully, including pre-commit checks. 15 | - [ ] Ensure any 3rd party code adheres with our [license policy](https://www.notion.so/gruntwork/Gruntwork-licenses-and-open-source-usage-policy-f7dece1f780341c7b69c1763f22b1378) or delete this line if its not applicable. 16 | - [ ] Include release notes. If this PR is backward incompatible, include a migration guide. 17 | 18 | ## Release Notes (draft) 19 | 20 | 21 | Added / Removed / Updated [X]. 22 | 23 | ### Migration Guide 24 | 25 | 26 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | # Ignore bundler config. 2 | /.bundle 3 | 4 | # Ignore the default SQLite database. 5 | /db/*.sqlite3 6 | /db/*.sqlite3-journal 7 | 8 | # Ignore all logfiles and tempfiles. 9 | /log/* 10 | !/log/.keep 11 | /tmp 12 | nohup.out 13 | 14 | # Rake files 15 | .generators 16 | .rakeTasks 17 | 18 | # The Terraform code in this app is just an example, so ignore any files that may store Terraform state from a real 19 | # deployment. You may want to remove these gitignore entries for a real app. 20 | terraform.tfvars 21 | .terraform 22 | *.tfstate 23 | *.tfstate.backup 24 | 25 | # Ignore OS X files 26 | .DS_Store 27 | 28 | # IntelliJ files 29 | .idea_modules 30 | *.iml 31 | *.iws 32 | *.ipr 33 | .idea/ 34 | build/ 35 | */build/ 36 | out/ 37 | 38 | 39 | # Ignore Terraform lock files, as we want to test the Terraform code in these repos with the latest provider 40 | # versions. 41 | .terraform.lock.hcl 42 | -------------------------------------------------------------------------------- /CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @brikis98 @arsci @hongil0316 2 | -------------------------------------------------------------------------------- /LICENSE.txt: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright 2016 Gruntwork, Inc 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Infrastructure-as-code Training 2 | 3 | This repo contains materials for learning how to use infrastructure-as-code practices, including: 4 | 5 | 1. An [example Ruby on Rails app](/example-rails-app) used for demonstration purposes. 6 | 1. A [Packer example](/packer-example) that shows how to create an AMI that has Ruby on Rails installed and contains 7 | the code from the example Rails app. 8 | 1. A [Docker example](/docker-example) that shows how to create a Docker container that has Node.js installed and 9 | runs a simple Node "Hello, World" web server. 10 | 1. A [basic Terraform example](/terraform-example-basic) that shows an intro to Terraform. 11 | 1. A [full Terraform example](/terraform-example-full) that shows more advanced Terraform usage, including how to take 12 | the AMI created by the Packer example, deploy it on AWS, and run the example Rails app. 13 | 14 | Note: all the code in this repo is used only for demonstration and teaching purposes and should not be used in 15 | production. If you need help using Packer, Terraform, or any other DevOps tools in production, reach out to us at 16 | [Gruntwork](http://www.gruntwork.io/). 17 | -------------------------------------------------------------------------------- /docker-example/Dockerfile: -------------------------------------------------------------------------------- 1 | # In this example, we use the 'latest' tag for simplicity. In production code, we recommend pinning to a more specific version. 2 | # Details: https://vsupalov.com/docker-latest-tag/ 3 | FROM ubuntu:latest 4 | LABEL maintainer="Yevgeniy Brikman " 5 | 6 | ENV DEBIAN_FRONTEND=noninteractive 7 | RUN apt-get update && \ 8 | apt-get install -o Acquire::ForceIPv4=true -y curl 9 | RUN curl -sL https://deb.nodesource.com/setup_12.x | bash - && \ 10 | apt-get install -y nodejs 11 | RUN npm install -g nodemon 12 | 13 | WORKDIR /usr/src/app 14 | COPY ./src ./ 15 | 16 | EXPOSE 8080 17 | CMD ["nodemon", "server.js"] 18 | -------------------------------------------------------------------------------- /docker-example/src/server.js: -------------------------------------------------------------------------------- 1 | var http = require('http'); 2 | 3 | var server = http.createServer(function (request, response) { 4 | response.writeHead(200, {"Content-Type": "text/plain"}); 5 | response.end("Hello World!\n"); 6 | }); 7 | 8 | server.listen(8080); 9 | 10 | console.log("Server running at http://127.0.0.1:8080/"); 11 | 12 | process.on('SIGINT', function() { 13 | process.exit(); 14 | }); -------------------------------------------------------------------------------- /example-rails-app/Gemfile: -------------------------------------------------------------------------------- 1 | source 'https://rubygems.org' 2 | 3 | gem 'rails', '4.2.6' 4 | 5 | # Bundle edge Rails instead: 6 | # gem 'rails', :git => 'git://github.com/rails/rails.git' 7 | 8 | # These gem versions are what is available as apt packages in Ubuntu 16.04 9 | gem 'sqlite3', '1.3.11' 10 | gem 'json', '1.8.3' 11 | gem 'nokogiri', '1.13.9' 12 | -------------------------------------------------------------------------------- /example-rails-app/Gemfile.lock: -------------------------------------------------------------------------------- 1 | GEM 2 | remote: https://rubygems.org/ 3 | specs: 4 | actionmailer (4.2.6) 5 | actionpack (= 4.2.6) 6 | actionview (= 4.2.6) 7 | activejob (= 4.2.6) 8 | mail (~> 2.5, >= 2.5.4) 9 | rails-dom-testing (~> 1.0, >= 1.0.5) 10 | actionpack (4.2.6) 11 | actionview (= 4.2.6) 12 | activesupport (= 4.2.6) 13 | rack (~> 1.6) 14 | rack-test (~> 0.6.2) 15 | rails-dom-testing (~> 1.0, >= 1.0.5) 16 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 17 | actionview (4.2.6) 18 | activesupport (= 4.2.6) 19 | builder (~> 3.1) 20 | erubis (~> 2.7.0) 21 | rails-dom-testing (~> 1.0, >= 1.0.5) 22 | rails-html-sanitizer (~> 1.0, >= 1.0.2) 23 | activejob (4.2.6) 24 | activesupport (= 4.2.6) 25 | globalid (>= 0.3.0) 26 | activemodel (4.2.6) 27 | activesupport (= 4.2.6) 28 | builder (~> 3.1) 29 | activerecord (4.2.6) 30 | activemodel (= 4.2.6) 31 | activesupport (= 4.2.6) 32 | arel (~> 6.0) 33 | activesupport (4.2.6) 34 | i18n (~> 0.7) 35 | json (~> 1.7, >= 1.7.7) 36 | minitest (~> 5.1) 37 | thread_safe (~> 0.3, >= 0.3.4) 38 | tzinfo (~> 1.1) 39 | arel (6.0.4) 40 | builder (3.2.4) 41 | concurrent-ruby (1.1.5) 42 | crass (1.0.5) 43 | erubis (2.7.0) 44 | globalid (0.4.2) 45 | activesupport (>= 4.2.0) 46 | i18n (0.9.5) 47 | concurrent-ruby (~> 1.0) 48 | json (1.8.3) 49 | loofah (2.4.0) 50 | crass (~> 1.0.2) 51 | nokogiri (>= 1.5.9) 52 | mail (2.7.1) 53 | mini_mime (>= 0.1.1) 54 | mini_mime (1.0.2) 55 | mini_portile2 (2.8.0) 56 | minitest (5.13.0) 57 | nokogiri (1.13.9) 58 | mini_portile2 (~> 2.8.0) 59 | racc (~> 1.4) 60 | racc (1.6.0) 61 | rack (1.6.13) 62 | rack-test (0.6.3) 63 | rack (>= 1.0) 64 | rails (4.2.6) 65 | actionmailer (= 4.2.6) 66 | actionpack (= 4.2.6) 67 | actionview (= 4.2.6) 68 | activejob (= 4.2.6) 69 | activemodel (= 4.2.6) 70 | activerecord (= 4.2.6) 71 | activesupport (= 4.2.6) 72 | bundler (>= 1.3.0, < 2.0) 73 | railties (= 4.2.6) 74 | sprockets-rails 75 | rails-deprecated_sanitizer (1.0.3) 76 | activesupport (>= 4.2.0.alpha) 77 | rails-dom-testing (1.0.9) 78 | activesupport (>= 4.2.0, < 5.0) 79 | nokogiri (~> 1.6) 80 | rails-deprecated_sanitizer (>= 1.0.1) 81 | rails-html-sanitizer (1.3.0) 82 | loofah (~> 2.3) 83 | railties (4.2.6) 84 | actionpack (= 4.2.6) 85 | activesupport (= 4.2.6) 86 | rake (>= 0.8.7) 87 | thor (>= 0.18.1, < 2.0) 88 | rake (13.0.1) 89 | sprockets (3.7.2) 90 | concurrent-ruby (~> 1.0) 91 | rack (> 1, < 3) 92 | sprockets-rails (3.2.1) 93 | actionpack (>= 4.0) 94 | activesupport (>= 4.0) 95 | sprockets (>= 3.0.0) 96 | sqlite3 (1.3.11) 97 | thor (1.0.0) 98 | thread_safe (0.3.6) 99 | tzinfo (1.2.5) 100 | thread_safe (~> 0.1) 101 | 102 | PLATFORMS 103 | ruby 104 | 105 | DEPENDENCIES 106 | json (= 1.8.3) 107 | nokogiri (= 1.13.9) 108 | rails (= 4.2.6) 109 | sqlite3 (= 1.3.11) 110 | 111 | BUNDLED WITH 112 | 1.17.3 113 | -------------------------------------------------------------------------------- /example-rails-app/README.md: -------------------------------------------------------------------------------- 1 | # Example Ruby on Rails App 2 | 3 | This is a Ruby on Rails app that just renders the text "Hello, World" when you hit the `/` URL. It is used for 4 | demonstration purposes in the `packer-example` and `terraform-example-full` folders. -------------------------------------------------------------------------------- /example-rails-app/Rakefile: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env rake 2 | # Add your own tasks in files placed in lib/tasks ending in .rake, 3 | # for example lib/tasks/capistrano.rake, and they will automatically be available to Rake. 4 | 5 | require File.expand_path('../config/application', __FILE__) 6 | 7 | ExampleRailsApp::Application.load_tasks 8 | -------------------------------------------------------------------------------- /example-rails-app/app/assets/config/manifest.js: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/app/assets/config/manifest.js -------------------------------------------------------------------------------- /example-rails-app/app/assets/images/rails.png: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/app/assets/images/rails.png -------------------------------------------------------------------------------- /example-rails-app/app/assets/javascripts/application.js: -------------------------------------------------------------------------------- 1 | // This is a manifest file that'll be compiled into application.js, which will include all the files 2 | // listed below. 3 | // 4 | // Any JavaScript/Coffee file within this directory, lib/assets/javascripts, vendor/assets/javascripts, 5 | // or vendor/assets/javascripts of plugins, if any, can be referenced here using a relative path. 6 | // 7 | // It's not advisable to add code directly here, but if you do, it'll appear at the bottom of the 8 | // the compiled file. 9 | // 10 | // WARNING: THE FIRST BLANK LINE MARKS THE END OF WHAT'S TO BE PROCESSED, ANY BLANK LINE SHOULD 11 | // GO AFTER THE REQUIRES BELOW. 12 | // 13 | //= require jquery 14 | //= require jquery_ujs 15 | //= require_tree . 16 | -------------------------------------------------------------------------------- /example-rails-app/app/assets/stylesheets/application.css: -------------------------------------------------------------------------------- 1 | /* 2 | * This is a manifest file that'll be compiled into application.css, which will include all the files 3 | * listed below. 4 | * 5 | * Any CSS and SCSS file within this directory, lib/assets/stylesheets, vendor/assets/stylesheets, 6 | * or vendor/assets/stylesheets of plugins, if any, can be referenced here using a relative path. 7 | * 8 | * You're free to add application-wide styles to this file and they'll appear at the top of the 9 | * compiled file, but it's generally better to create a new file per style scope. 10 | * 11 | *= require_self 12 | *= require_tree . 13 | */ 14 | -------------------------------------------------------------------------------- /example-rails-app/app/controllers/application_controller.rb: -------------------------------------------------------------------------------- 1 | class ApplicationController < ActionController::Base 2 | protect_from_forgery 3 | 4 | def index 5 | render text: "Hello, World" 6 | end 7 | end 8 | -------------------------------------------------------------------------------- /example-rails-app/app/helpers/application_helper.rb: -------------------------------------------------------------------------------- 1 | module ApplicationHelper 2 | end 3 | -------------------------------------------------------------------------------- /example-rails-app/app/mailers/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/app/mailers/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/app/models/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/app/models/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/app/views/layouts/application.html.erb: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | ExampleRailsApp 5 | <%= stylesheet_link_tag "application", :media => "all" %> 6 | <%= javascript_include_tag "application" %> 7 | <%= csrf_meta_tags %> 8 | 9 | 10 | 11 | <%= yield %> 12 | 13 | 14 | 15 | -------------------------------------------------------------------------------- /example-rails-app/bin/bundle: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 3 | load Gem.bin_path('bundler', 'bundle') 4 | -------------------------------------------------------------------------------- /example-rails-app/bin/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | APP_PATH = File.expand_path('../../config/application', __FILE__) 3 | require_relative '../config/boot' 4 | require 'rails/commands' 5 | -------------------------------------------------------------------------------- /example-rails-app/bin/rake: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require_relative '../config/boot' 3 | require 'rake' 4 | Rake.application.run 5 | -------------------------------------------------------------------------------- /example-rails-app/bin/setup: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | require 'pathname' 3 | 4 | # path to your application root. 5 | APP_ROOT = Pathname.new File.expand_path('../../', __FILE__) 6 | 7 | Dir.chdir APP_ROOT do 8 | # This script is a starting point to setup your application. 9 | # Add necessary setup steps to this file: 10 | 11 | puts "== Installing dependencies ==" 12 | system "gem install bundler --conservative" 13 | system "bundle check || bundle install" 14 | 15 | # puts "\n== Copying sample files ==" 16 | # unless File.exist?("config/database.yml") 17 | # system "cp config/database.yml.sample config/database.yml" 18 | # end 19 | 20 | puts "\n== Preparing database ==" 21 | system "bin/rake db:setup" 22 | 23 | puts "\n== Removing old logs and tempfiles ==" 24 | system "rm -f log/*" 25 | system "rm -rf tmp/cache" 26 | 27 | puts "\n== Restarting application server ==" 28 | system "touch tmp/restart.txt" 29 | end 30 | -------------------------------------------------------------------------------- /example-rails-app/config.ru: -------------------------------------------------------------------------------- 1 | # This file is used by Rack-based servers to start the application. 2 | 3 | require ::File.expand_path('../config/environment', __FILE__) 4 | run ExampleRailsApp::Application 5 | -------------------------------------------------------------------------------- /example-rails-app/config/application.rb: -------------------------------------------------------------------------------- 1 | require File.expand_path('../boot', __FILE__) 2 | 3 | require 'rails/all' 4 | 5 | # Require the gems listed in Gemfile, including any gems 6 | # you've limited to :test, :development, or :production. 7 | Bundler.require(*Rails.groups) 8 | 9 | module ExampleRailsApp 10 | class Application < Rails::Application 11 | # Settings in config/environments/* take precedence over those specified here. 12 | # Application configuration should go into files in config/initializers 13 | # -- all .rb files in that directory are automatically loaded. 14 | 15 | # Set Time.zone default to the specified zone and make Active Record auto-convert to this zone. 16 | # Run "rake -D time" for a list of tasks for finding time zone names. Default is UTC. 17 | # config.time_zone = 'Central Time (US & Canada)' 18 | 19 | # The default locale is :en and all translations from config/locales/*.rb,yml are auto loaded. 20 | # config.i18n.load_path += Dir[Rails.root.join('my', 'locales', '*.{rb,yml}').to_s] 21 | # config.i18n.default_locale = :de 22 | 23 | # Do not swallow errors in after_commit/after_rollback callbacks. 24 | config.active_record.raise_in_transactional_callbacks = true 25 | end 26 | end 27 | -------------------------------------------------------------------------------- /example-rails-app/config/boot.rb: -------------------------------------------------------------------------------- 1 | ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__) 2 | 3 | require 'bundler/setup' # Set up gems listed in the Gemfile. 4 | -------------------------------------------------------------------------------- /example-rails-app/config/database.yml: -------------------------------------------------------------------------------- 1 | # SQLite version 3.x 2 | # gem install sqlite3 3 | # 4 | # Ensure the SQLite 3 gem is defined in your Gemfile 5 | # gem 'sqlite3' 6 | development: 7 | adapter: sqlite3 8 | database: db/development.sqlite3 9 | pool: 5 10 | timeout: 5000 11 | 12 | # Warning: The database defined as "test" will be erased and 13 | # re-generated from your development database when you run "rake". 14 | # Do not set this db to the same as development or production. 15 | test: 16 | adapter: sqlite3 17 | database: db/test.sqlite3 18 | pool: 5 19 | timeout: 5000 20 | 21 | production: 22 | adapter: sqlite3 23 | database: db/production.sqlite3 24 | pool: 5 25 | timeout: 5000 26 | -------------------------------------------------------------------------------- /example-rails-app/config/environment.rb: -------------------------------------------------------------------------------- 1 | # Load the Rails application. 2 | require File.expand_path('../application', __FILE__) 3 | 4 | # Initialize the Rails application. 5 | Rails.application.initialize! 6 | -------------------------------------------------------------------------------- /example-rails-app/config/environments/development.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # In the development environment your application's code is reloaded on 5 | # every request. This slows down response time but is perfect for development 6 | # since you don't have to restart the web server when you make code changes. 7 | config.cache_classes = false 8 | 9 | # Do not eager load code on boot. 10 | config.eager_load = false 11 | 12 | # Show full error reports and disable caching. 13 | config.consider_all_requests_local = true 14 | config.action_controller.perform_caching = false 15 | 16 | # Don't care if the mailer can't send. 17 | config.action_mailer.raise_delivery_errors = false 18 | 19 | # Print deprecation notices to the Rails logger. 20 | config.active_support.deprecation = :log 21 | 22 | # Raise an error on page load if there are pending migrations. 23 | config.active_record.migration_error = :page_load 24 | 25 | # Debug mode disables concatenation and preprocessing of assets. 26 | # This option may cause significant delays in view rendering with a large 27 | # number of complex assets. 28 | config.assets.debug = true 29 | 30 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 31 | # yet still be able to expire them through the digest params. 32 | config.assets.digest = true 33 | 34 | # Adds additional error checking when serving assets at runtime. 35 | # Checks for improperly declared sprockets dependencies. 36 | # Raises helpful error messages. 37 | config.assets.raise_runtime_errors = true 38 | 39 | # Raises error for missing translations 40 | # config.action_view.raise_on_missing_translations = true 41 | end 42 | -------------------------------------------------------------------------------- /example-rails-app/config/environments/production.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # Code is not reloaded between requests. 5 | config.cache_classes = true 6 | 7 | # Eager load code on boot. This eager loads most of Rails and 8 | # your application in memory, allowing both threaded web servers 9 | # and those relying on copy on write to perform better. 10 | # Rake tasks automatically ignore this option for performance. 11 | config.eager_load = true 12 | 13 | # Full error reports are disabled and caching is turned on. 14 | config.consider_all_requests_local = false 15 | config.action_controller.perform_caching = true 16 | 17 | # Enable Rack::Cache to put a simple HTTP cache in front of your application 18 | # Add `rack-cache` to your Gemfile before enabling this. 19 | # For large-scale production use, consider using a caching reverse proxy like 20 | # NGINX, varnish or squid. 21 | # config.action_dispatch.rack_cache = true 22 | 23 | # Disable serving static files from the `/public` folder by default since 24 | # Apache or NGINX already handles this. 25 | config.serve_static_files = ENV['RAILS_SERVE_STATIC_FILES'].present? 26 | 27 | # Compress JavaScripts and CSS. 28 | config.assets.js_compressor = :uglifier 29 | # config.assets.css_compressor = :sass 30 | 31 | # Do not fallback to assets pipeline if a precompiled asset is missed. 32 | config.assets.compile = false 33 | 34 | # Asset digests allow you to set far-future HTTP expiration dates on all assets, 35 | # yet still be able to expire them through the digest params. 36 | config.assets.digest = true 37 | 38 | # `config.assets.precompile` and `config.assets.version` have moved to config/initializers/assets.rb 39 | 40 | # Specifies the header that your server uses for sending files. 41 | # config.action_dispatch.x_sendfile_header = 'X-Sendfile' # for Apache 42 | # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for NGINX 43 | 44 | # Force all access to the app over SSL, use Strict-Transport-Security, and use secure cookies. 45 | # config.force_ssl = true 46 | 47 | # Use the lowest log level to ensure availability of diagnostic information 48 | # when problems arise. 49 | config.log_level = :debug 50 | 51 | # Prepend all log lines with the following tags. 52 | # config.log_tags = [ :subdomain, :uuid ] 53 | 54 | # Use a different logger for distributed setups. 55 | # config.logger = ActiveSupport::TaggedLogging.new(SyslogLogger.new) 56 | 57 | # Use a different cache store in production. 58 | # config.cache_store = :mem_cache_store 59 | 60 | # Enable serving of images, stylesheets, and JavaScripts from an asset server. 61 | # config.action_controller.asset_host = 'http://assets.example.com' 62 | 63 | # Ignore bad email addresses and do not raise email delivery errors. 64 | # Set this to true and configure the email server for immediate delivery to raise delivery errors. 65 | # config.action_mailer.raise_delivery_errors = false 66 | 67 | # Enable locale fallbacks for I18n (makes lookups for any locale fall back to 68 | # the I18n.default_locale when a translation cannot be found). 69 | config.i18n.fallbacks = true 70 | 71 | # Send deprecation notices to registered listeners. 72 | config.active_support.deprecation = :notify 73 | 74 | # Use default logging formatter so that PID and timestamp are not suppressed. 75 | config.log_formatter = ::Logger::Formatter.new 76 | 77 | # Do not dump schema after migrations. 78 | config.active_record.dump_schema_after_migration = false 79 | end 80 | -------------------------------------------------------------------------------- /example-rails-app/config/environments/test.rb: -------------------------------------------------------------------------------- 1 | Rails.application.configure do 2 | # Settings specified here will take precedence over those in config/application.rb. 3 | 4 | # The test environment is used exclusively to run your application's 5 | # test suite. You never need to work with it otherwise. Remember that 6 | # your test database is "scratch space" for the test suite and is wiped 7 | # and recreated between test runs. Don't rely on the data there! 8 | config.cache_classes = true 9 | 10 | # Do not eager load code on boot. This avoids loading your whole application 11 | # just for the purpose of running a single test. If you are using a tool that 12 | # preloads Rails for running tests, you may have to set it to true. 13 | config.eager_load = false 14 | 15 | # Configure static file server for tests with Cache-Control for performance. 16 | config.serve_static_files = true 17 | config.static_cache_control = 'public, max-age=3600' 18 | 19 | # Show full error reports and disable caching. 20 | config.consider_all_requests_local = true 21 | config.action_controller.perform_caching = false 22 | 23 | # Raise exceptions instead of rendering exception templates. 24 | config.action_dispatch.show_exceptions = false 25 | 26 | # Disable request forgery protection in test environment. 27 | config.action_controller.allow_forgery_protection = false 28 | 29 | # Tell Action Mailer not to deliver emails to the real world. 30 | # The :test delivery method accumulates sent emails in the 31 | # ActionMailer::Base.deliveries array. 32 | config.action_mailer.delivery_method = :test 33 | 34 | # Randomize the order test cases are executed. 35 | config.active_support.test_order = :random 36 | 37 | # Print deprecation notices to the stderr. 38 | config.active_support.deprecation = :stderr 39 | 40 | # Raises error for missing translations 41 | # config.action_view.raise_on_missing_translations = true 42 | end 43 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/assets.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Version of your assets, change this if you want to expire all your assets. 4 | Rails.application.config.assets.version = '1.0' 5 | 6 | # Add additional assets to the asset load path 7 | # Rails.application.config.assets.paths << Emoji.images_path 8 | 9 | # Precompile additional assets. 10 | # application.js, application.css, and all non-JS/CSS in app/assets folder are already added. 11 | # Rails.application.config.assets.precompile += %w( search.js ) 12 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/backtrace_silencers.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # You can add backtrace silencers for libraries that you're using but don't wish to see in your backtraces. 4 | # Rails.backtrace_cleaner.add_silencer { |line| line =~ /my_noisy_library/ } 5 | 6 | # You can also remove all the silencers if you're trying to debug a problem that might stem from framework code. 7 | # Rails.backtrace_cleaner.remove_silencers! 8 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/cookies_serializer.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.action_dispatch.cookies_serializer = :marshal 4 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/filter_parameter_logging.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Configure sensitive parameters which will be filtered from the log file. 4 | Rails.application.config.filter_parameters += [:password] 5 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/inflections.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new inflection rules using the following format. Inflections 4 | # are locale specific, and you may define rules for as many different 5 | # locales as you wish. All of these examples are active by default: 6 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 7 | # inflect.plural /^(ox)$/i, '\1en' 8 | # inflect.singular /^(ox)en/i, '\1' 9 | # inflect.irregular 'person', 'people' 10 | # inflect.uncountable %w( fish sheep ) 11 | # end 12 | 13 | # These inflection rules are supported but not enabled by default: 14 | # ActiveSupport::Inflector.inflections(:en) do |inflect| 15 | # inflect.acronym 'RESTful' 16 | # end 17 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/mime_types.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Add new mime types for use in respond_to blocks: 4 | # Mime::Type.register "text/richtext", :rtf 5 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/secret_token.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | # Make sure the secret is at least 30 characters and all random, 6 | # no regular words or you'll be exposed to dictionary attacks. 7 | ExampleRailsApp::Application.config.secret_token = '3dcfefe6b0380c79ff1c1716e0d42982daa35354fbb427ed71977d67fd7ae2ff62b390b6a1055b06aa111dce9fa603aca0366b51af66a082487062f92b654720' 8 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/session_store.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | Rails.application.config.session_store :cookie_store, key: '_example_rails_app_session' 4 | -------------------------------------------------------------------------------- /example-rails-app/config/initializers/wrap_parameters.rb: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # This file contains settings for ActionController::ParamsWrapper which 4 | # is enabled by default. 5 | 6 | # Enable parameter wrapping for JSON. You can disable this by setting :format to an empty array. 7 | ActiveSupport.on_load(:action_controller) do 8 | wrap_parameters format: [:json] if respond_to?(:wrap_parameters) 9 | end 10 | 11 | # To enable root element in JSON for ActiveRecord objects. 12 | # ActiveSupport.on_load(:active_record) do 13 | # self.include_root_in_json = true 14 | # end 15 | -------------------------------------------------------------------------------- /example-rails-app/config/locales/en.yml: -------------------------------------------------------------------------------- 1 | # Files in the config/locales directory are used for internationalization 2 | # and are automatically loaded by Rails. If you want to use locales other 3 | # than English, add the necessary files in this directory. 4 | # 5 | # To use the locales, use `I18n.t`: 6 | # 7 | # I18n.t 'hello' 8 | # 9 | # In views, this is aliased to just `t`: 10 | # 11 | # <%= t('hello') %> 12 | # 13 | # To use a different locale, set it with `I18n.locale`: 14 | # 15 | # I18n.locale = :es 16 | # 17 | # This would use the information in config/locales/es.yml. 18 | # 19 | # To learn more, please read the Rails Internationalization guide 20 | # available at http://guides.rubyonrails.org/i18n.html. 21 | 22 | en: 23 | hello: "Hello world" 24 | -------------------------------------------------------------------------------- /example-rails-app/config/routes.rb: -------------------------------------------------------------------------------- 1 | Rails.application.routes.draw do 2 | root 'application#index' 3 | end 4 | -------------------------------------------------------------------------------- /example-rails-app/config/secrets.yml: -------------------------------------------------------------------------------- 1 | # Be sure to restart your server when you modify this file. 2 | 3 | # Your secret key is used for verifying the integrity of signed cookies. 4 | # If you change this key, all old signed cookies will become invalid! 5 | 6 | # Make sure the secret is at least 30 characters and all random, 7 | # no regular words or you'll be exposed to dictionary attacks. 8 | # You can use `rake secret` to generate a secure secret key. 9 | 10 | # Make sure the secrets in this file are kept private 11 | # if you're sharing your code publicly. 12 | 13 | development: 14 | secret_key_base: 63a74a8645f55d0368b273ca7eec6ec4c67acaa6fbeb2df014883fca3f1120ff674d2e77bde0d9266ccd5a31e51cec5d65f11ee4849635dc23a5cf4891c98d8f 15 | 16 | test: 17 | secret_key_base: ea77f9d0e6655f286f7c928d1a664defb4904242f83c46b7c30a7ca0fe960a4d5ecd4c5bcff0708b64532a6bfa8a189043856d112ef432376b98c42b1f6c8402 18 | 19 | # Do not keep production secrets in the repository, 20 | # instead read values from the environment. 21 | production: 22 | secret_key_base: <%= ENV["SECRET_KEY_BASE"] %> 23 | -------------------------------------------------------------------------------- /example-rails-app/db/development.sqlite3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/db/development.sqlite3 -------------------------------------------------------------------------------- /example-rails-app/db/seeds.rb: -------------------------------------------------------------------------------- 1 | # This file should contain all the record creation needed to seed the database with its default values. 2 | # The data can then be loaded with the rake db:seed (or created alongside the db with db:setup). 3 | # 4 | # Examples: 5 | # 6 | # cities = City.create([{ name: 'Chicago' }, { name: 'Copenhagen' }]) 7 | # Mayor.create(name: 'Emanuel', city: cities.first) 8 | -------------------------------------------------------------------------------- /example-rails-app/doc/README_FOR_APP: -------------------------------------------------------------------------------- 1 | Use this README file to introduce your application and point to useful places in the API for learning more. 2 | Run "rake doc:app" to generate API documentation for your models, controllers, helpers, and libraries. 3 | -------------------------------------------------------------------------------- /example-rails-app/lib/assets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/lib/assets/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/lib/tasks/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/lib/tasks/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/log/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/log/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/log/development.log: -------------------------------------------------------------------------------- 1 | 2 | 3 | Started GET "/assets/rails.png" for 93.47.231.89 at 2016-04-05 14:37:26 +0000 4 | Connecting to database specified by database.yml 5 | Sprockets Cache miss "file_digest:app/assets/images/rails.png:1459866924" (1ms) 6 | Served asset /rails.png - 200 OK (128ms) 7 | -------------------------------------------------------------------------------- /example-rails-app/public/404.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The page you were looking for doesn't exist (404) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The page you were looking for doesn't exist.

23 |

You may have mistyped the address or the page may have moved.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /example-rails-app/public/422.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | The change you wanted was rejected (422) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

The change you wanted was rejected.

23 |

Maybe you tried to change something you didn't have access to.

24 |
25 | 26 | 27 | -------------------------------------------------------------------------------- /example-rails-app/public/500.html: -------------------------------------------------------------------------------- 1 | 2 | 3 | 4 | We're sorry, but something went wrong (500) 5 | 17 | 18 | 19 | 20 | 21 |
22 |

We're sorry, but something went wrong.

23 |
24 | 25 | 26 | -------------------------------------------------------------------------------- /example-rails-app/public/favicon.ico: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/public/favicon.ico -------------------------------------------------------------------------------- /example-rails-app/public/robots.txt: -------------------------------------------------------------------------------- 1 | # See http://www.robotstxt.org/wc/norobots.html for documentation on how to use the robots.txt file 2 | # 3 | # To ban all spiders from the entire site uncomment the next two lines: 4 | # User-Agent: * 5 | # Disallow: / 6 | -------------------------------------------------------------------------------- /example-rails-app/script/rails: -------------------------------------------------------------------------------- 1 | #!/usr/bin/env ruby 2 | # This command will automatically be run when you run "rails" with Rails 3 gems installed from the root of your application. 3 | 4 | APP_PATH = File.expand_path('../../config/application', __FILE__) 5 | require File.expand_path('../../config/boot', __FILE__) 6 | require 'rails/commands' 7 | -------------------------------------------------------------------------------- /example-rails-app/test/fixtures/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/test/fixtures/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/test/functional/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/test/functional/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/test/integration/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/test/integration/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/test/performance/browsing_test.rb: -------------------------------------------------------------------------------- 1 | require 'test_helper' 2 | require 'rails/performance_test_help' 3 | 4 | class BrowsingTest < ActionDispatch::PerformanceTest 5 | # Refer to the documentation for all available options 6 | # self.profile_options = { :runs => 5, :metrics => [:wall_time, :memory] 7 | # :output => 'tmp/performance', :formats => [:flat] } 8 | 9 | def test_homepage 10 | get '/' 11 | end 12 | end 13 | -------------------------------------------------------------------------------- /example-rails-app/test/test_helper.rb: -------------------------------------------------------------------------------- 1 | ENV["RAILS_ENV"] = "test" 2 | require File.expand_path('../../config/environment', __FILE__) 3 | require 'rails/test_help' 4 | 5 | class ActiveSupport::TestCase 6 | # Setup all fixtures in test/fixtures/*.(yml|csv) for all tests in alphabetical order. 7 | # 8 | # Note: You'll currently still have to declare fixtures explicitly in integration tests 9 | # -- they do not yet inherit this setting 10 | fixtures :all 11 | 12 | # Add more helper methods to be used by all tests here... 13 | end 14 | -------------------------------------------------------------------------------- /example-rails-app/test/unit/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/test/unit/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/tmp/cache/assets/404/FB1/sprockets%2Fv3.0%2FBl90b2W_x-luH9JpUId0e9HoWLbCr1b6Sm5ouFF3vUU: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/tmp/cache/assets/404/FB1/sprockets%2Fv3.0%2FBl90b2W_x-luH9JpUId0e9HoWLbCr1b6Sm5ouFF3vUU -------------------------------------------------------------------------------- /example-rails-app/tmp/cache/assets/456/621/sprockets%2Fv3.0%2FiF87pDOFHbUvx-m34Et4rFyJc0pzK1Q1bdjoUVQzK7g: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/tmp/cache/assets/456/621/sprockets%2Fv3.0%2FiF87pDOFHbUvx-m34Et4rFyJc0pzK1Q1bdjoUVQzK7g -------------------------------------------------------------------------------- /example-rails-app/tmp/cache/assets/49C/BC1/sprockets%2Fv3.0%2F5eQEx6JCkKrKTqU4gDwP6WAiUuEgpSEFvrp3Vmkc_08: -------------------------------------------------------------------------------- 1 | o: ActiveSupport::Cache::Entry :@compressedF:@expires_in0:@created_atf1459867047.0787113: @value"}I"sapp/assets/images/rails.png?type=image/png&id=a4ebe29a89f50494feee49f06e8e46275aa9508e41bc67f39a260a10c7f3d096:EF -------------------------------------------------------------------------------- /example-rails-app/tmp/cache/assets/4EE/7F1/sprockets%2Fv3.0%2F9PIO2pMXjcKtNTwGlShXht2vejB3dKZSupd8-1UWuds: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/tmp/cache/assets/4EE/7F1/sprockets%2Fv3.0%2F9PIO2pMXjcKtNTwGlShXht2vejB3dKZSupd8-1UWuds -------------------------------------------------------------------------------- /example-rails-app/vendor/assets/javascripts/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/vendor/assets/javascripts/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/vendor/assets/stylesheets/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/vendor/assets/stylesheets/.gitkeep -------------------------------------------------------------------------------- /example-rails-app/vendor/plugins/.gitkeep: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/gruntwork-io/infrastructure-as-code-training/0e5acae59c5ca97d267a56c83422d7c088562cc6/example-rails-app/vendor/plugins/.gitkeep -------------------------------------------------------------------------------- /packer-example/README.md: -------------------------------------------------------------------------------- 1 | # Packer example 2 | 3 | This folder contains an example of how define infrastructure-as-code using [Packer](https://www.packer.io/). The 4 | `simple-web-server.json` Packer template shows how to create an AMI containing a simple web server that you can deploy 5 | in AWS. The AMI is built on top of Ubuntu, has Ruby on Rails installed, and contains the code from the 6 | `example-rails-app` folder. 7 | 8 | ## Quick start 9 | 10 | 1. Install [Packer](https://www.packer.io/). 11 | 2. Add your AWS credentials as the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. 12 | 3. Run `packer build simple-web-server.json`. 13 | 4. When the build is done, it'll output the ID of an AMI in `us-east-2` that you can deploy. See the 14 | `terraform-example-full` folder for an example of how to deploy this AMI and run the Ruby on Rails app within it. 15 | -------------------------------------------------------------------------------- /packer-example/install-rails.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # A script that install Ruby on Rails on Ubuntu. 3 | 4 | set -e 5 | 6 | sudo apt-get update 7 | sudo DEBIAN_FRONTEND=noninteractive apt-get install -y rails libsqlite3-dev sqlite3 nodejs 8 | rails -v 9 | -------------------------------------------------------------------------------- /packer-example/simple-web-server.json: -------------------------------------------------------------------------------- 1 | { 2 | "variables": { 3 | "region": "us-east-2" 4 | }, 5 | "builders": [{ 6 | "ami_name": "gruntwork-packer-training-rails-{{isotime | clean_resource_name}}", 7 | "ami_description": "An Ubuntu AMI that has Ruby on Rails installed.", 8 | "instance_type": "t2.micro", 9 | "region": "{{user `region`}}", 10 | "type": "amazon-ebs", 11 | "source_ami_filter": { 12 | "filters": { 13 | "virtualization-type": "hvm", 14 | "architecture": "x86_64", 15 | "name": "*ubuntu-xenial-16.04-amd64-server-*", 16 | "block-device-mapping.volume-type": "gp2", 17 | "root-device-type": "ebs" 18 | }, 19 | "owners": ["099720109477"], 20 | "most_recent": true 21 | }, 22 | "ssh_username": "ubuntu" 23 | }], 24 | "provisioners": [{ 25 | "type": "shell", 26 | "inline": [ 27 | "echo 'Sleeping for 30 seconds to give Ubuntu enough time to initialize (otherwise, packages may fail to install).'", 28 | "sleep 30" 29 | ] 30 | },{ 31 | "type": "shell", 32 | "script": "{{template_dir}}/install-rails.sh" 33 | },{ 34 | "type": "file", 35 | "source": "{{template_dir}}/../example-rails-app", 36 | "destination": "/home/ubuntu" 37 | },{ 38 | "type": "shell", 39 | "inline": [ 40 | "cd /home/ubuntu/example-rails-app", 41 | "bundle install" 42 | ] 43 | }] 44 | } 45 | -------------------------------------------------------------------------------- /terraform-example-basic/README.md: -------------------------------------------------------------------------------- 1 | # Terraform example 2 | 3 | This folder contains an example of how define infrastructure-as-code using [Terraform](https://www.terraform.io/). The 4 | Terraform templates in this folder are the "Hello, World" of Terraform, showing how to create a single EC2 instance. 5 | 6 | ## Quick start 7 | 8 | Note: these Terraform templates create real resources in your AWS account. The resources are part of the [AWS Free 9 | Tier](https://aws.amazon.com/free/), but if you've used up all your credits, they may cost you money. 10 | 11 | 1. Install [Terraform](https://www.terraform.io/). 12 | 2. Add your AWS credentials as the environment variables `AWS_ACCESS_KEY_ID` and `AWS_SECRET_ACCESS_KEY`. 13 | 3. Run `terraform plan`. 14 | 4. If the plan looks good, run `terraform apply`. 15 | 16 | ## Making changes 17 | 18 | Try making some changes to the template to learn about basic Terraform features, as described in the following sections. 19 | 20 | ### Use a variable 21 | 22 | Variables make your templates configurable. To become familiar with variables, try defining one in `main.tf`: 23 | 24 | ```hcl 25 | variable "name" { 26 | description = "The name of the EC2 instance" 27 | } 28 | ``` 29 | 30 | Next, use that variable in the `tags` of the `aws_instance`: 31 | 32 | ```hcl 33 | resource "aws_instance" "example" { 34 | // ... 35 | 36 | tags { 37 | Name = "${var.name}" 38 | } 39 | } 40 | ``` 41 | 42 | Try running `terraform plan` and `terraform apply` to see what happens. 43 | 44 | ### Use dependencies 45 | 46 | Terraform resources can depend on each other. Terraform will automatically build a dependency graph and ensure the 47 | resources get created in the right order. For example, to add an IP address to the EC2 instance, you can define an 48 | `aws_eip` resource: 49 | 50 | ```hcl 51 | resource "aws_eip" "example" { 52 | instance = "${aws_instance.example.id}" 53 | } 54 | ``` 55 | 56 | Notice how the `instance` parameter is set to `"${aws_instance.example.id}"`. This is dependency on the `id` attribute 57 | of the `aws_instance` you've already created. Terraform now knows that when you `apply` these templates, it needs to 58 | create the `aws_instance` first, pull out its `id`, and then it can create the `aws_eip`. 59 | 60 | ## Cleaning up 61 | 62 | To clean up the resources created by these templates, just run `terraform destroy`. -------------------------------------------------------------------------------- /terraform-example-basic/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | # This module is now only being tested with Terraform 1.1.x. However, to make upgrading easier, we are setting 1.0.0 as the minimum version. 3 | required_version = ">= 1.0.0" 4 | } 5 | 6 | # Configure the AWS Provider 7 | provider "aws" { 8 | region = "us-east-2" 9 | } 10 | 11 | # Create an EC2 instance 12 | resource "aws_instance" "example" { 13 | # AMI ID for Amazon Linux AMI 2018.03.0 (HVM) 14 | ami = "ami-0c64dd618a49aeee8" 15 | instance_type = "t3.micro" 16 | 17 | tags = { 18 | Name = "example" 19 | } 20 | } 21 | 22 | -------------------------------------------------------------------------------- /terraform-example-full/README.md: -------------------------------------------------------------------------------- 1 | # Terraform example 2 | 3 | This folder contains an example of how define infrastructure-as-code using [Terraform](https://www.terraform.io/). The 4 | Terraform templates in this folder show how to use the Terraform module defined in the [rails-module 5 | folder](./rails-module) to take the AMI created in the `packer-example folder`, deploy it on an EC2 instance, and run 6 | the Ruby on Rails app within the AMI. 7 | 8 | ## Quick start 9 | 10 | Note: these Terraform templates create real resources in your AWS account. The resources are part of the [AWS Free 11 | Tier](https://aws.amazon.com/free/), but if you've used up all your credits, they may cost you money. 12 | 13 | 1. Install [Terraform](https://www.terraform.io/). 14 | 1. Open `vars.tf`, set the environment variables specified at the top of the file, and fill in any other variables that 15 | don't have a `default`. 16 | 1. Run `terraform get`. 17 | 1. Run `terraform plan`. 18 | 1. If the plan looks good, run `terraform apply`. 19 | 1. After the templates have been applied, Terraform will output a URL. Once the server is up and running (which can 20 | take 1-2 minutes), visit this URL to test the Rails app. You should see the text "Hello, World". 21 | 22 | ## Cleaning up 23 | 24 | To clean up the resources created by these templates, just run `terraform destroy`. -------------------------------------------------------------------------------- /terraform-example-full/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | # This module is now only being tested with Terraform 1.1.x. However, to make upgrading easier, we are setting 1.0.0 as the minimum version. 3 | required_version = ">= 1.0.0" 4 | } 5 | 6 | # Configure the AWS Provider 7 | provider "aws" { 8 | region = "us-east-2" 9 | } 10 | 11 | # This shows an example of how to use a Terraform module. 12 | 13 | module "example_rails_app_stage" { 14 | # The source field can be a path on your file system or a Git URL (even a versioned one!) 15 | source = "./rails-module" 16 | 17 | # Pass parameters to the module 18 | name = "Example Rails App (Stage)" 19 | port = 3000 20 | ami = var.ami 21 | key_pair_name = var.key_pair_name 22 | } 23 | 24 | module "example_rails_app_prod" { 25 | # The source field can be a path on your file system or a Git URL (even a versioned one!) 26 | source = "./rails-module" 27 | 28 | # Pass parameters to the module 29 | name = "Example Rails App" 30 | port = 8080 31 | ami = var.ami 32 | key_pair_name = var.key_pair_name 33 | } 34 | -------------------------------------------------------------------------------- /terraform-example-full/outputs.tf: -------------------------------------------------------------------------------- 1 | # Output EC2 instance URL from the example_rails_app_stage module 2 | output "stage_url" { 3 | value = module.example_rails_app_stage.url 4 | } 5 | 6 | # Output EC2 instance URL from the example_rails_app_prod module 7 | output "prod_url" { 8 | value = module.example_rails_app_prod.url 9 | } 10 | -------------------------------------------------------------------------------- /terraform-example-full/rails-module/README.md: -------------------------------------------------------------------------------- 1 | # Rails Module 2 | 3 | These Terraform templates show an example of how to define a 4 | [Terraform Module](https://www.terraform.io/intro/getting-started/modules.html). This module shows an example of how 5 | to: 6 | 7 | 1. Take the AMI created in the `packer-example` folder. 8 | 2. Deploy it on an EC2 instance in AWS. 9 | 3. Run the Ruby on Rails app within the AMI. 10 | 11 | ## How to use this module 12 | 13 | * See the [Using Modules documentation](https://www.terraform.io/docs/modules/usage.html) on how to use modules in your 14 | code. 15 | * See [vars.tf](./vars.tf) for the parameters you need to pass to this module. 16 | * See [terraform-example-full](../) for an example. 17 | -------------------------------------------------------------------------------- /terraform-example-full/rails-module/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | # This module is now only being tested with Terraform 1.1.x. However, to make upgrading easier, we are setting 1.0.0 as the minimum version. 3 | required_version = ">= 1.0.0" 4 | } 5 | 6 | # Create an EC2 instance 7 | resource "aws_instance" "example_rails_app" { 8 | ami = var.ami 9 | instance_type = "t3.micro" 10 | security_groups = [aws_security_group.example_rails_app.name] 11 | user_data = data.template_file.user_data.rendered 12 | key_name = var.key_pair_name 13 | 14 | tags = { 15 | Name = var.name 16 | } 17 | } 18 | 19 | # A User Data script that will run when the EC2 instance boots up and start the Ruby on Rails server 20 | data "template_file" "user_data" { 21 | template = file("${path.module}/user-data.sh") 22 | 23 | vars = { 24 | port = var.port 25 | } 26 | } 27 | 28 | # A Security Group that controls what network traffic can go in and out of the EC2 instance 29 | resource "aws_security_group" "example_rails_app" { 30 | name = var.name 31 | description = "A Security Group for ${var.name}" 32 | 33 | # Inbound HTTP from anywhere 34 | ingress { 35 | from_port = var.port 36 | to_port = var.port 37 | protocol = "tcp" 38 | cidr_blocks = ["0.0.0.0/0"] 39 | } 40 | 41 | # Inbound SSH from anywhere 42 | ingress { 43 | from_port = 22 44 | to_port = 22 45 | protocol = "tcp" 46 | cidr_blocks = ["0.0.0.0/0"] 47 | } 48 | 49 | # Outbound everything 50 | egress { 51 | from_port = 0 52 | to_port = 0 53 | protocol = "-1" 54 | cidr_blocks = ["0.0.0.0/0"] 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /terraform-example-full/rails-module/outputs.tf: -------------------------------------------------------------------------------- 1 | # Output the URL of the EC2 instance after the templates are applied 2 | output "url" { 3 | value = "http://${aws_instance.example_rails_app.public_ip}:${var.port}" 4 | } 5 | -------------------------------------------------------------------------------- /terraform-example-full/rails-module/user-data.sh: -------------------------------------------------------------------------------- 1 | #!/bin/bash 2 | # A script that runs the Ruby on Rails app. It expects certain variables to be set via Terraform interpolation. 3 | 4 | set -e 5 | 6 | # Send the log output from this script to user-data.log, syslog, and the console 7 | # From: https://alestic.com/2010/12/ec2-user-data-output/ 8 | exec > >(tee /var/log/user-data.log|logger -t user-data -s 2>/dev/console) 2>&1 9 | 10 | echo "Starting Ruby on Rails app on port ${port} and piping all log output to syslog" 11 | cd /home/ubuntu/example-rails-app 12 | export RAILS_ENV=production 13 | nohup rails s --port=${port} --binding=0.0.0.0 2>&1 | logger & 14 | -------------------------------------------------------------------------------- /terraform-example-full/rails-module/vars.tf: -------------------------------------------------------------------------------- 1 | variable "name" { 2 | description = "The name used to namespace resources created by this module" 3 | type = string 4 | } 5 | 6 | variable "ami" { 7 | description = "The ID of the AMI that has Ruby on Rails installed and contains the code from the example-rails-app" 8 | type = string 9 | } 10 | 11 | variable "key_pair_name" { 12 | description = "The name of a Key Pair that you've created in AWS and have saved on your computer. You will be able to use this Key Pair to SSH to the EC2 instance." 13 | type = string 14 | } 15 | 16 | variable "port" { 17 | description = "The port the Ruby on Rails app should listen on for HTTP requests" 18 | type = number 19 | } 20 | -------------------------------------------------------------------------------- /terraform-example-full/vars.tf: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------------------------------------------------------------------------- 2 | # ENVIRONMENT VARIABLES 3 | # Define these secrets as environment variables 4 | # --------------------------------------------------------------------------------------------------------------------- 5 | 6 | # AWS_ACCESS_KEY_ID 7 | # AWS_SECRET_ACCESS_KEY 8 | 9 | # --------------------------------------------------------------------------------------------------------------------- 10 | # MODULE PARAMETERS 11 | # These variables are expected to be passed in by the operator 12 | # --------------------------------------------------------------------------------------------------------------------- 13 | 14 | variable "ami" { 15 | description = "The ID of the AMI that has Ruby on Rails installed and contains the code from the example-rails-app" 16 | type = string 17 | } 18 | 19 | variable "key_pair_name" { 20 | description = "The name of a Key Pair that you've created in AWS and have saved on your computer. You will be able to use this Key Pair to SSH to the EC2 instance." 21 | type = string 22 | } 23 | -------------------------------------------------------------------------------- /terraform-example-s3-backend/main.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | # This module is now only being tested with Terraform 1.1.x. However, to make upgrading easier, we are setting 1.0.0 as the minimum version. 3 | required_version = ">= 1.0.0" 4 | 5 | # Configure the Terraform backend 6 | backend "s3" { 7 | # Be sure to change this bucket name and region to match an S3 Bucket you have already created! 8 | bucket = "gruntwork-iac-training" 9 | region = "us-west-2" 10 | key = "terraform.tfstate" 11 | } 12 | } 13 | 14 | # Configure the AWS Provider 15 | provider "aws" { 16 | region = "us-east-2" 17 | } 18 | 19 | # Get the latest Amazon Linux AMI 20 | data "aws_ami" "amzn_linux" { 21 | most_recent = true 22 | owners = ["amazon"] 23 | 24 | filter { 25 | name = "root-device-type" 26 | values = ["ebs"] 27 | } 28 | 29 | filter { 30 | name = "name" 31 | values = ["amzn-ami-hvm-*"] 32 | } 33 | } 34 | 35 | # Create an EC2 instance 36 | resource "aws_instance" "example" { 37 | ami = data.aws_ami.amzn_linux.image_id 38 | instance_type = "t3.micro" 39 | key_name = var.key_pair_name 40 | 41 | tags = { 42 | Name = var.ec2_name 43 | } 44 | } 45 | -------------------------------------------------------------------------------- /terraform-example-s3-backend/vars.tf: -------------------------------------------------------------------------------- 1 | # --------------------------------------------------------------------------------------------------------------------- 2 | # ENVIRONMENT VARIABLES 3 | # Define these secrets as environment variables 4 | # --------------------------------------------------------------------------------------------------------------------- 5 | 6 | # AWS_ACCESS_KEY_ID 7 | # AWS_SECRET_ACCESS_KEY 8 | 9 | # --------------------------------------------------------------------------------------------------------------------- 10 | # MODULE PARAMETERS 11 | # These variables are expected to be passed in by the operator 12 | # --------------------------------------------------------------------------------------------------------------------- 13 | 14 | variable "ec2_name" { 15 | description = "The name of the EC2 Instance." 16 | type = string 17 | } 18 | 19 | variable "key_pair_name" { 20 | description = "The name of a Key Pair that you've created in AWS and have saved on your computer. You will be able to use this Key Pair to SSH to the EC2 instance." 21 | type = string 22 | } 23 | --------------------------------------------------------------------------------