├── CHANGELOG.md
├── LICENSE
├── README.md
├── copier.yml
└── project
├── .gitignore
├── .header.md
├── .pre-commit-config.yaml.jinja
├── .terraform-docs.yaml
├── .tflint.hcl.jinja
├── .tfsec
├── launch_configuration_imdsv2_tfchecks.json
├── launch_template_imdsv2_tfchecks.json
├── no_launch_config_tfchecks.json
├── sg_no_embedded_egress_rules_tfchecks.json
└── sg_no_embedded_ingress_rules_tfchecks.json
├── CHANGELOG.md.jinja
├── CODEOWNERS.jinja
├── LICENSE.jinja
├── NOTICE.txt
├── README.md.jinja
├── [[_copier_conf.answers_file]].jinja
├── examples
└── basic
│ ├── .header.md
│ ├── README.md.jinja
│ ├── main.tf
│ ├── outputs.tf
│ ├── providers.tf.jinja
│ └── variables.tf
├── main.tf
├── outputs.tf
├── providers.tf.jinja
├── scripts
└── post_provisioner.py.jinja
├── test
└── examples_basic_test.go
└── variables.tf
/CHANGELOG.md:
--------------------------------------------------------------------------------
1 | # copier-terraform-module Changelog
2 |
3 | ...
4 |
--------------------------------------------------------------------------------
/LICENSE:
--------------------------------------------------------------------------------
1 | Apache License
2 | Version 2.0, January 2004
3 | http://www.apache.org/licenses/
4 |
5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
6 |
7 | 1. Definitions.
8 |
9 | "License" shall mean the terms and conditions for use, reproduction,
10 | and distribution as defined by Sections 1 through 9 of this document.
11 |
12 | "Licensor" shall mean the copyright owner or entity authorized by
13 | the copyright owner that is granting the License.
14 |
15 | "Legal Entity" shall mean the union of the acting entity and all
16 | other entities that control, are controlled by, or are under common
17 | control with that entity. For the purposes of this definition,
18 | "control" means (i) the power, direct or indirect, to cause the
19 | direction or management of such entity, whether by contract or
20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
21 | outstanding shares, or (iii) beneficial ownership of such entity.
22 |
23 | "You" (or "Your") shall mean an individual or Legal Entity
24 | exercising permissions granted by this License.
25 |
26 | "Source" form shall mean the preferred form for making modifications,
27 | including but not limited to software source code, documentation
28 | source, and configuration files.
29 |
30 | "Object" form shall mean any form resulting from mechanical
31 | transformation or translation of a Source form, including but
32 | not limited to compiled object code, generated documentation,
33 | and conversions to other media types.
34 |
35 | "Work" shall mean the work of authorship, whether in Source or
36 | Object form, made available under the License, as indicated by a
37 | copyright notice that is included in or attached to the work
38 | (an example is provided in the Appendix below).
39 |
40 | "Derivative Works" shall mean any work, whether in Source or Object
41 | form, that is based on (or derived from) the Work and for which the
42 | editorial revisions, annotations, elaborations, or other modifications
43 | represent, as a whole, an original work of authorship. For the purposes
44 | of this License, Derivative Works shall not include works that remain
45 | separable from, or merely link (or bind by name) to the interfaces of,
46 | the Work and Derivative Works thereof.
47 |
48 | "Contribution" shall mean any work of authorship, including
49 | the original version of the Work and any modifications or additions
50 | to that Work or Derivative Works thereof, that is intentionally
51 | submitted to Licensor for inclusion in the Work by the copyright owner
52 | or by an individual or Legal Entity authorized to submit on behalf of
53 | the copyright owner. For the purposes of this definition, "submitted"
54 | means any form of electronic, verbal, or written communication sent
55 | to the Licensor or its representatives, including but not limited to
56 | communication on electronic mailing lists, source code control systems,
57 | and issue tracking systems that are managed by, or on behalf of, the
58 | Licensor for the purpose of discussing and improving the Work, but
59 | excluding communication that is conspicuously marked or otherwise
60 | designated in writing by the copyright owner as "Not a Contribution."
61 |
62 | "Contributor" shall mean Licensor and any individual or Legal Entity
63 | on behalf of whom a Contribution has been received by Licensor and
64 | subsequently incorporated within the Work.
65 |
66 | 2. Grant of Copyright License. Subject to the terms and conditions of
67 | this License, each Contributor hereby grants to You a perpetual,
68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
69 | copyright license to reproduce, prepare Derivative Works of,
70 | publicly display, publicly perform, sublicense, and distribute the
71 | Work and such Derivative Works in Source or Object form.
72 |
73 | 3. Grant of Patent License. Subject to the terms and conditions of
74 | this License, each Contributor hereby grants to You a perpetual,
75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
76 | (except as stated in this section) patent license to make, have made,
77 | use, offer to sell, sell, import, and otherwise transfer the Work,
78 | where such license applies only to those patent claims licensable
79 | by such Contributor that are necessarily infringed by their
80 | Contribution(s) alone or by combination of their Contribution(s)
81 | with the Work to which such Contribution(s) was submitted. If You
82 | institute patent litigation against any entity (including a
83 | cross-claim or counterclaim in a lawsuit) alleging that the Work
84 | or a Contribution incorporated within the Work constitutes direct
85 | or contributory patent infringement, then any patent licenses
86 | granted to You under this License for that Work shall terminate
87 | as of the date such litigation is filed.
88 |
89 | 4. Redistribution. You may reproduce and distribute copies of the
90 | Work or Derivative Works thereof in any medium, with or without
91 | modifications, and in Source or Object form, provided that You
92 | meet the following conditions:
93 |
94 | (a) You must give any other recipients of the Work or
95 | Derivative Works a copy of this License; and
96 |
97 | (b) You must cause any modified files to carry prominent notices
98 | stating that You changed the files; and
99 |
100 | (c) You must retain, in the Source form of any Derivative Works
101 | that You distribute, all copyright, patent, trademark, and
102 | attribution notices from the Source form of the Work,
103 | excluding those notices that do not pertain to any part of
104 | the Derivative Works; and
105 |
106 | (d) If the Work includes a "NOTICE" text file as part of its
107 | distribution, then any Derivative Works that You distribute must
108 | include a readable copy of the attribution notices contained
109 | within such NOTICE file, excluding those notices that do not
110 | pertain to any part of the Derivative Works, in at least one
111 | of the following places: within a NOTICE text file distributed
112 | as part of the Derivative Works; within the Source form or
113 | documentation, if provided along with the Derivative Works; or,
114 | within a display generated by the Derivative Works, if and
115 | wherever such third-party notices normally appear. The contents
116 | of the NOTICE file are for informational purposes only and
117 | do not modify the License. You may add Your own attribution
118 | notices within Derivative Works that You distribute, alongside
119 | or as an addendum to the NOTICE text from the Work, provided
120 | that such additional attribution notices cannot be construed
121 | as modifying the License.
122 |
123 | You may add Your own copyright statement to Your modifications and
124 | may provide additional or different license terms and conditions
125 | for use, reproduction, or distribution of Your modifications, or
126 | for any such Derivative Works as a whole, provided Your use,
127 | reproduction, and distribution of the Work otherwise complies with
128 | the conditions stated in this License.
129 |
130 | 5. Submission of Contributions. Unless You explicitly state otherwise,
131 | any Contribution intentionally submitted for inclusion in the Work
132 | by You to the Licensor shall be under the terms and conditions of
133 | this License, without any additional terms or conditions.
134 | Notwithstanding the above, nothing herein shall supersede or modify
135 | the terms of any separate license agreement you may have executed
136 | with Licensor regarding such Contributions.
137 |
138 | 6. Trademarks. This License does not grant permission to use the trade
139 | names, trademarks, service marks, or product names of the Licensor,
140 | except as required for reasonable and customary use in describing the
141 | origin of the Work and reproducing the content of the NOTICE file.
142 |
143 | 7. Disclaimer of Warranty. Unless required by applicable law or
144 | agreed to in writing, Licensor provides the Work (and each
145 | Contributor provides its Contributions) on an "AS IS" BASIS,
146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
147 | implied, including, without limitation, any warranties or conditions
148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
149 | PARTICULAR PURPOSE. You are solely responsible for determining the
150 | appropriateness of using or redistributing the Work and assume any
151 | risks associated with Your exercise of permissions under this License.
152 |
153 | 8. Limitation of Liability. In no event and under no legal theory,
154 | whether in tort (including negligence), contract, or otherwise,
155 | unless required by applicable law (such as deliberate and grossly
156 | negligent acts) or agreed to in writing, shall any Contributor be
157 | liable to You for damages, including any direct, indirect, special,
158 | incidental, or consequential damages of any character arising as a
159 | result of this License or out of the use or inability to use the
160 | Work (including but not limited to damages for loss of goodwill,
161 | work stoppage, computer failure or malfunction, or any and all
162 | other commercial damages or losses), even if such Contributor
163 | has been advised of the possibility of such damages.
164 |
165 | 9. Accepting Warranty or Additional Liability. While redistributing
166 | the Work or Derivative Works thereof, You may choose to offer,
167 | and charge a fee for, acceptance of support, warranty, indemnity,
168 | or other liability obligations and/or rights consistent with this
169 | License. However, in accepting such obligations, You may act only
170 | on Your own behalf and on Your sole responsibility, not on behalf
171 | of any other Contributor, and only if You agree to indemnify,
172 | defend, and hold each Contributor harmless for any liability
173 | incurred by, or claims asserted against, such Contributor by reason
174 | of your accepting any such warranty or additional liability.
175 |
176 | END OF TERMS AND CONDITIONS
177 |
178 | APPENDIX: How to apply the Apache License to your work.
179 |
180 | To apply the Apache License to your work, attach the following
181 | boilerplate notice, with the fields enclosed by brackets "[]"
182 | replaced with your own identifying information. (Don't include
183 | the brackets!) The text should be enclosed in the appropriate
184 | comment syntax for the file format. We also recommend that a
185 | file or class name and description of purpose be included on the
186 | same "printed page" as the copyright notice for easier
187 | identification within third-party archives.
188 |
189 | Copyright [yyyy] [name of copyright owner]
190 |
191 | Licensed under the Apache License, Version 2.0 (the "License");
192 | you may not use this file except in compliance with the License.
193 | You may obtain a copy of the License at
194 |
195 | http://www.apache.org/licenses/LICENSE-2.0
196 |
197 | Unless required by applicable law or agreed to in writing, software
198 | distributed under the License is distributed on an "AS IS" BASIS,
199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
200 | See the License for the specific language governing permissions and
201 | limitations under the License.
202 |
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # Copier Terraform Module
2 |
3 | This project is a copier template for creating Terraform projects and modules.
4 |
5 | The copier template provided here is used to stamp out the GitHub repository template: [aws-ia/terraform-repo-template](https://github.com/aws-ia/terraform-repo-template).
6 |
7 | ## Prerequisites
8 |
9 | This project template uses the [`copier`](https://github.com/copier-org/copier) framework to facilitate project generation.
10 | Copier is a Python CLI and library for rendering project templates.
11 |
12 | In order to use this template (and copier, generally), you must first install Python, `git`, and the `copier` module.
13 |
14 | - [Download & Install Python 3.7+](https://www.python.org/downloads/)
15 | - [Download & Install Git](https://git-scm.com/book/en/v2/Getting-Started-Installing-Git)
16 | - [Install `copier`](https://copier.readthedocs.io/en/stable/#installation) (`pip install copier`)
17 |
18 | _Note: Please refer to the official Copier documentation if you encounter difficulty [here](https://copier.readthedocs.io/en/stable/#installation)._
19 |
20 | ## Usage
21 |
22 | This project generation template can be used by first installing the pre-requisites annotated above, followed by direct usage of this repository (depending on intended usecase):
23 |
24 | ### CLI
25 |
26 | ```bash
27 | # Directly against GitHub repository using HTTPS
28 | copier "https://github.com/aws-ia/copier-terraform-repo-template.git" target/project/path
29 |
30 | # or directly against GitHub using the gh shortcut
31 | copier "gh:aws-ia/copier-terraform-repo-template" target/project/path
32 | ```
33 |
34 | ### Programmatically (Python)
35 |
36 | ```python
37 | from copier import run_auto
38 |
39 | # Create a project from this upstream GitHub repository
40 | run_auto("https://github.com/aws-ia/copier-terraform-repo-template.git", "target/project/pathn")
41 |
42 | # You can also use "gh:" as a shortcut of "https://github.com/"
43 | run_auto("gh:aws-ia/copier-terraform-repo-template", "target/project/path")
44 | ```
45 |
46 | _Note: Please refer to the official Copier documentation for further information on using `copier` either programmatically or via the CLI [here](https://copier.readthedocs.io/en/stable/#quick-start)._
47 |
--------------------------------------------------------------------------------
/copier.yml:
--------------------------------------------------------------------------------
1 | # Copier Configuration
2 | _subdirectory: project
3 | _templates_suffix: .jinja
4 | _skip_if_exists:
5 | - CHANGELOG.md
6 | _tasks:
7 | - python scripts/post_provisioner.py
8 | _min_copier_version: "5.1.0"
9 |
10 | # Ensure backwards compatibility with Copier 5.x
11 | _envops:
12 | autoescape: false
13 | block_end_string: "%]"
14 | block_start_string: "[%"
15 | comment_end_string: "#]"
16 | comment_start_string: "[#"
17 | keep_trailing_newline: true
18 | variable_end_string: "]]"
19 | variable_start_string: "[["
20 |
21 | # User Input
22 | module_name:
23 | type: str
24 | help: The name of your module
25 |
26 | module_description:
27 | type: str
28 | help: The description of your module
29 |
30 | author_fullname:
31 | type: str
32 | help: Your full name
33 |
34 | author_email:
35 | type: str
36 | help: Your email
37 |
38 | author_username:
39 | type: str
40 | help: Your username (e.g. on GitHub/GitLab)
41 |
42 | vcs_provider:
43 | type: str
44 | help: Your VCS / repository provider
45 | default: github.com
46 | choices:
47 | - github.com
48 | - gitlab.com
49 |
50 | copyright_holder:
51 | type: str
52 | help: The name of the organization or individual holding the copyright
53 | default: '[[ author_fullname ]]'
54 |
55 | copyright_holder_email:
56 | type: str
57 | help: The email of the organization or individual holding the copyright
58 | default: '[[ author_email ]]'
59 |
60 | copyright_year:
61 | type: str
62 | help: The copyright year
63 | default: '2022'
64 |
65 | copyright_license:
66 | type: str
67 | help: Your project's license
68 | default: Apache License 2.0
69 | choices:
70 | - Apache License 2.0
71 | - MIT License
72 | - MIT-0 License
73 |
74 | enable_precommit:
75 | type: bool
76 | help: Enable pre-commit (for git hooks of common checks)?
77 | default: yes
78 |
79 | enable_tflint:
80 | type: bool
81 | help: Enable tflint (for more robust Terraform linting)?
82 | default: yes
83 |
84 | enable_tfsec:
85 | type: bool
86 | help: Enable TFSec (for Terraform security controls and custom checks)?
87 | default: yes
88 |
89 | enable_terraform_docs:
90 | type: bool
91 | help: Enable terraform-docs (for automatic documentation of common Terraform resources)?
92 | default: yes
93 |
94 | enable_examples:
95 | type: bool
96 | help: Enable Examples directory creation (for demonstrating basic module usage)?
97 | default: yes
98 |
99 | enable_terraform_tests:
100 | type: bool
101 | help: Enable basic Terraform test example (using Terratest)?
102 | default: yes
103 |
104 | enable_awscc:
105 | type: bool
106 | help: Enable AWS CC provider?
107 | default: yes
108 |
109 | terraform_version:
110 | type: str
111 | help: The Terraform required_version constraint value
112 | default: '>= 0.14.0'
113 |
114 | aws_provider_version:
115 | type: str
116 | help: The AWS Provider required_providers version constraint value.
117 | default: '>= 4.0.0, < 5.0.0'
118 |
119 | awscc_provider_version:
120 | type: str
121 | help: The AWS CC Provider required_providers version constraint value.
122 | default: '>= 0.24.0'
123 |
124 | minimum_pre_commit_version:
125 | type: str
126 | help: The minimum version of pre-commit supported by the output project git hook routines.
127 | default: '2.6.0'
128 |
129 | pre_commit_hooks_rev:
130 | type: str
131 | help: The pre-commit-hooks revision
132 | default: '80ed3f0a164f282afaac0b6aec70e20f7e541932'
133 |
134 | tflint_aws_plugin_version:
135 | type: str
136 | help: The TFLint AWS Plugin version
137 | default: '0.14.0'
138 |
--------------------------------------------------------------------------------
/project/.gitignore:
--------------------------------------------------------------------------------
1 | build/
2 | plan.out
3 | plan.out.json
4 |
5 | # Local .terraform directories
6 | .terraform/
7 |
8 | # .tfstate files
9 | *.tfstate
10 | *.tfstate.*
11 |
12 | # Crash log files
13 | crash.log
14 |
15 | # Exclude all .tfvars files, which are likely to contain sentitive data, such as
16 | # password, private keys, and other secrets. These should not be part of version
17 | # control as they are data points which are potentially sensitive and subject
18 | # to change depending on the environment.
19 | #
20 | *.tfvars
21 |
22 | # Ignore override files as they are usually used to override resources locally and so
23 | # are not checked in
24 | override.tf
25 | override.tf.json
26 | *_override.tf
27 | *_override.tf.json
28 |
29 | # Include override files you do wish to add to version control using negated pattern
30 | #
31 | # !example_override.tf
32 |
33 | # Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
34 | # example: *tfplan*
35 |
36 | # Ignore CLI configuration files
37 | .terraformrc
38 | terraform.rc
39 | .terraform.lock.hcl
40 |
41 | go.mod
42 | go.sum
43 |
--------------------------------------------------------------------------------
/project/.header.md:
--------------------------------------------------------------------------------
1 | # Creating modules for AWS I&A Organization
2 |
3 | This repo template is used to seed Terraform Module templates for the [AWS I&A GitHub organization](https://github.com/aws-ia). Usage of this template is allowed per included license. PRs to this template will be considered but are not guaranteed to be included. Consider creating an issue to discuss a feature you want to include before taking the time to create a PR.
4 | ### TL;DR
5 |
6 | 1. [install pre-commit](https://pre-commit.com/)
7 | 2. configure pre-commit: `pre-commit install`
8 | 3. install required tools
9 | - [tflint](https://github.com/terraform-linters/tflint)
10 | - [tfsec](https://aquasecurity.github.io/tfsec/v1.0.11/)
11 | - [terraform-docs](https://github.com/terraform-docs/terraform-docs)
12 | - [golang](https://go.dev/doc/install) (for macos you can use `brew`)
13 | - [coreutils](https://www.gnu.org/software/coreutils/)
14 |
15 | Write code according to [I&A module standards](https://aws-ia.github.io/standards-terraform/)
16 |
17 | ## Module Documentation
18 |
19 | **Do not manually update README.md**. `terraform-docs` is used to generate README files. For any instructions an content, please update [.header.md](./.header.md) then simply run `terraform-docs ./` or allow the `pre-commit` to do so.
20 |
21 | ## Terratest
22 |
23 | Please include tests to validate your examples/<> root modules, at a minimum. This can be accomplished with usually only slight modifications to the [boilerplate test provided in this template](./test/examples_basic_test.go)
24 |
25 | ### Configure and run Terratest
26 |
27 | 1. Install
28 |
29 | [golang](https://go.dev/doc/install) (for macos you can use `brew`)
30 | 2. Change directory into the test folder.
31 |
32 | `cd test`
33 | 3. Initialize your test
34 |
35 | go mod init github.com/[github org]/[repository]
36 |
37 | `go mod init github.com/aws-ia/terraform-aws-vpc`
38 | 4. Run tidy
39 |
40 | `git mod tidy`
41 | 5. Install Terratest
42 |
43 | `go get github.com/gruntwork-io/terratest/modules/terraform`
44 | 6. Run test (You can have multiple test files).
45 | - Run all tests
46 |
47 | `go test`
48 | - Run a specific test with a timeout
49 |
50 | `go test -run examples_basic_test.go -timeout 45m`
51 | ## Module Standards
52 |
53 | For best practices and information on developing with Terraform, see the [I&A Module Standards](https://aws-ia.github.io/standards-terraform/)
54 |
55 | ## Continuous Integration
56 |
57 | The I&A team uses AWS CodeBuild to perform continuous integration (CI) within the organization. Our CI uses the a repo's `.pre-commit-config.yaml` file as well as some other checks. All PRs with other CI will be rejected. See our [FAQ](https://aws-ia.github.io/standards-terraform/faq/#are-modules-protected-by-ci-automation) for more details.
--------------------------------------------------------------------------------
/project/.pre-commit-config.yaml.jinja:
--------------------------------------------------------------------------------
1 | ---
2 | fail_fast: false
3 | minimum_pre_commit_version: "[[ minimum_pre_commit_version ]]"
4 | repos:
5 | -
6 | repo: https://github.com/aws-ia/pre-commit-configs
7 | # To update run:
8 | # pre-commit autoupdate --freeze
9 | rev: [[ pre_commit_hooks_rev ]] # frozen: v1.5.0
10 | hooks:
11 | - id: aws-ia-meta-hook
12 |
--------------------------------------------------------------------------------
/project/.terraform-docs.yaml:
--------------------------------------------------------------------------------
1 | formatter: markdown
2 | header-from: .header.md
3 | settings:
4 | anchor: true
5 | color: true
6 | default: true
7 | escape: true
8 | html: true
9 | indent: 2
10 | required: true
11 | sensitive: true
12 | type: true
13 |
14 | sort:
15 | enabled: true
16 | by: required
17 |
18 | output:
19 | file: README.md
20 | mode: replace
21 |
--------------------------------------------------------------------------------
/project/.tflint.hcl.jinja:
--------------------------------------------------------------------------------
1 | # https://github.com/terraform-linters/tflint/blob/master/docs/user-guide/module-inspection.md
2 | # borrowed & modified indefinitely from https://github.com/ksatirli/building-infrastructure-you-can-mostly-trust/blob/main/.tflint.hcl
3 |
4 | plugin "aws" {
5 | enabled = true
6 | version = "[[ tflint_aws_plugin_version ]]"
7 | source = "github.com/terraform-linters/tflint-ruleset-aws"
8 | }
9 |
10 | config {
11 | module = true
12 | force = false
13 | }
14 |
15 | rule "terraform_required_providers" {
16 | enabled = true
17 | }
18 |
19 | rule "terraform_required_version" {
20 | enabled = true
21 | }
22 |
23 | rule "terraform_naming_convention" {
24 | enabled = true
25 | format = "snake_case"
26 | }
27 |
28 | rule "terraform_typed_variables" {
29 | enabled = true
30 | }
31 |
32 | rule "terraform_unused_declarations" {
33 | enabled = true
34 | }
35 |
36 | rule "terraform_comment_syntax" {
37 | enabled = true
38 | }
39 |
40 | rule "terraform_deprecated_index" {
41 | enabled = true
42 | }
43 |
44 | rule "terraform_deprecated_interpolation" {
45 | enabled = true
46 | }
47 |
48 | rule "terraform_documented_outputs" {
49 | enabled = true
50 | }
51 |
52 | rule "terraform_documented_variables" {
53 | enabled = true
54 | }
55 |
56 | rule "terraform_module_pinned_source" {
57 | enabled = true
58 | }
59 |
60 | rule "terraform_standard_module_structure" {
61 | enabled = true
62 | }
63 |
64 | rule "terraform_workspace_remote" {
65 | enabled = true
66 | }
67 |
--------------------------------------------------------------------------------
/project/.tfsec/launch_configuration_imdsv2_tfchecks.json:
--------------------------------------------------------------------------------
1 | {
2 | "checks": [
3 | {
4 | "code": "CUS002",
5 | "description": "Check to IMDSv2 is required on EC2 instances created by this Launch Template",
6 | "impact": "Instance metadata service can be interacted with freely",
7 | "resolution": "Enable HTTP token requirement for IMDS",
8 | "requiredTypes": [
9 | "resource"
10 | ],
11 | "requiredLabels": [
12 | "aws_launch_configuration"
13 | ],
14 | "severity": "CRITICAL",
15 | "matchSpec": {
16 | "action": "isPresent",
17 | "name": "metadata_options",
18 | "subMatch": {
19 | "action": "and",
20 | "predicateMatchSpec": [
21 | {
22 | "action": "equals",
23 | "name": "http_tokens",
24 | "value": "required"
25 |
26 | }
27 | ]
28 | }
29 | },
30 |
31 | "errorMessage": "is missing `metadata_options` block - it is required with `http_tokens` set to `required` to make Instance Metadata Service more secure.",
32 | "relatedLinks": [
33 | "https://tfsec.dev/docs/aws/ec2/enforce-http-token-imds#aws/ec2",
34 | "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_configuration#metadata-options",
35 | "https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service"
36 | ]
37 | }
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/project/.tfsec/launch_template_imdsv2_tfchecks.json:
--------------------------------------------------------------------------------
1 | {
2 | "checks": [
3 | {
4 | "code": "CUS001",
5 | "description": "Check to IMDSv2 is required on EC2 instances created by this Launch Template",
6 | "impact": "Instance metadata service can be interacted with freely",
7 | "resolution": "Enable HTTP token requirement for IMDS",
8 | "requiredTypes": [
9 | "resource"
10 | ],
11 | "requiredLabels": [
12 | "aws_launch_template"
13 | ],
14 | "severity": "CRITICAL",
15 | "matchSpec": {
16 | "action": "isPresent",
17 | "name": "metadata_options",
18 | "subMatch": {
19 | "action": "and",
20 | "predicateMatchSpec": [
21 | {
22 | "action": "equals",
23 | "name": "http_tokens",
24 | "value": "required"
25 |
26 | }
27 | ]
28 | }
29 | },
30 |
31 | "errorMessage": "is missing `metadata_options` block - it is required with `http_tokens` set to `required` to make Instance Metadata Service more secure.",
32 | "relatedLinks": [
33 | "https://tfsec.dev/docs/aws/ec2/enforce-http-token-imds#aws/ec2",
34 | "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template#metadata-options",
35 | "https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service"
36 | ]
37 | }
38 | ]
39 | }
40 |
--------------------------------------------------------------------------------
/project/.tfsec/no_launch_config_tfchecks.json:
--------------------------------------------------------------------------------
1 | {
2 | "checks": [
3 | {
4 | "code": "CUS003",
5 | "description": "Use `aws_launch_template` over `aws_launch_configuration",
6 | "impact": "Launch configurations are not capable of versions",
7 | "resolution": "Convert resource type and attributes to `aws_launch_template`",
8 | "requiredTypes": [
9 | "resource"
10 | ],
11 | "requiredLabels": [
12 | "aws_launch_configuration"
13 | ],
14 | "severity": "MEDIUM",
15 | "matchSpec": {
16 | "action": "notPresent",
17 | "name": "image_id"
18 | },
19 |
20 | "errorMessage": "should be changed to `aws_launch_template` since the functionality is the same but templates can be versioned.",
21 | "relatedLinks": [
22 | "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/launch_template",
23 | "https://aws.amazon.com/blogs/security/defense-in-depth-open-firewalls-reverse-proxies-ssrf-vulnerabilities-ec2-instance-metadata-service"
24 | ]
25 | }
26 | ]
27 | }
28 |
--------------------------------------------------------------------------------
/project/.tfsec/sg_no_embedded_egress_rules_tfchecks.json:
--------------------------------------------------------------------------------
1 | {
2 | "checks": [
3 | {
4 | "code": "CUS005",
5 | "description": "Security group rules should be defined with `aws_security_group_rule` instead of embedded.",
6 | "impact": "Embedded security group rules can cause issues during configuration updates.",
7 | "resolution": "Move `egress` rules to `aws_security_group_rule` and attach to `aws_security_group`.",
8 | "requiredTypes": [
9 | "resource"
10 | ],
11 | "requiredLabels": [
12 | "aws_security_group"
13 | ],
14 | "severity": "MEDIUM",
15 | "matchSpec": {
16 | "action": "notPresent",
17 | "name": "egress"
18 | },
19 |
20 | "errorMessage": "`egress` rules should be moved to `aws_security_group_rule` and attached to `aws_security_group` instead of embedded.",
21 | "relatedLinks": [
22 | "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule",
23 | "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group"
24 | ]
25 | }
26 | ]
27 | }
28 |
--------------------------------------------------------------------------------
/project/.tfsec/sg_no_embedded_ingress_rules_tfchecks.json:
--------------------------------------------------------------------------------
1 | {
2 | "checks": [
3 | {
4 | "code": "CUS004",
5 | "description": "Security group rules should be defined with `aws_security_group_rule` instead of embedded.",
6 | "impact": "Embedded security group rules can cause issues during configuration updates.",
7 | "resolution": "Move `ingress` rules to `aws_security_group_rule` and attach to `aws_security_group`.",
8 | "requiredTypes": [
9 | "resource"
10 | ],
11 | "requiredLabels": [
12 | "aws_security_group"
13 | ],
14 | "severity": "MEDIUM",
15 | "matchSpec": {
16 | "action": "notPresent",
17 | "name": "ingress"
18 | },
19 |
20 | "errorMessage": "`ingress` rules should be moved to `aws_security_group_rule` and attached to `aws_security_group` instead of embedded.",
21 | "relatedLinks": [
22 | "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule",
23 | "https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group"
24 | ]
25 | }
26 | ]
27 | }
28 |
--------------------------------------------------------------------------------
/project/CHANGELOG.md.jinja:
--------------------------------------------------------------------------------
1 | # [[ module_name ]] Changelog
2 |
3 | ...
4 |
--------------------------------------------------------------------------------
/project/CODEOWNERS.jinja:
--------------------------------------------------------------------------------
1 | * @[[author_username]]
2 |
--------------------------------------------------------------------------------
/project/LICENSE.jinja:
--------------------------------------------------------------------------------
1 | [% if copyright_license == 'Apache License 2.0' -%]
2 | Apache License
3 | Version 2.0, January 2004
4 | http://www.apache.org/licenses/
5 |
6 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION
7 |
8 | 1. Definitions.
9 |
10 | "License" shall mean the terms and conditions for use, reproduction,
11 | and distribution as defined by Sections 1 through 9 of this document.
12 |
13 | "Licensor" shall mean the copyright owner or entity authorized by
14 | the copyright owner that is granting the License.
15 |
16 | "Legal Entity" shall mean the union of the acting entity and all
17 | other entities that control, are controlled by, or are under common
18 | control with that entity. For the purposes of this definition,
19 | "control" means (i) the power, direct or indirect, to cause the
20 | direction or management of such entity, whether by contract or
21 | otherwise, or (ii) ownership of fifty percent (50%) or more of the
22 | outstanding shares, or (iii) beneficial ownership of such entity.
23 |
24 | "You" (or "Your") shall mean an individual or Legal Entity
25 | exercising permissions granted by this License.
26 |
27 | "Source" form shall mean the preferred form for making modifications,
28 | including but not limited to software source code, documentation
29 | source, and configuration files.
30 |
31 | "Object" form shall mean any form resulting from mechanical
32 | transformation or translation of a Source form, including but
33 | not limited to compiled object code, generated documentation,
34 | and conversions to other media types.
35 |
36 | "Work" shall mean the work of authorship, whether in Source or
37 | Object form, made available under the License, as indicated by a
38 | copyright notice that is included in or attached to the work
39 | (an example is provided in the Appendix below).
40 |
41 | "Derivative Works" shall mean any work, whether in Source or Object
42 | form, that is based on (or derived from) the Work and for which the
43 | editorial revisions, annotations, elaborations, or other modifications
44 | represent, as a whole, an original work of authorship. For the purposes
45 | of this License, Derivative Works shall not include works that remain
46 | separable from, or merely link (or bind by name) to the interfaces of,
47 | the Work and Derivative Works thereof.
48 |
49 | "Contribution" shall mean any work of authorship, including
50 | the original version of the Work and any modifications or additions
51 | to that Work or Derivative Works thereof, that is intentionally
52 | submitted to Licensor for inclusion in the Work by the copyright owner
53 | or by an individual or Legal Entity authorized to submit on behalf of
54 | the copyright owner. For the purposes of this definition, "submitted"
55 | means any form of electronic, verbal, or written communication sent
56 | to the Licensor or its representatives, including but not limited to
57 | communication on electronic mailing lists, source code control systems,
58 | and issue tracking systems that are managed by, or on behalf of, the
59 | Licensor for the purpose of discussing and improving the Work, but
60 | excluding communication that is conspicuously marked or otherwise
61 | designated in writing by the copyright owner as "Not a Contribution."
62 |
63 | "Contributor" shall mean Licensor and any individual or Legal Entity
64 | on behalf of whom a Contribution has been received by Licensor and
65 | subsequently incorporated within the Work.
66 |
67 | 2. Grant of Copyright License. Subject to the terms and conditions of
68 | this License, each Contributor hereby grants to You a perpetual,
69 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
70 | copyright license to reproduce, prepare Derivative Works of,
71 | publicly display, publicly perform, sublicense, and distribute the
72 | Work and such Derivative Works in Source or Object form.
73 |
74 | 3. Grant of Patent License. Subject to the terms and conditions of
75 | this License, each Contributor hereby grants to You a perpetual,
76 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable
77 | (except as stated in this section) patent license to make, have made,
78 | use, offer to sell, sell, import, and otherwise transfer the Work,
79 | where such license applies only to those patent claims licensable
80 | by such Contributor that are necessarily infringed by their
81 | Contribution(s) alone or by combination of their Contribution(s)
82 | with the Work to which such Contribution(s) was submitted. If You
83 | institute patent litigation against any entity (including a
84 | cross-claim or counterclaim in a lawsuit) alleging that the Work
85 | or a Contribution incorporated within the Work constitutes direct
86 | or contributory patent infringement, then any patent licenses
87 | granted to You under this License for that Work shall terminate
88 | as of the date such litigation is filed.
89 |
90 | 4. Redistribution. You may reproduce and distribute copies of the
91 | Work or Derivative Works thereof in any medium, with or without
92 | modifications, and in Source or Object form, provided that You
93 | meet the following conditions:
94 |
95 | (a) You must give any other recipients of the Work or
96 | Derivative Works a copy of this License; and
97 |
98 | (b) You must cause any modified files to carry prominent notices
99 | stating that You changed the files; and
100 |
101 | (c) You must retain, in the Source form of any Derivative Works
102 | that You distribute, all copyright, patent, trademark, and
103 | attribution notices from the Source form of the Work,
104 | excluding those notices that do not pertain to any part of
105 | the Derivative Works; and
106 |
107 | (d) If the Work includes a "NOTICE" text file as part of its
108 | distribution, then any Derivative Works that You distribute must
109 | include a readable copy of the attribution notices contained
110 | within such NOTICE file, excluding those notices that do not
111 | pertain to any part of the Derivative Works, in at least one
112 | of the following places: within a NOTICE text file distributed
113 | as part of the Derivative Works; within the Source form or
114 | documentation, if provided along with the Derivative Works; or,
115 | within a display generated by the Derivative Works, if and
116 | wherever such third-party notices normally appear. The contents
117 | of the NOTICE file are for informational purposes only and
118 | do not modify the License. You may add Your own attribution
119 | notices within Derivative Works that You distribute, alongside
120 | or as an addendum to the NOTICE text from the Work, provided
121 | that such additional attribution notices cannot be construed
122 | as modifying the License.
123 |
124 | You may add Your own copyright statement to Your modifications and
125 | may provide additional or different license terms and conditions
126 | for use, reproduction, or distribution of Your modifications, or
127 | for any such Derivative Works as a whole, provided Your use,
128 | reproduction, and distribution of the Work otherwise complies with
129 | the conditions stated in this License.
130 |
131 | 5. Submission of Contributions. Unless You explicitly state otherwise,
132 | any Contribution intentionally submitted for inclusion in the Work
133 | by You to the Licensor shall be under the terms and conditions of
134 | this License, without any additional terms or conditions.
135 | Notwithstanding the above, nothing herein shall supersede or modify
136 | the terms of any separate license agreement you may have executed
137 | with Licensor regarding such Contributions.
138 |
139 | 6. Trademarks. This License does not grant permission to use the trade
140 | names, trademarks, service marks, or product names of the Licensor,
141 | except as required for reasonable and customary use in describing the
142 | origin of the Work and reproducing the content of the NOTICE file.
143 |
144 | 7. Disclaimer of Warranty. Unless required by applicable law or
145 | agreed to in writing, Licensor provides the Work (and each
146 | Contributor provides its Contributions) on an "AS IS" BASIS,
147 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or
148 | implied, including, without limitation, any warranties or conditions
149 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A
150 | PARTICULAR PURPOSE. You are solely responsible for determining the
151 | appropriateness of using or redistributing the Work and assume any
152 | risks associated with Your exercise of permissions under this License.
153 |
154 | 8. Limitation of Liability. In no event and under no legal theory,
155 | whether in tort (including negligence), contract, or otherwise,
156 | unless required by applicable law (such as deliberate and grossly
157 | negligent acts) or agreed to in writing, shall any Contributor be
158 | liable to You for damages, including any direct, indirect, special,
159 | incidental, or consequential damages of any character arising as a
160 | result of this License or out of the use or inability to use the
161 | Work (including but not limited to damages for loss of goodwill,
162 | work stoppage, computer failure or malfunction, or any and all
163 | other commercial damages or losses), even if such Contributor
164 | has been advised of the possibility of such damages.
165 |
166 | 9. Accepting Warranty or Additional Liability. While redistributing
167 | the Work or Derivative Works thereof, You may choose to offer,
168 | and charge a fee for, acceptance of support, warranty, indemnity,
169 | or other liability obligations and/or rights consistent with this
170 | License. However, in accepting such obligations, You may act only
171 | on Your own behalf and on Your sole responsibility, not on behalf
172 | of any other Contributor, and only if You agree to indemnify,
173 | defend, and hold each Contributor harmless for any liability
174 | incurred by, or claims asserted against, such Contributor by reason
175 | of your accepting any such warranty or additional liability.
176 |
177 | END OF TERMS AND CONDITIONS
178 |
179 | APPENDIX: How to apply the Apache License to your work.
180 |
181 | To apply the Apache License to your work, attach the following
182 | boilerplate notice, with the fields enclosed by brackets "[]"
183 | replaced with your own identifying information. (Don't include
184 | the brackets!) The text should be enclosed in the appropriate
185 | comment syntax for the file format. We also recommend that a
186 | file or class name and description of purpose be included on the
187 | same "printed page" as the copyright notice for easier
188 | identification within third-party archives.
189 |
190 | Copyright [[ copyright_year ]] [[ copyright_holder ]]
191 |
192 | Licensed under the Apache License, Version 2.0 (the "License");
193 | you may not use this file except in compliance with the License.
194 | You may obtain a copy of the License at
195 |
196 | http://www.apache.org/licenses/LICENSE-2.0
197 |
198 | Unless required by applicable law or agreed to in writing, software
199 | distributed under the License is distributed on an "AS IS" BASIS,
200 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
201 | See the License for the specific language governing permissions and
202 | limitations under the License.
203 | [% elif copyright_license == 'MIT License' -%]
204 | MIT License
205 |
206 | Copyright (c) [[ copyright_year ]] [[ copyright_holder ]]
207 |
208 | Permission is hereby granted, free of charge, to any person obtaining a copy
209 | of this software and associated documentation files (the "Software"), to deal
210 | in the Software without restriction, including without limitation the rights
211 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
212 | copies of the Software, and to permit persons to whom the Software is
213 | furnished to do so, subject to the following conditions:
214 |
215 | The above copyright notice and this permission notice shall be included in all
216 | copies or substantial portions of the Software.
217 |
218 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
219 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
220 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
221 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
222 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
223 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
224 | SOFTWARE.
225 | [% elif copyright_license == 'MIT-0 License' -%]
226 | MIT No Attribution
227 |
228 | Copyright [[ copyright_year ]] [[ copyright_holder ]]
229 |
230 | Permission is hereby granted, free of charge, to any person obtaining a copy of this
231 | software and associated documentation files (the "Software"), to deal in the Software
232 | without restriction, including without limitation the rights to use, copy, modify,
233 | merge, publish, distribute, sublicense, and/or sell copies of the Software, and to
234 | permit persons to whom the Software is furnished to do so.
235 |
236 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED,
237 | INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
238 | PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT
239 | HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
240 | OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
241 | SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
242 | [%- endif %]
--------------------------------------------------------------------------------
/project/NOTICE.txt:
--------------------------------------------------------------------------------
1 | Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved.
2 |
3 | Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at
4 |
5 | http://aws.amazon.com/apache2.0/
6 |
7 | or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.
8 |
--------------------------------------------------------------------------------
/project/README.md.jinja:
--------------------------------------------------------------------------------
1 | # [[ module_name ]]
2 |
3 | [[ module_description ]]
4 |
5 |
6 | ## Creating modules for AWS I&A Organization
7 |
8 | This repo template is used to seed Terraform Module templates for the [AWS I&A GitHub organization](https://github.com/aws-ia). Usage of this template is allowed per included license. PRs to this template will be considered but are not guaranteed to be included. Consider creating an issue to discuss a feature you want to include before taking the time to create a PR.
9 |
10 | ### TL;DR
11 |
12 | 1. [install pre-commit](https://pre-commit.com/)
13 | 2. configure pre-commit: `pre-commit install`
14 | 3. install required tools
15 | - [tflint](https://github.com/terraform-linters/tflint)
16 | - [tfsec](https://aquasecurity.github.io/tfsec/v1.0.11/)
17 | - [terraform-docs](https://github.com/terraform-docs/terraform-docs)
18 | - [golang](https://go.dev/doc/install) (for macos you can use `brew`)
19 | - [coreutils](https://www.gnu.org/software/coreutils/)
20 |
21 | Write code according to [I&A module standards](https://aws-ia.github.io/standards-terraform/)
22 |
23 | ## Module Documentation
24 |
25 | **Do not manually update README.md**. `terraform-docs` is used to generate README files. For any instructions an content, please update [.header.md](./.header.md) then simply run `terraform-docs ./` or allow the `pre-commit` to do so.
26 |
27 | ## Terratest
28 |
29 | Please include tests to validate your examples/<> root modules, at a minimum. This can be accomplished with usually only slight modifications to the [boilerplate test provided in this template](./test/examples\_basic\_test.go)
30 |
31 | ### Configure and run Terratest
32 |
33 | 1. Install
34 |
35 | [golang](https://go.dev/doc/install) (for macos you can use `brew`)
36 | 2. Change directory into the test folder.
37 |
38 | `cd test`
39 | 3. Initialize your test
40 |
41 | go mod init github.com/[github org]/[repository]
42 |
43 | `go mod init github.com/aws-ia/terraform-aws-vpc`
44 | 4. Run tidy
45 |
46 | `git mod tidy`
47 | 5. Install Terratest
48 |
49 | `go get github.com/gruntwork-io/terratest/modules/terraform`
50 | 6. Run test (You can have multiple test files).
51 | - Run all tests
52 |
53 | `go test`
54 | - Run a specific test with a timeout
55 |
56 | `go test -run examples_basic_test.go -timeout 45m`
57 |
58 | ## Module Standards
59 |
60 | For best practices and information on developing with Terraform, see the [I&A Module Standards](https://aws-ia.github.io/standards-terraform/)
61 |
62 | ## Continuous Integration
63 |
64 | The I&A team uses AWS CodeBuild to perform continuous integration (CI) within the organization. Our CI uses the a repo's `.pre-commit-config.yaml` file as well as some other checks. All PRs with other CI will be rejected. See our [FAQ](https://aws-ia.github.io/standards-terraform/faq/#are-modules-protected-by-ci-automation) for more details.
65 |
66 | ## Requirements
67 |
68 | | Name | Version |
69 | |------|---------|
70 | | [terraform](#requirement\_terraform) | [[ terraform_version ]] |
71 | | [aws](#requirement\_aws) | [[ aws_provider_version ]] |
72 | [% if enable_awscc -%]| [awscc](#requirement\_awscc) | [[ awscc_provider_version ]] |[% endif %]
73 |
74 | ## Providers
75 |
76 | No providers.
77 |
78 | ## Modules
79 |
80 | No modules.
81 |
82 | ## Resources
83 |
84 | No resources.
85 |
86 | ## Inputs
87 |
88 | No inputs.
89 |
90 | ## Outputs
91 |
92 | No outputs.
93 |
94 |
--------------------------------------------------------------------------------
/project/[[_copier_conf.answers_file]].jinja:
--------------------------------------------------------------------------------
1 | # Changes here will be overwritten by Copier
2 | [[_copier_answers|to_nice_yaml]]
3 |
--------------------------------------------------------------------------------
/project/examples/basic/.header.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-ia/copier-terraform-repo-template/6585eeb345a2574e63577cfd9332180e9b04a620/project/examples/basic/.header.md
--------------------------------------------------------------------------------
/project/examples/basic/README.md.jinja:
--------------------------------------------------------------------------------
1 | # [[ module_name ]] - Basic Example
2 |
3 | This example demonstrates the basic usage of the **[[ module_name ]]** Terraform module.
4 |
5 |
6 | ## Requirements
7 |
8 | | Name | Version |
9 | |------|---------|
10 | | [terraform](#requirement\_terraform) | >= 0.14.0 |
11 | | [aws](#requirement\_aws) | >= 3.72.0 |
12 | | [awscc](#requirement\_awscc) | >= 0.11.0 |
13 |
14 | ## Providers
15 |
16 | No providers.
17 |
18 | ## Modules
19 |
20 | No modules.
21 |
22 | ## Resources
23 |
24 | No resources.
25 |
26 | ## Inputs
27 |
28 | No inputs.
29 |
30 | ## Outputs
31 |
32 | No outputs.
33 |
--------------------------------------------------------------------------------
/project/examples/basic/main.tf:
--------------------------------------------------------------------------------
1 | #####################################################################################
2 | # Terraform module examples are meant to show an _example_ on how to use a module
3 | # per use-case. The code below should not be copied directly but referenced in order
4 | # to build your own root module that invokes this module
5 | #####################################################################################
6 |
--------------------------------------------------------------------------------
/project/examples/basic/outputs.tf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-ia/copier-terraform-repo-template/6585eeb345a2574e63577cfd9332180e9b04a620/project/examples/basic/outputs.tf
--------------------------------------------------------------------------------
/project/examples/basic/providers.tf.jinja:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_version = "[[ terraform_version ]]"
3 | required_providers {
4 | aws = {
5 | source = "hashicorp/aws"
6 | version = "[[ aws_provider_version ]]"
7 | }
8 | [% if enable_awscc -%]
9 | awscc = {
10 | source = "hashicorp/awscc"
11 | version = "[[ awscc_provider_version ]]"
12 | }
13 | [%- endif %]
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/project/examples/basic/variables.tf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-ia/copier-terraform-repo-template/6585eeb345a2574e63577cfd9332180e9b04a620/project/examples/basic/variables.tf
--------------------------------------------------------------------------------
/project/main.tf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-ia/copier-terraform-repo-template/6585eeb345a2574e63577cfd9332180e9b04a620/project/main.tf
--------------------------------------------------------------------------------
/project/outputs.tf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-ia/copier-terraform-repo-template/6585eeb345a2574e63577cfd9332180e9b04a620/project/outputs.tf
--------------------------------------------------------------------------------
/project/providers.tf.jinja:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_version = "[[ terraform_version ]]"
3 | required_providers {
4 | aws = {
5 | source = "hashicorp/aws"
6 | version = "[[ aws_provider_version ]]"
7 | }
8 | [% if enable_awscc -%]
9 | awscc = {
10 | source = "hashicorp/awscc"
11 | version = "[[ awscc_provider_version ]]"
12 | }
13 | [%- endif %]
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/project/scripts/post_provisioner.py.jinja:
--------------------------------------------------------------------------------
1 | """Define the post provisioning steps to be taken by Copier to complete module generation."""
2 | import os
3 | import subprocess
4 | from shutil import rmtree
5 |
6 |
7 | def on_error_handler(func, path, exc_info) -> None:
8 | """Handle exceptions raised by the rmtree method."""
9 | print(f"Warning! Exception encountered while attempting to cleanup project path: ({path})! Continuing...\nExc Info: ({exc_info})")
10 |
11 |
12 | class CleanupModuleOutput:
13 | """Define the cleanup object to handle finalizing module output and self destuction."""
14 |
15 | def __init__(self) -> None:
16 | """Initialize the cleanup module output object."""
17 | self.vcs_provider: str = "[[ vcs_provider ]]"
18 | self.enable_tfsec: bool = [[ enable_tfsec ]]
19 | self.enable_precommit: bool = [[ enable_precommit ]]
20 | self.enable_terraform_tests: bool = [[ enable_terraform_tests ]]
21 | self.enable_tflint: bool = [[ enable_tflint ]]
22 | self.enable_terraform_docs: bool = [[ enable_terraform_docs ]]
23 | self.enable_examples: bool = [[ enable_examples ]]
24 |
25 | def remove_directory(self, directory_path: str) -> None:
26 | """Remove the target directory and it's contents by path."""
27 | rmtree(directory_path, onerror=on_error_handler)
28 |
29 | def remove_file(self, file_path: str) -> None:
30 | """Remove the target file by path."""
31 | try:
32 | os.remove(file_path)
33 | except OSError:
34 | print(f"Warning! OSError encountered while attempting to cleanup project file: ({file_path})! Continuing...")
35 |
36 | def cleanup(self) -> None:
37 | """Cleanup the module by executing cleanup methods."""
38 | self.cleanup_vcs()
39 | self.cleanup_precommit()
40 | self.cleanup_terraform_docs()
41 | self.cleanup_tfsec()
42 | self.cleanup_tests()
43 | self.cleanup_tflint()
44 | self.cleanup_examples()
45 |
46 | def cleanup_vcs(self) -> None:
47 | if self.vcs_provider == "github.com":
48 | self.remove_file(".gitlab-ci.yml")
49 | elif self.vcs_provider == "gitlab.com":
50 | self.remove_directory(".github")
51 |
52 | def cleanup_precommit(self) -> None:
53 | if not self.enable_precommit:
54 | self.remove_file(".pre-commit-config.yaml")
55 |
56 | def cleanup_tfsec(self) -> None:
57 | if not self.enable_tfsec:
58 | self.remove_directory(".tfsec")
59 |
60 | def cleanup_tflint(self) -> None:
61 | if not self.enable_tflint:
62 | self.remove_file(".tflint.hcl")
63 |
64 | def cleanup_terraform_docs(self) -> None:
65 | if not self.enable_terraform_docs:
66 | self.remove_file(".header.md")
67 | self.remove_file("examples/.header.md")
68 | self.remove_file(".terraform-docs.yaml")
69 |
70 | def cleanup_tests(self) -> None:
71 | if not self.enable_terraform_tests:
72 | self.remove_directory("tests")
73 |
74 | def cleanup_examples(self) -> None:
75 | if not self.enable_examples:
76 | self.remove_directory("examples")
77 |
78 | def execute_format(self) -> None:
79 | subprocess.run(["terraform", "fmt", "-recursive", "."])
80 |
81 | def self_destruct(self) -> None:
82 | self.remove_directory(os.path.dirname(__file__))
83 |
84 |
85 | if __name__ == "__main__":
86 | cleanup_module: CleanupModuleOutput = CleanupModuleOutput()
87 | cleanup_module.cleanup()
88 | cleanup_module.execute_format()
89 | cleanup_module.self_destruct()
90 | print("Module generated successfully!")
91 |
--------------------------------------------------------------------------------
/project/test/examples_basic_test.go:
--------------------------------------------------------------------------------
1 | package test
2 |
3 | import (
4 | "testing"
5 |
6 | "github.com/gruntwork-io/terratest/modules/terraform"
7 | )
8 |
9 | func TestExamplesBasic(t *testing.T) {
10 |
11 | terraformOptions := &terraform.Options{
12 | TerraformDir: "../examples/basic",
13 | // Vars: map[string]interface{}{
14 | // "myvar": "test",
15 | // "mylistvar": []string{"list_item_1"},
16 | // },
17 | }
18 |
19 | defer terraform.Destroy(t, terraformOptions)
20 | terraform.InitAndApply(t, terraformOptions)
21 | }
22 |
--------------------------------------------------------------------------------
/project/variables.tf:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/aws-ia/copier-terraform-repo-template/6585eeb345a2574e63577cfd9332180e9b04a620/project/variables.tf
--------------------------------------------------------------------------------