├── .editorconfig
├── .github
├── CODEOWNERS
├── ISSUE_TEMPLATE
│ ├── bug_report.md
│ ├── bug_report.yml
│ ├── config.yml
│ ├── feature_request.md
│ ├── feature_request.yml
│ └── question.md
├── PULL_REQUEST_TEMPLATE.md
├── banner.png
├── mergify.yml
├── renovate.json
├── settings.yml
└── workflows
│ ├── branch.yml
│ ├── chatops.yml
│ ├── release.yml
│ └── scheduled.yml
├── .gitignore
├── LICENSE
├── README.md
├── README.yaml
├── atmos.yaml
├── context.tf
├── elb.tf
├── examples
└── complete
│ ├── context.tf
│ ├── fixtures.us-east-2.tfvars
│ ├── main.tf
│ ├── outputs.tf
│ ├── variables.tf
│ └── versions.tf
├── main.tf
├── outputs.tf
├── test
├── .gitignore
├── Makefile
├── Makefile.alpine
└── src
│ ├── .gitignore
│ ├── Makefile
│ ├── examples_complete_test.go
│ ├── go.mod
│ └── go.sum
├── variables.tf
└── versions.tf
/.editorconfig:
--------------------------------------------------------------------------------
1 | # Unix-style newlines with a newline ending every file
2 | [*]
3 | charset = utf-8
4 | end_of_line = lf
5 | indent_size = 2
6 | indent_style = space
7 | insert_final_newline = true
8 | trim_trailing_whitespace = true
9 |
10 | [*.{tf,tfvars}]
11 | indent_size = 2
12 | indent_style = space
13 |
14 | [*.md]
15 | max_line_length = 0
16 | trim_trailing_whitespace = false
17 |
18 | # Override for Makefile
19 | [{Makefile, makefile, GNUmakefile, Makefile.*}]
20 | tab_width = 2
21 | indent_style = tab
22 | indent_size = 4
23 |
24 | [COMMIT_EDITMSG]
25 | max_line_length = 0
26 |
--------------------------------------------------------------------------------
/.github/CODEOWNERS:
--------------------------------------------------------------------------------
1 | # Use this file to define individuals or teams that are responsible for code in a repository.
2 | # Read more:
3 | #
4 | # Order is important: the last matching pattern has the highest precedence
5 |
6 | # These owners will be the default owners for everything
7 | * @cloudposse/engineering @cloudposse/contributors
8 |
9 | # Cloud Posse must review any changes to Makefiles
10 | **/Makefile @cloudposse/engineering
11 | **/Makefile.* @cloudposse/engineering
12 |
13 | # Cloud Posse must review any changes to GitHub actions
14 | .github/* @cloudposse/engineering
15 |
16 | # Cloud Posse must review any changes to standard context definition,
17 | # but some changes can be rubber-stamped.
18 | **/*.tf @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
19 | README.yaml @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
20 | README.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
21 | docs/*.md @cloudposse/engineering @cloudposse/contributors @cloudposse/approvers
22 |
23 | # Cloud Posse Admins must review all changes to CODEOWNERS or the mergify configuration
24 | .github/mergify.yml @cloudposse/admins
25 | .github/CODEOWNERS @cloudposse/admins
26 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | about: Create a report to help us improve
4 | title: ''
5 | labels: 'bug'
6 | assignees: ''
7 |
8 | ---
9 |
10 | Found a bug? Maybe our [Slack Community](https://slack.cloudposse.com) can help.
11 |
12 | [](https://slack.cloudposse.com)
13 |
14 | ## Describe the Bug
15 | A clear and concise description of what the bug is.
16 |
17 | ## Expected Behavior
18 | A clear and concise description of what you expected to happen.
19 |
20 | ## Steps to Reproduce
21 | Steps to reproduce the behavior:
22 | 1. Go to '...'
23 | 2. Run '....'
24 | 3. Enter '....'
25 | 4. See error
26 |
27 | ## Screenshots
28 | If applicable, add screenshots or logs to help explain your problem.
29 |
30 | ## Environment (please complete the following information):
31 |
32 | Anything that will help us triage the bug will help. Here are some ideas:
33 | - OS: [e.g. Linux, OSX, WSL, etc]
34 | - Version [e.g. 10.15]
35 |
36 | ## Additional Context
37 | Add any other context about the problem here.
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/bug_report.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Bug report
3 | description: Create a report to help us improve
4 | labels: ["bug"]
5 | assignees: [""]
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | Found a bug?
11 |
12 | Please checkout our [Slack Community](https://slack.cloudposse.com)
13 | or visit our [Slack Archive](https://archive.sweetops.com/).
14 |
15 | [](https://slack.cloudposse.com)
16 |
17 | - type: textarea
18 | id: concise-description
19 | attributes:
20 | label: Describe the Bug
21 | description: A clear and concise description of what the bug is.
22 | placeholder: What is the bug about?
23 | validations:
24 | required: true
25 |
26 | - type: textarea
27 | id: expected
28 | attributes:
29 | label: Expected Behavior
30 | description: A clear and concise description of what you expected.
31 | placeholder: What happened?
32 | validations:
33 | required: true
34 |
35 | - type: textarea
36 | id: reproduction-steps
37 | attributes:
38 | label: Steps to Reproduce
39 | description: Steps to reproduce the behavior.
40 | placeholder: How do we reproduce it?
41 | validations:
42 | required: true
43 |
44 | - type: textarea
45 | id: screenshots
46 | attributes:
47 | label: Screenshots
48 | description: If applicable, add screenshots or logs to help explain.
49 | validations:
50 | required: false
51 |
52 | - type: textarea
53 | id: environment
54 | attributes:
55 | label: Environment
56 | description: Anything that will help us triage the bug.
57 | placeholder: |
58 | - OS: [e.g. Linux, OSX, WSL, etc]
59 | - Version [e.g. 10.15]
60 | - Module version
61 | - Terraform version
62 | validations:
63 | required: false
64 |
65 | - type: textarea
66 | id: additional
67 | attributes:
68 | label: Additional Context
69 | description: |
70 | Add any other context about the problem here.
71 | validations:
72 | required: false
73 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/config.yml:
--------------------------------------------------------------------------------
1 | blank_issues_enabled: false
2 |
3 | contact_links:
4 |
5 | - name: Community Slack Team
6 | url: https://cloudposse.com/slack/
7 | about: |-
8 | Please ask and answer questions here.
9 |
10 | - name: Office Hours
11 | url: https://cloudposse.com/office-hours/
12 | about: |-
13 | Join us every Wednesday for FREE Office Hours (lunch & learn).
14 |
15 | - name: DevOps Accelerator Program
16 | url: https://cloudposse.com/accelerate/
17 | about: |-
18 | Own your infrastructure in record time. We build it. You drive it.
19 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.md:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature Request
3 | about: Suggest an idea for this project
4 | title: ''
5 | labels: 'feature request'
6 | assignees: ''
7 |
8 | ---
9 |
10 | Have a question? Please checkout our [Slack Community](https://slack.cloudposse.com) or visit our [Slack Archive](https://archive.sweetops.com/).
11 |
12 | [](https://slack.cloudposse.com)
13 |
14 | ## Describe the Feature
15 |
16 | A clear and concise description of what the bug is.
17 |
18 | ## Expected Behavior
19 |
20 | A clear and concise description of what you expected to happen.
21 |
22 | ## Use Case
23 |
24 | Is your feature request related to a problem/challenge you are trying to solve? Please provide some additional context of why this feature or capability will be valuable.
25 |
26 | ## Describe Ideal Solution
27 |
28 | A clear and concise description of what you want to happen. If you don't know, that's okay.
29 |
30 | ## Alternatives Considered
31 |
32 | Explain what alternative solutions or features you've considered.
33 |
34 | ## Additional Context
35 |
36 | Add any other context or screenshots about the feature request here.
37 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/feature_request.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Feature Request
3 | description: Suggest an idea for this project
4 | labels: ["feature request"]
5 | assignees: [""]
6 | body:
7 | - type: markdown
8 | attributes:
9 | value: |
10 | Have a question?
11 |
12 | Please checkout our [Slack Community](https://slack.cloudposse.com)
13 | or visit our [Slack Archive](https://archive.sweetops.com/).
14 |
15 | [](https://slack.cloudposse.com)
16 |
17 | - type: textarea
18 | id: concise-description
19 | attributes:
20 | label: Describe the Feature
21 | description: A clear and concise description of what the feature is.
22 | placeholder: What is the feature about?
23 | validations:
24 | required: true
25 |
26 | - type: textarea
27 | id: expected
28 | attributes:
29 | label: Expected Behavior
30 | description: A clear and concise description of what you expected.
31 | placeholder: What happened?
32 | validations:
33 | required: true
34 |
35 | - type: textarea
36 | id: use-case
37 | attributes:
38 | label: Use Case
39 | description: |
40 | Is your feature request related to a problem/challenge you are trying
41 | to solve?
42 |
43 | Please provide some additional context of why this feature or
44 | capability will be valuable.
45 | validations:
46 | required: true
47 |
48 | - type: textarea
49 | id: ideal-solution
50 | attributes:
51 | label: Describe Ideal Solution
52 | description: A clear and concise description of what you want to happen.
53 | validations:
54 | required: true
55 |
56 | - type: textarea
57 | id: alternatives-considered
58 | attributes:
59 | label: Alternatives Considered
60 | description: Explain alternative solutions or features considered.
61 | validations:
62 | required: false
63 |
64 | - type: textarea
65 | id: additional
66 | attributes:
67 | label: Additional Context
68 | description: |
69 | Add any other context about the problem here.
70 | validations:
71 | required: false
72 |
--------------------------------------------------------------------------------
/.github/ISSUE_TEMPLATE/question.md:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudposse/terraform-aws-utils/eb16232359c052ee129a7dd3cc898de4049bbe01/.github/ISSUE_TEMPLATE/question.md
--------------------------------------------------------------------------------
/.github/PULL_REQUEST_TEMPLATE.md:
--------------------------------------------------------------------------------
1 | ## what
2 |
3 |
7 |
8 | ## why
9 |
10 |
15 |
16 | ## references
17 |
18 |
22 |
--------------------------------------------------------------------------------
/.github/banner.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/cloudposse/terraform-aws-utils/eb16232359c052ee129a7dd3cc898de4049bbe01/.github/banner.png
--------------------------------------------------------------------------------
/.github/mergify.yml:
--------------------------------------------------------------------------------
1 | extends: .github
2 |
--------------------------------------------------------------------------------
/.github/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base",
4 | ":preserveSemverRanges",
5 | ":rebaseStalePrs"
6 | ],
7 | "baseBranches": ["main"],
8 | "labels": ["auto-update"],
9 | "dependencyDashboardAutoclose": true,
10 | "enabledManagers": ["terraform"],
11 | "terraform": {
12 | "ignorePaths": ["**/context.tf"]
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/.github/settings.yml:
--------------------------------------------------------------------------------
1 | # Upstream changes from _extends are only recognized when modifications are made to this file in the default branch.
2 | _extends: .github
3 | repository:
4 | name: terraform-aws-utils
5 | description: Utility functions for use with Terraform in the AWS environment
6 | homepage: https://cloudposse.com/accelerate
7 | topics: ""
8 |
9 |
10 |
11 |
12 |
--------------------------------------------------------------------------------
/.github/workflows/branch.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: Branch
3 | on:
4 | pull_request:
5 | branches:
6 | - main
7 | - release/**
8 | types: [opened, synchronize, reopened, labeled, unlabeled]
9 | push:
10 | branches:
11 | - main
12 | - release/v*
13 | paths-ignore:
14 | - '.github/**'
15 | - 'docs/**'
16 | - 'examples/**'
17 | - 'test/**'
18 | - 'README.md'
19 |
20 | permissions: {}
21 |
22 | jobs:
23 | terraform-module:
24 | uses: cloudposse/.github/.github/workflows/shared-terraform-module.yml@main
25 | secrets: inherit
26 |
--------------------------------------------------------------------------------
/.github/workflows/chatops.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: chatops
3 | on:
4 | issue_comment:
5 | types: [created]
6 |
7 | permissions:
8 | pull-requests: write
9 | id-token: write
10 | contents: write
11 | statuses: write
12 |
13 | jobs:
14 | test:
15 | uses: cloudposse/.github/.github/workflows/shared-terraform-chatops.yml@main
16 | if: ${{ github.event.issue.pull_request && contains(github.event.comment.body, '/terratest') }}
17 | secrets: inherit
18 |
--------------------------------------------------------------------------------
/.github/workflows/release.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: release
3 | on:
4 | release:
5 | types:
6 | - published
7 |
8 | permissions:
9 | id-token: write
10 | contents: write
11 | pull-requests: write
12 |
13 | jobs:
14 | terraform-module:
15 | uses: cloudposse/.github/.github/workflows/shared-release-branches.yml@main
16 | secrets: inherit
17 |
--------------------------------------------------------------------------------
/.github/workflows/scheduled.yml:
--------------------------------------------------------------------------------
1 | ---
2 | name: scheduled
3 | on:
4 | workflow_dispatch: { } # Allows manually trigger this workflow
5 | schedule:
6 | - cron: "0 3 * * *"
7 |
8 | permissions:
9 | pull-requests: write
10 | id-token: write
11 | contents: write
12 |
13 | jobs:
14 | scheduled:
15 | uses: cloudposse/.github/.github/workflows/shared-terraform-scheduled.yml@main
16 | secrets: inherit
17 |
--------------------------------------------------------------------------------
/.gitignore:
--------------------------------------------------------------------------------
1 | # Local .terraform directories
2 | **/.terraform/*
3 |
4 | # .tfstate files
5 | *.tfstate
6 | *.tfstate.*
7 | .terraform
8 | .terraform.tfstate.lock.info
9 |
10 | **/.idea
11 | **/*.iml
12 |
13 | # Cloud Posse Build Harness https://github.com/cloudposse/build-harness
14 | **/.build-harness
15 | **/build-harness
16 |
17 | # Crash log files
18 | crash.log
19 | test.log
20 |
--------------------------------------------------------------------------------
/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 2020-2024 Cloud Posse, LLC
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 |
2 |
3 |
4 | 
5 |
6 | 


7 |
8 |
9 |
29 |
30 | This `terraform-aws-utils` module provides some simple utilities to use when working in AWS.
31 |
32 |
33 | > [!TIP]
34 | > #### 👽 Use Atmos with Terraform
35 | > Cloud Posse uses [`atmos`](https://atmos.tools) to easily orchestrate multiple environments using Terraform.
36 | > Works with [Github Actions](https://atmos.tools/integrations/github-actions/), [Atlantis](https://atmos.tools/integrations/atlantis), or [Spacelift](https://atmos.tools/integrations/spacelift).
37 | >
38 | >
39 | > Watch demo of using Atmos with Terraform
40 | > 
41 | > Example of running atmos
to manage infrastructure from our Quick Start tutorial.
42 | >
43 |
44 |
45 | ## Introduction
46 |
47 | This `terraform-aws-utils` module provides some simple utilities to use when working in AWS.
48 | More complex utilities are available through Cloud Posse's `utils` Terraform provider
49 | [terraform-provider-utils](https://github.com/cloudposse/terraform-provider-utils).
50 |
51 | ### Compact Alternative Codes (Abbreviations)
52 | This module's primary function is to provide compact alternative codes for Regions, Availability Zones,
53 | and Local Zones, codes which are guaranteed to use only digits and lower case letters: no hyphens.
54 | Conversions to and from official codes and alternative codes are handled via lookup maps.
55 |
56 | - The `short` abbreviations for regions are variable length (generally 4-6 characters, but length limits not guaranteed)
57 | and strictly algorithmically derived so that people can more easily interpret them. The `short` region
58 | code abbreviations typically match the prefix of the Availability Zone IDs in that region, but this is
59 | not guaranteed. The `short` abbreviations for local regions are generally of the form AWS uses, with
60 | the region prefix and dashes removed.
61 | - The `fixed` abbreviations are always exactly 3 characters for regions and 4 characters
62 | for availability zones and local zones, but have some exceptional cases (China, Africa, Asia-Pacific South, US GovCloud)
63 | that have non-obvious abbreviations. If a future new region causes a conflict with an established local zone
64 | abbreviation, we may change the local zone abbreviation to keep the region mappings consistent. For example,
65 | the local zone `us-east-1-mci-1a` would have been abbreviated `mc1a` had we released it earlier, and that would have
66 | conflicted with the new (in 2022) `me-central-1a` which would also be abbreviated `mc1a` in keeping with the general
67 | pattern of using the first letter of each of the first 2 parts. We might have chosen to change the abbreviation
68 | for `us-east-1-mci-1` so we could use `mc1a` for `me-central-1a`. (As it happens, we added them both at the same
69 | time and avoided this collision.) If we were to make such a change, this
70 | would be a breaking change for people using the affected local zone, so we recommend using the `short`
71 | abbreviations if you are using local zones, which are far less likely to have conflicts in the future.
72 | - The `identity` "abbreviations" are not abbreviations but are instead the official codes (output equals input,
73 | which is why it is called "identity"). This map is provided to simplify algorithmic choice of region code
74 | abbreviation when you want to include a "no abbreviation" option.
75 |
76 | We currently support Local Zones but not Wavelength Zones. If we support Wavelength Zones in the future,
77 | it is likely that the fixed-length abbreviations for them will be non-intuitive, or we may only provide
78 | `short` and not `fixed` abbreviations for them.
79 |
80 | The intention is that existing region mappings will never change, and if new regions or zones are created that
81 | conflict with existing ones, they will be given non-standard mappings so as not to conflict. However, as
82 | stated above, we may choose to change a local region abbreviation if it conflicts with the obvious abbreviation
83 | for a newly created region. We have picked abbreviations for local zones with avoiding such future
84 | collisions in mind, but we cannot predict the future. (Both `bos` and `den` fit the pattern for region abbreviations,
85 | but we do not envision a future `bo-south-1` or `de-north-1` region.)
86 |
87 | ### ELB Logging
88 |
89 | This module provides Elastic Load Balancing Account IDs per region to be used in
90 | configuring [S3 Bucket Permissions](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions)
91 | to allow access logs to be stored in S3.
92 |
93 | However, the account IDs have no other purpose, and as AWS expands, it has become more complicated to create
94 | the correct bucket policy. The policy for region `me-central-1` is different than the policy for `us-east-1`.
95 | So now this module has a new feature: you provide the full AWS region code for the region where logging
96 | is to take place (`elb_logging_region`), and the S3 bucket ARN for where logs are to be stored (`elb_logging_bucket_resource_arn`),
97 | and this module will output the appropriate S3 bucket policy (in JSON) to attach to your S3 bucket.
98 |
99 | NOTE: The region must be known at Terraform "plan" time. Use a configuration input, such as what you used
100 | to configure the Terraform AWS Provider, not an output from some resource or module.
101 |
102 | ### Region Display Names
103 |
104 | There is no AWS API that reliably returns the human-friendly display name (e.g. "Europe (Stockholm)") given
105 | the API-friendly region name. So this module provides `region_display_name_map` to implement this functionality.
106 |
107 | ### Enabled and Disabled Regions
108 |
109 | For convenience, this module provides lists of enabled and disabled regions in the current account. Note that
110 | since these lists are dynamic, they cannot be used in Terraform `count` or `for_each` resource expressions.
111 |
112 |
113 | > [!TIP]
114 | > #### Use Terraform Reference Architectures for AWS
115 | >
116 | > Use Cloud Posse's ready-to-go [terraform architecture blueprints](https://cloudposse.com/reference-architecture/) for AWS to get up and running quickly.
117 | >
118 | > ✅ We build it together with your team.
119 | > ✅ Your team owns everything.
120 | > ✅ 100% Open Source and backed by fanatical support.
121 | >
122 | >
123 | > 📚 Learn More
124 | >
125 | >
126 | >
127 | > Cloud Posse is the leading [**DevOps Accelerator**](https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-utils&utm_content=commercial_support) for funded startups and enterprises.
128 | >
129 | > *Your team can operate like a pro today.*
130 | >
131 | > Ensure that your team succeeds by using Cloud Posse's proven process and turnkey blueprints. Plus, we stick around until you succeed.
132 | > #### Day-0: Your Foundation for Success
133 | > - **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
134 | > - **Deployment Strategy.** Adopt a proven deployment strategy with GitHub Actions, enabling automated, repeatable, and reliable software releases.
135 | > - **Site Reliability Engineering.** Gain total visibility into your applications and services with Datadog, ensuring high availability and performance.
136 | > - **Security Baseline.** Establish a secure environment from the start, with built-in governance, accountability, and comprehensive audit logs, safeguarding your operations.
137 | > - **GitOps.** Empower your team to manage infrastructure changes confidently and efficiently through Pull Requests, leveraging the full power of GitHub Actions.
138 | >
139 | >
140 | >
141 | > #### Day-2: Your Operational Mastery
142 | > - **Training.** Equip your team with the knowledge and skills to confidently manage the infrastructure, ensuring long-term success and self-sufficiency.
143 | > - **Support.** Benefit from a seamless communication over Slack with our experts, ensuring you have the support you need, whenever you need it.
144 | > - **Troubleshooting.** Access expert assistance to quickly resolve any operational challenges, minimizing downtime and maintaining business continuity.
145 | > - **Code Reviews.** Enhance your team’s code quality with our expert feedback, fostering continuous improvement and collaboration.
146 | > - **Bug Fixes.** Rely on our team to troubleshoot and resolve any issues, ensuring your systems run smoothly.
147 | > - **Migration Assistance.** Accelerate your migration process with our dedicated support, minimizing disruption and speeding up time-to-value.
148 | > - **Customer Workshops.** Engage with our team in weekly workshops, gaining insights and strategies to continuously improve and innovate.
149 | >
150 | >
151 | >
152 |
153 |
154 | ## Usage
155 |
156 | Here's how to invoke this example module in your projects
157 |
158 | ```hcl
159 | locals {
160 | shorten_regions = true
161 | naming_convention = local.shorten_regions ? "to_short" : "identity"
162 | az_map = module.example.region_az_alt_code_maps[local.naming_convention]
163 | }
164 |
165 | module "utils_example_complete" {
166 | source = "cloudposse/utils/aws"
167 | # Cloud Posse recommends pinning every module to a specific version
168 | # version = "x.x.x"
169 | }
170 |
171 | module "label" {
172 | source = "cloudposse/label/null"
173 | # Cloud Posse recommends pinning every module to a specific version
174 | # version = "x.x.x"
175 |
176 | attributes = [local.az_map["us-east-2"]]
177 |
178 | context = module.this.context
179 | }
180 | ```
181 |
182 | > [!IMPORTANT]
183 | > In Cloud Posse's examples, we avoid pinning modules to specific versions to prevent discrepancies between the documentation
184 | > and the latest released versions. However, for your own projects, we strongly advise pinning each module to the exact version
185 | > you're using. This practice ensures the stability of your infrastructure. Additionally, we recommend implementing a systematic
186 | > approach for updating versions to avoid unexpected changes.
187 |
188 |
189 |
190 |
191 |
192 | ## Examples
193 |
194 | Here is an example of using this module:
195 | - [`examples/complete`](examples/complete) - complete example of using this module
196 |
197 |
198 |
199 |
200 |
201 | ## Requirements
202 |
203 | | Name | Version |
204 | |------|---------|
205 | | [terraform](#requirement\_terraform) | >= 0.14.0 |
206 | | [aws](#requirement\_aws) | >= 2 |
207 |
208 | ## Providers
209 |
210 | | Name | Version |
211 | |------|---------|
212 | | [aws](#provider\_aws) | >= 2 |
213 |
214 | ## Modules
215 |
216 | | Name | Source | Version |
217 | |------|--------|---------|
218 | | [this](#module\_this) | cloudposse/label/null | 0.25.0 |
219 |
220 | ## Resources
221 |
222 | | Name | Type |
223 | |------|------|
224 | | [aws_iam_policy_document.by_account](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
225 | | [aws_iam_policy_document.by_region](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
226 | | [aws_regions.complete](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/regions) | data source |
227 | | [aws_regions.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/regions) | data source |
228 | | [aws_regions.not_opted_in](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/regions) | data source |
229 | | [aws_regions.opted_in](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/regions) | data source |
230 |
231 | ## Inputs
232 |
233 | | Name | Description | Type | Default | Required |
234 | |------|-------------|------|---------|:--------:|
235 | | [additional\_tag\_map](#input\_additional\_tag\_map) | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
This is for some rare cases where resources want additional configuration of tags
and therefore take a list of maps with tag key, value, and additional configuration. | `map(string)` | `{}` | no |
236 | | [attributes](#input\_attributes) | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
in the order they appear in the list. New attributes are appended to the
end of the list. The elements of the list are joined by the `delimiter`
and treated as a single ID element. | `list(string)` | `[]` | no |
237 | | [context](#input\_context) | Single object for setting entire context at once.
See description of individual variables for details.
Leave string and numeric variables as `null` to use default value.
Individual variable settings (non-null) override settings in context object,
except for attributes, tags, and additional\_tag\_map, which are merged. | `any` | {
"additional_tag_map": {},
"attributes": [],
"delimiter": null,
"descriptor_formats": {},
"enabled": true,
"environment": null,
"id_length_limit": null,
"label_key_case": null,
"label_order": [],
"label_value_case": null,
"labels_as_tags": [
"unset"
],
"name": null,
"namespace": null,
"regex_replace_chars": null,
"stage": null,
"tags": {},
"tenant": null
}
| no |
238 | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
239 | | [descriptor\_formats](#input\_descriptor\_formats) | Describe additional descriptors to be output in the `descriptors` output map.
Map of maps. Keys are names of descriptors. Values are maps of the form
`{
format = string
labels = list(string)
}`
(Type is `any` so the map values can later be enhanced to provide additional options.)
`format` is a Terraform format string to be passed to the `format()` function.
`labels` is a list of labels, in order, to pass to `format()` function.
Label values will be normalized before being passed to `format()` so they will be
identical to how they appear in `id`.
Default is `{}` (`descriptors` output will be empty). | `any` | `{}` | no |
240 | | [elb\_logging\_bucket\_resource\_arn](#input\_elb\_logging\_bucket\_resource\_arn) | The AWS Resource ARN to use in the policy granting access to Load Balancer Logging.
Typically of the form `arn:aws:s3:::_bucket-name_/_prefix_/AWSLogs/_your-aws-account-id_/*`.
Required to generate `elb_logging_s3_bucket_policy_json`.
See [AWS Documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-access-logging.html#attach-bucket-policy). | `string` | `""` | no |
241 | | [elb\_logging\_region](#input\_elb\_logging\_region) | Full region (e.g. `us-east-1`) where ELB logging is taking place. Required to generate `elb_s3_bucket_policy_json`.
Must be known at "plan" time. | `string` | `""` | no |
242 | | [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
243 | | [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
244 | | [id\_length\_limit](#input\_id\_length\_limit) | Limit `id` to this many characters (minimum 6).
Set to `0` for unlimited length.
Set to `null` for keep the existing setting, which defaults to `0`.
Does not affect `id_full`. | `number` | `null` | no |
245 | | [label\_key\_case](#input\_label\_key\_case) | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
Does not affect keys of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper`.
Default value: `title`. | `string` | `null` | no |
246 | | [label\_order](#input\_label\_order) | The order in which the labels (ID elements) appear in the `id`.
Defaults to ["namespace", "environment", "stage", "name", "attributes"].
You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present. | `list(string)` | `null` | no |
247 | | [label\_value\_case](#input\_label\_value\_case) | Controls the letter case of ID elements (labels) as included in `id`,
set as tag values, and output by this module individually.
Does not affect values of tags passed in via the `tags` input.
Possible values: `lower`, `title`, `upper` and `none` (no transformation).
Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
Default value: `lower`. | `string` | `null` | no |
248 | | [labels\_as\_tags](#input\_labels\_as\_tags) | Set of labels (ID elements) to include as tags in the `tags` output.
Default is to include all labels.
Tags with empty values will not be included in the `tags` output.
Set to `[]` to suppress all generated tags.
**Notes:**
The value of the `name` tag, if included, will be the `id`, not the `name`.
Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
changed in later chained modules. Attempts to change it will be silently ignored. | `set(string)` | [
"default"
]
| no |
249 | | [name](#input\_name) | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
This is the only ID element not also included as a `tag`.
The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input. | `string` | `null` | no |
250 | | [namespace](#input\_namespace) | ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique | `string` | `null` | no |
251 | | [regex\_replace\_chars](#input\_regex\_replace\_chars) | Terraform regular expression (regex) string.
Characters matching the regex will be removed from the ID elements.
If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits. | `string` | `null` | no |
252 | | [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
253 | | [tags](#input\_tags) | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
Neither the tag keys nor the tag values will be modified by this module. | `map(string)` | `{}` | no |
254 | | [tenant](#input\_tenant) | ID element \_(Rarely used, not included by default)\_. A customer identifier, indicating who this instance of a resource is for | `string` | `null` | no |
255 |
256 | ## Outputs
257 |
258 | | Name | Description |
259 | |------|-------------|
260 | | [all\_regions](#output\_all\_regions) | A list of all regions regardless of availability to the account |
261 | | [disabled\_regions](#output\_disabled\_regions) | A list of regions that are disabled in the account |
262 | | [elb\_logging\_account](#output\_elb\_logging\_account) | Map of full region to ELB logging account |
263 | | [elb\_logging\_s3\_bucket\_policy\_json](#output\_elb\_logging\_s3\_bucket\_policy\_json) | The S3 bucket policy (in JSON) to attach to the S3 bucket to allow Load Balancer logs to be added.
Requires `elb_logging_bucket_resource_arn` and `elb_logging_region` inputs. |
264 | | [enabled\_regions](#output\_enabled\_regions) | A list of regions that are enabled in the account |
265 | | [region\_az\_alt\_code\_maps](#output\_region\_az\_alt\_code\_maps) | Collection of maps converting between official AWS Region, Availability Zone, and Local Zone codes and shorter unofficial codes using only lower case letters and digits. Inspired for use in naming and tagging so that region or AZ code will be 1 semantic unit.
- `to_fixed` = Map of regions to 3-character codes and Availability Zones to 4-character codes
- `to_short` = Map of regions and Availability Zones to compact (usually 4-6 characters) codes
- `from_fixed` = Map of `fixed` codes back to full region or Availability Zone codes
- `from_short` = Map of `short` codes back to full region or Availability Zone codes
- `identity` = Identity map of full region and Availability Zone codes back to themselves |
266 | | [region\_display\_name\_map](#output\_region\_display\_name\_map) | Map of full region names to user-friendly display names (e.g. "eu-west-3" = "Europe (Paris)"). |
267 |
268 |
269 |
270 |
271 |
272 |
273 |
274 |
275 | ## Related Projects
276 |
277 | Check out these related projects.
278 |
279 | - [terraform-provider-utils](https://github.com/cloudposse/terraform-provider-utils) - The Cloud Posse Terraform Provider for various utilities (e.g. deep merging, stack configuration management).
280 | - [terraform-null-label](https://github.com/cloudposse/terraform-null-label) - Terraform module designed to generate consistent names and tags for resources. Use terraform-null-label to implement a strict naming convention.
281 |
282 |
283 | ## References
284 |
285 | For additional context, refer to some of these links.
286 |
287 | - [Terraform Standard Module Structure](https://www.terraform.io/docs/modules/index.html#standard-module-structure) - HashiCorp's standard module structure is a file and directory layout we recommend for reusable modules distributed in separate repositories.
288 | - [Terraform Module Requirements](https://www.terraform.io/docs/registry/modules/publish.html#requirements) - HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy.
289 | - [Terraform Version Pinning](https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version) - The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration
290 | - [AWS Regions and Zones](https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html) - AWS documentation on regions and zones
291 |
292 |
293 |
294 |
295 | ## ✨ Contributing
296 |
297 | This project is under active development, and we encourage contributions from our community.
298 |
299 |
300 |
301 | Many thanks to our outstanding contributors:
302 |
303 |
304 |
305 |
306 |
307 | For 🐛 bug reports & feature requests, please use the [issue tracker](https://github.com/cloudposse/terraform-aws-utils/issues).
308 |
309 | In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
310 | 1. Review our [Code of Conduct](https://github.com/cloudposse/terraform-aws-utils/?tab=coc-ov-file#code-of-conduct) and [Contributor Guidelines](https://github.com/cloudposse/.github/blob/main/CONTRIBUTING.md).
311 | 2. **Fork** the repo on GitHub
312 | 3. **Clone** the project to your own machine
313 | 4. **Commit** changes to your own branch
314 | 5. **Push** your work back up to your fork
315 | 6. Submit a **Pull Request** so that we can review your changes
316 |
317 | **NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request!
318 |
319 | ### 🌎 Slack Community
320 |
321 | Join our [Open Source Community](https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-utils&utm_content=slack) on Slack. It's **FREE** for everyone! Our "SweetOps" community is where you get to talk with others who share a similar vision for how to rollout and manage infrastructure. This is the best place to talk shop, ask questions, solicit feedback, and work together as a community to build totally *sweet* infrastructure.
322 |
323 | ### 📰 Newsletter
324 |
325 | Sign up for [our newsletter](https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-utils&utm_content=newsletter) and join 3,000+ DevOps engineers, CTOs, and founders who get insider access to the latest DevOps trends, so you can always stay in the know.
326 | Dropped straight into your Inbox every week — and usually a 5-minute read.
327 |
328 | ### 📆 Office Hours
329 |
330 | [Join us every Wednesday via Zoom](https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-utils&utm_content=office_hours) for your weekly dose of insider DevOps trends, AWS news and Terraform insights, all sourced from our SweetOps community, plus a _live Q&A_ that you can’t find anywhere else.
331 | It's **FREE** for everyone!
332 | ## License
333 |
334 |
335 |
336 |
337 | Preamble to the Apache License, Version 2.0
338 |
339 |
340 |
341 | Complete license is available in the [`LICENSE`](LICENSE) file.
342 |
343 | ```text
344 | Licensed to the Apache Software Foundation (ASF) under one
345 | or more contributor license agreements. See the NOTICE file
346 | distributed with this work for additional information
347 | regarding copyright ownership. The ASF licenses this file
348 | to you under the Apache License, Version 2.0 (the
349 | "License"); you may not use this file except in compliance
350 | with the License. You may obtain a copy of the License at
351 |
352 | https://www.apache.org/licenses/LICENSE-2.0
353 |
354 | Unless required by applicable law or agreed to in writing,
355 | software distributed under the License is distributed on an
356 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
357 | KIND, either express or implied. See the License for the
358 | specific language governing permissions and limitations
359 | under the License.
360 | ```
361 |
362 |
363 | ## Trademarks
364 |
365 | All other trademarks referenced herein are the property of their respective owners.
366 |
367 |
368 | ## Copyrights
369 |
370 | Copyright © 2020-2025 [Cloud Posse, LLC](https://cloudposse.com)
371 |
372 |
373 |
374 |
375 |
376 |
377 |
--------------------------------------------------------------------------------
/README.yaml:
--------------------------------------------------------------------------------
1 | #
2 | # This is the canonical configuration for the `README.md`
3 | # Run `make readme` to rebuild the `README.md`
4 | #
5 |
6 | # Name of this project
7 | name: terraform-aws-utils
8 |
9 | # Logo for this project
10 | #logo: docs/logo.png
11 |
12 | # License of this project
13 | license: "APACHE2"
14 |
15 | # Copyrights
16 | copyrights:
17 | - name: "Cloud Posse, LLC"
18 | url: "https://cloudposse.com"
19 | year: "2020"
20 |
21 | # Canonical GitHub repo
22 | github_repo: cloudposse/terraform-aws-utils
23 |
24 | # Badges to display
25 | badges:
26 | - name: Latest Release
27 | image: https://img.shields.io/github/release/cloudposse/terraform-aws-utils.svg?style=for-the-badge
28 | url: https://github.com/cloudposse/terraform-aws-utils/releases/latest
29 | - name: Last Updated
30 | image: https://img.shields.io/github/last-commit/cloudposse/terraform-aws-utils.svg?style=for-the-badge
31 | url: https://github.com/cloudposse/terraform-aws-utils/commits
32 | - name: Slack Community
33 | image: https://slack.cloudposse.com/for-the-badge.svg
34 | url: https://cloudposse.com/slack
35 |
36 | # List any related terraform modules that this module may be used with or that this module depends on.
37 | related:
38 | - name: "terraform-provider-utils"
39 | description: "The Cloud Posse Terraform Provider for various utilities (e.g. deep merging, stack configuration management)."
40 | url: "https://github.com/cloudposse/terraform-provider-utils"
41 | - name: "terraform-null-label"
42 | description: "Terraform module designed to generate consistent names and tags for resources. Use terraform-null-label to implement a strict naming convention."
43 | url: "https://github.com/cloudposse/terraform-null-label"
44 |
45 | # List any resources helpful for someone to get started. For example, link to the hashicorp documentation or AWS documentation.
46 | references:
47 | - name: "Terraform Standard Module Structure"
48 | description: "HashiCorp's standard module structure is a file and directory layout we recommend for reusable modules distributed in separate repositories."
49 | url: "https://www.terraform.io/docs/modules/index.html#standard-module-structure"
50 | - name: "Terraform Module Requirements"
51 | description: "HashiCorp's guidance on all the requirements for publishing a module. Meeting the requirements for publishing a module is extremely easy."
52 | url: "https://www.terraform.io/docs/registry/modules/publish.html#requirements"
53 | - name: "Terraform Version Pinning"
54 | description: "The required_version setting can be used to constrain which versions of the Terraform CLI can be used with your configuration"
55 | url: "https://www.terraform.io/docs/configuration/terraform.html#specifying-a-required-terraform-version"
56 | - name: "AWS Regions and Zones"
57 | description: "AWS documentation on regions and zones"
58 | url: "https://docs.aws.amazon.com/AmazonRDS/latest/UserGuide/Concepts.RegionsAndAvailabilityZones.html"
59 | # Short description of this project
60 | description: |-
61 | This `terraform-aws-utils` module provides some simple utilities to use when working in AWS.
62 |
63 | # Introduction to the project
64 | introduction: |-
65 | This `terraform-aws-utils` module provides some simple utilities to use when working in AWS.
66 | More complex utilities are available through Cloud Posse's `utils` Terraform provider
67 | [terraform-provider-utils](https://github.com/cloudposse/terraform-provider-utils).
68 |
69 | ### Compact Alternative Codes (Abbreviations)
70 | This module's primary function is to provide compact alternative codes for Regions, Availability Zones,
71 | and Local Zones, codes which are guaranteed to use only digits and lower case letters: no hyphens.
72 | Conversions to and from official codes and alternative codes are handled via lookup maps.
73 |
74 | - The `short` abbreviations for regions are variable length (generally 4-6 characters, but length limits not guaranteed)
75 | and strictly algorithmically derived so that people can more easily interpret them. The `short` region
76 | code abbreviations typically match the prefix of the Availability Zone IDs in that region, but this is
77 | not guaranteed. The `short` abbreviations for local regions are generally of the form AWS uses, with
78 | the region prefix and dashes removed.
79 | - The `fixed` abbreviations are always exactly 3 characters for regions and 4 characters
80 | for availability zones and local zones, but have some exceptional cases (China, Africa, Asia-Pacific South, US GovCloud)
81 | that have non-obvious abbreviations. If a future new region causes a conflict with an established local zone
82 | abbreviation, we may change the local zone abbreviation to keep the region mappings consistent. For example,
83 | the local zone `us-east-1-mci-1a` would have been abbreviated `mc1a` had we released it earlier, and that would have
84 | conflicted with the new (in 2022) `me-central-1a` which would also be abbreviated `mc1a` in keeping with the general
85 | pattern of using the first letter of each of the first 2 parts. We might have chosen to change the abbreviation
86 | for `us-east-1-mci-1` so we could use `mc1a` for `me-central-1a`. (As it happens, we added them both at the same
87 | time and avoided this collision.) If we were to make such a change, this
88 | would be a breaking change for people using the affected local zone, so we recommend using the `short`
89 | abbreviations if you are using local zones, which are far less likely to have conflicts in the future.
90 | - The `identity` "abbreviations" are not abbreviations but are instead the official codes (output equals input,
91 | which is why it is called "identity"). This map is provided to simplify algorithmic choice of region code
92 | abbreviation when you want to include a "no abbreviation" option.
93 |
94 | We currently support Local Zones but not Wavelength Zones. If we support Wavelength Zones in the future,
95 | it is likely that the fixed-length abbreviations for them will be non-intuitive, or we may only provide
96 | `short` and not `fixed` abbreviations for them.
97 |
98 | The intention is that existing region mappings will never change, and if new regions or zones are created that
99 | conflict with existing ones, they will be given non-standard mappings so as not to conflict. However, as
100 | stated above, we may choose to change a local region abbreviation if it conflicts with the obvious abbreviation
101 | for a newly created region. We have picked abbreviations for local zones with avoiding such future
102 | collisions in mind, but we cannot predict the future. (Both `bos` and `den` fit the pattern for region abbreviations,
103 | but we do not envision a future `bo-south-1` or `de-north-1` region.)
104 |
105 | ### ELB Logging
106 |
107 | This module provides Elastic Load Balancing Account IDs per region to be used in
108 | configuring [S3 Bucket Permissions](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/load-balancer-access-logs.html#access-logging-bucket-permissions)
109 | to allow access logs to be stored in S3.
110 |
111 | However, the account IDs have no other purpose, and as AWS expands, it has become more complicated to create
112 | the correct bucket policy. The policy for region `me-central-1` is different than the policy for `us-east-1`.
113 | So now this module has a new feature: you provide the full AWS region code for the region where logging
114 | is to take place (`elb_logging_region`), and the S3 bucket ARN for where logs are to be stored (`elb_logging_bucket_resource_arn`),
115 | and this module will output the appropriate S3 bucket policy (in JSON) to attach to your S3 bucket.
116 |
117 | NOTE: The region must be known at Terraform "plan" time. Use a configuration input, such as what you used
118 | to configure the Terraform AWS Provider, not an output from some resource or module.
119 |
120 | ### Region Display Names
121 |
122 | There is no AWS API that reliably returns the human-friendly display name (e.g. "Europe (Stockholm)") given
123 | the API-friendly region name. So this module provides `region_display_name_map` to implement this functionality.
124 |
125 | ### Enabled and Disabled Regions
126 |
127 | For convenience, this module provides lists of enabled and disabled regions in the current account. Note that
128 | since these lists are dynamic, they cannot be used in Terraform `count` or `for_each` resource expressions.
129 |
130 | # How to use this module. Should be an easy example to copy and paste.
131 | usage: |-
132 | Here's how to invoke this example module in your projects
133 |
134 | ```hcl
135 | locals {
136 | shorten_regions = true
137 | naming_convention = local.shorten_regions ? "to_short" : "identity"
138 | az_map = module.example.region_az_alt_code_maps[local.naming_convention]
139 | }
140 |
141 | module "utils_example_complete" {
142 | source = "cloudposse/utils/aws"
143 | # Cloud Posse recommends pinning every module to a specific version
144 | # version = "x.x.x"
145 | }
146 |
147 | module "label" {
148 | source = "cloudposse/label/null"
149 | # Cloud Posse recommends pinning every module to a specific version
150 | # version = "x.x.x"
151 |
152 | attributes = [local.az_map["us-east-2"]]
153 |
154 | context = module.this.context
155 | }
156 | ```
157 |
158 | # Example usage
159 | examples: |-
160 | Here is an example of using this module:
161 | - [`examples/complete`](examples/complete) - complete example of using this module
162 |
163 | # How to get started quickly
164 | #quickstart: |-
165 | # Here's how to get started...
166 |
167 | # Other files to include in this README from the project folder
168 | include: []
169 | contributors: []
170 |
--------------------------------------------------------------------------------
/atmos.yaml:
--------------------------------------------------------------------------------
1 | # Atmos Configuration — powered by https://atmos.tools
2 | #
3 | # This configuration enables centralized, DRY, and consistent project scaffolding using Atmos.
4 | #
5 | # Included features:
6 | # - Organizational custom commands: https://atmos.tools/core-concepts/custom-commands
7 | # - Automated README generation: https://atmos.tools/cli/commands/docs/generate
8 | #
9 |
10 | # Import shared configuration used by all modules
11 | import:
12 | - https://raw.githubusercontent.com/cloudposse/.github/refs/heads/main/.github/atmos/terraform-module.yaml
13 |
--------------------------------------------------------------------------------
/context.tf:
--------------------------------------------------------------------------------
1 | #
2 | # ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
3 | # All other instances of this file should be a copy of that one
4 | #
5 | #
6 | # Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
7 | # and then place it in your Terraform module to automatically get
8 | # Cloud Posse's standard configuration inputs suitable for passing
9 | # to Cloud Posse modules.
10 | #
11 | # curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf
12 | #
13 | # Modules should access the whole context as `module.this.context`
14 | # to get the input variables with nulls for defaults,
15 | # for example `context = module.this.context`,
16 | # and access individual variables as `module.this.`,
17 | # with final values filled in.
18 | #
19 | # For example, when using defaults, `module.this.context.delimiter`
20 | # will be null, and `module.this.delimiter` will be `-` (hyphen).
21 | #
22 |
23 | module "this" {
24 | source = "cloudposse/label/null"
25 | version = "0.25.0" # requires Terraform >= 0.13.0
26 |
27 | enabled = var.enabled
28 | namespace = var.namespace
29 | tenant = var.tenant
30 | environment = var.environment
31 | stage = var.stage
32 | name = var.name
33 | delimiter = var.delimiter
34 | attributes = var.attributes
35 | tags = var.tags
36 | additional_tag_map = var.additional_tag_map
37 | label_order = var.label_order
38 | regex_replace_chars = var.regex_replace_chars
39 | id_length_limit = var.id_length_limit
40 | label_key_case = var.label_key_case
41 | label_value_case = var.label_value_case
42 | descriptor_formats = var.descriptor_formats
43 | labels_as_tags = var.labels_as_tags
44 |
45 | context = var.context
46 | }
47 |
48 | # Copy contents of cloudposse/terraform-null-label/variables.tf here
49 |
50 | variable "context" {
51 | type = any
52 | default = {
53 | enabled = true
54 | namespace = null
55 | tenant = null
56 | environment = null
57 | stage = null
58 | name = null
59 | delimiter = null
60 | attributes = []
61 | tags = {}
62 | additional_tag_map = {}
63 | regex_replace_chars = null
64 | label_order = []
65 | id_length_limit = null
66 | label_key_case = null
67 | label_value_case = null
68 | descriptor_formats = {}
69 | # Note: we have to use [] instead of null for unset lists due to
70 | # https://github.com/hashicorp/terraform/issues/28137
71 | # which was not fixed until Terraform 1.0.0,
72 | # but we want the default to be all the labels in `label_order`
73 | # and we want users to be able to prevent all tag generation
74 | # by setting `labels_as_tags` to `[]`, so we need
75 | # a different sentinel to indicate "default"
76 | labels_as_tags = ["unset"]
77 | }
78 | description = <<-EOT
79 | Single object for setting entire context at once.
80 | See description of individual variables for details.
81 | Leave string and numeric variables as `null` to use default value.
82 | Individual variable settings (non-null) override settings in context object,
83 | except for attributes, tags, and additional_tag_map, which are merged.
84 | EOT
85 |
86 | validation {
87 | condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
88 | error_message = "Allowed values: `lower`, `title`, `upper`."
89 | }
90 |
91 | validation {
92 | condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
93 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
94 | }
95 | }
96 |
97 | variable "enabled" {
98 | type = bool
99 | default = null
100 | description = "Set to false to prevent the module from creating any resources"
101 | }
102 |
103 | variable "namespace" {
104 | type = string
105 | default = null
106 | description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique"
107 | }
108 |
109 | variable "tenant" {
110 | type = string
111 | default = null
112 | description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for"
113 | }
114 |
115 | variable "environment" {
116 | type = string
117 | default = null
118 | description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'"
119 | }
120 |
121 | variable "stage" {
122 | type = string
123 | default = null
124 | description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'"
125 | }
126 |
127 | variable "name" {
128 | type = string
129 | default = null
130 | description = <<-EOT
131 | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
132 | This is the only ID element not also included as a `tag`.
133 | The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input.
134 | EOT
135 | }
136 |
137 | variable "delimiter" {
138 | type = string
139 | default = null
140 | description = <<-EOT
141 | Delimiter to be used between ID elements.
142 | Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
143 | EOT
144 | }
145 |
146 | variable "attributes" {
147 | type = list(string)
148 | default = []
149 | description = <<-EOT
150 | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
151 | in the order they appear in the list. New attributes are appended to the
152 | end of the list. The elements of the list are joined by the `delimiter`
153 | and treated as a single ID element.
154 | EOT
155 | }
156 |
157 | variable "labels_as_tags" {
158 | type = set(string)
159 | default = ["default"]
160 | description = <<-EOT
161 | Set of labels (ID elements) to include as tags in the `tags` output.
162 | Default is to include all labels.
163 | Tags with empty values will not be included in the `tags` output.
164 | Set to `[]` to suppress all generated tags.
165 | **Notes:**
166 | The value of the `name` tag, if included, will be the `id`, not the `name`.
167 | Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
168 | changed in later chained modules. Attempts to change it will be silently ignored.
169 | EOT
170 | }
171 |
172 | variable "tags" {
173 | type = map(string)
174 | default = {}
175 | description = <<-EOT
176 | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
177 | Neither the tag keys nor the tag values will be modified by this module.
178 | EOT
179 | }
180 |
181 | variable "additional_tag_map" {
182 | type = map(string)
183 | default = {}
184 | description = <<-EOT
185 | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
186 | This is for some rare cases where resources want additional configuration of tags
187 | and therefore take a list of maps with tag key, value, and additional configuration.
188 | EOT
189 | }
190 |
191 | variable "label_order" {
192 | type = list(string)
193 | default = null
194 | description = <<-EOT
195 | The order in which the labels (ID elements) appear in the `id`.
196 | Defaults to ["namespace", "environment", "stage", "name", "attributes"].
197 | You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
198 | EOT
199 | }
200 |
201 | variable "regex_replace_chars" {
202 | type = string
203 | default = null
204 | description = <<-EOT
205 | Terraform regular expression (regex) string.
206 | Characters matching the regex will be removed from the ID elements.
207 | If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
208 | EOT
209 | }
210 |
211 | variable "id_length_limit" {
212 | type = number
213 | default = null
214 | description = <<-EOT
215 | Limit `id` to this many characters (minimum 6).
216 | Set to `0` for unlimited length.
217 | Set to `null` for keep the existing setting, which defaults to `0`.
218 | Does not affect `id_full`.
219 | EOT
220 | validation {
221 | condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
222 | error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
223 | }
224 | }
225 |
226 | variable "label_key_case" {
227 | type = string
228 | default = null
229 | description = <<-EOT
230 | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
231 | Does not affect keys of tags passed in via the `tags` input.
232 | Possible values: `lower`, `title`, `upper`.
233 | Default value: `title`.
234 | EOT
235 |
236 | validation {
237 | condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
238 | error_message = "Allowed values: `lower`, `title`, `upper`."
239 | }
240 | }
241 |
242 | variable "label_value_case" {
243 | type = string
244 | default = null
245 | description = <<-EOT
246 | Controls the letter case of ID elements (labels) as included in `id`,
247 | set as tag values, and output by this module individually.
248 | Does not affect values of tags passed in via the `tags` input.
249 | Possible values: `lower`, `title`, `upper` and `none` (no transformation).
250 | Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
251 | Default value: `lower`.
252 | EOT
253 |
254 | validation {
255 | condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
256 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
257 | }
258 | }
259 |
260 | variable "descriptor_formats" {
261 | type = any
262 | default = {}
263 | description = <<-EOT
264 | Describe additional descriptors to be output in the `descriptors` output map.
265 | Map of maps. Keys are names of descriptors. Values are maps of the form
266 | `{
267 | format = string
268 | labels = list(string)
269 | }`
270 | (Type is `any` so the map values can later be enhanced to provide additional options.)
271 | `format` is a Terraform format string to be passed to the `format()` function.
272 | `labels` is a list of labels, in order, to pass to `format()` function.
273 | Label values will be normalized before being passed to `format()` so they will be
274 | identical to how they appear in `id`.
275 | Default is `{}` (`descriptors` output will be empty).
276 | EOT
277 | }
278 |
279 | #### End of copy of cloudposse/terraform-null-label/variables.tf
280 |
--------------------------------------------------------------------------------
/elb.tf:
--------------------------------------------------------------------------------
1 | locals {
2 | // Do not base policy availability on resource ARN, as it may not be available at plan time
3 | elb_policy_enabled = (module.this.enabled &&
4 | try(length(var.elb_logging_region), 0) > 0
5 | )
6 |
7 | elb_policy_by_account = local.elb_policy_enabled && try(length(local.elb_logging_account[var.elb_logging_region]), 0) > 0
8 | elb_policy_by_region = local.elb_policy_enabled && !local.elb_policy_by_account
9 |
10 | # https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-access-logging.html#attach-bucket-policy
11 | elb_logging_account = {
12 | # For ease of maintenance, list accounts in same order as documentation does,
13 | # which is mostly alphabetical by display name, with exceptions.
14 | "us-east-1" = "127311923021" # "US East (N. Virginia)"
15 | "us-east-2" = "033677994240" # "US East (Ohio)"
16 | "us-west-1" = "027434742980" # "US West (N. California)"
17 | "us-west-2" = "797873946194" # "US West (Oregon)"
18 | "af-south-1" = "098369216593" # "Africa (Cape Town)"
19 | "ap-east-1" = "754344448648" # "Asia Pacific (Hong Kong)"
20 | "ap-southeast-3" = "589379963580" # "Asia Pacific (Jakarta)"
21 | "ap-south-1" = "718504428378" # "Asia Pacific (Mumbai)"
22 | "ap-northeast-3" = "383597477331" # "Asia Pacific (Osaka)"
23 | "ap-northeast-2" = "600734575887" # "Asia Pacific (Seoul)"
24 | "ap-southeast-1" = "114774131450" # "Asia Pacific (Singapore)"
25 | "ap-southeast-2" = "783225319266" # "Asia Pacific (Sydney)"
26 | "ap-northeast-1" = "582318560864" # "Asia Pacific (Tokyo)"
27 | "ca-central-1" = "985666609251" # "Canada (Central)"
28 | "eu-central-1" = "054676820928" # "Europe (Frankfurt)"
29 | "eu-west-1" = "156460612806" # "Europe (Ireland)"
30 | "eu-west-2" = "652711504416" # "Europe (London)"
31 | "eu-south-1" = "635631232127" # "Europe (Milan)"
32 | "eu-west-3" = "009996457667" # "Europe (Paris)"
33 | "eu-north-1" = "897822967062" # "Europe (Stockholm)"
34 | "me-south-1" = "076674570225" # "Middle East (Bahrain)"
35 | "sa-east-1" = "507241528517" # "South America (Sao Paulo)"
36 | "us-gov-west-1" = "048591011584" # "AWS GovCloud (US-West)"
37 | "us-gov-east-1" = "190560391635" # "AWS GovCloud (US-East)"
38 |
39 | # 2022-09-25: The `cn-*` account numbers are from the Chinese Language version of
40 | # https://docs.amazonaws.cn/elasticloadbalancing/latest/application/load-balancer-access-logs.html
41 | # and it is not clear if they should be used or if the new "by_region" policy
42 | # should be used instead. For now we continue to use the older "by_account" policy.
43 | "cn-north-1" = "638102146993"
44 | "cn-northwest-1" = "037604701340"
45 | }
46 | }
47 |
48 | data "aws_iam_policy_document" "by_account" {
49 | count = local.elb_policy_by_account ? 1 : 0
50 | statement {
51 | sid = "LoadBalancerLoggingAccess"
52 | effect = "Allow"
53 | resources = [var.elb_logging_bucket_resource_arn]
54 | actions = ["s3:PutObject"]
55 |
56 | principals {
57 | type = "AWS"
58 | identifiers = ["arn:aws:iam::${local.elb_logging_account[var.elb_logging_region]}:root"]
59 | }
60 | }
61 | }
62 |
63 | data "aws_iam_policy_document" "by_region" {
64 | count = local.elb_policy_by_region ? 1 : 0
65 | statement {
66 | sid = "LoadBalancerLoggingAccess"
67 | effect = "Allow"
68 | resources = [var.elb_logging_bucket_resource_arn]
69 | actions = ["s3:PutObject"]
70 |
71 | principals {
72 | type = "Service"
73 | identifiers = ["logdelivery.elasticloadbalancing.amazonaws.com"]
74 | }
75 | }
76 | }
77 |
--------------------------------------------------------------------------------
/examples/complete/context.tf:
--------------------------------------------------------------------------------
1 | #
2 | # ONLY EDIT THIS FILE IN github.com/cloudposse/terraform-null-label
3 | # All other instances of this file should be a copy of that one
4 | #
5 | #
6 | # Copy this file from https://github.com/cloudposse/terraform-null-label/blob/master/exports/context.tf
7 | # and then place it in your Terraform module to automatically get
8 | # Cloud Posse's standard configuration inputs suitable for passing
9 | # to Cloud Posse modules.
10 | #
11 | # curl -sL https://raw.githubusercontent.com/cloudposse/terraform-null-label/master/exports/context.tf -o context.tf
12 | #
13 | # Modules should access the whole context as `module.this.context`
14 | # to get the input variables with nulls for defaults,
15 | # for example `context = module.this.context`,
16 | # and access individual variables as `module.this.`,
17 | # with final values filled in.
18 | #
19 | # For example, when using defaults, `module.this.context.delimiter`
20 | # will be null, and `module.this.delimiter` will be `-` (hyphen).
21 | #
22 |
23 | module "this" {
24 | source = "cloudposse/label/null"
25 | version = "0.25.0" # requires Terraform >= 0.13.0
26 |
27 | enabled = var.enabled
28 | namespace = var.namespace
29 | tenant = var.tenant
30 | environment = var.environment
31 | stage = var.stage
32 | name = var.name
33 | delimiter = var.delimiter
34 | attributes = var.attributes
35 | tags = var.tags
36 | additional_tag_map = var.additional_tag_map
37 | label_order = var.label_order
38 | regex_replace_chars = var.regex_replace_chars
39 | id_length_limit = var.id_length_limit
40 | label_key_case = var.label_key_case
41 | label_value_case = var.label_value_case
42 | descriptor_formats = var.descriptor_formats
43 | labels_as_tags = var.labels_as_tags
44 |
45 | context = var.context
46 | }
47 |
48 | # Copy contents of cloudposse/terraform-null-label/variables.tf here
49 |
50 | variable "context" {
51 | type = any
52 | default = {
53 | enabled = true
54 | namespace = null
55 | tenant = null
56 | environment = null
57 | stage = null
58 | name = null
59 | delimiter = null
60 | attributes = []
61 | tags = {}
62 | additional_tag_map = {}
63 | regex_replace_chars = null
64 | label_order = []
65 | id_length_limit = null
66 | label_key_case = null
67 | label_value_case = null
68 | descriptor_formats = {}
69 | # Note: we have to use [] instead of null for unset lists due to
70 | # https://github.com/hashicorp/terraform/issues/28137
71 | # which was not fixed until Terraform 1.0.0,
72 | # but we want the default to be all the labels in `label_order`
73 | # and we want users to be able to prevent all tag generation
74 | # by setting `labels_as_tags` to `[]`, so we need
75 | # a different sentinel to indicate "default"
76 | labels_as_tags = ["unset"]
77 | }
78 | description = <<-EOT
79 | Single object for setting entire context at once.
80 | See description of individual variables for details.
81 | Leave string and numeric variables as `null` to use default value.
82 | Individual variable settings (non-null) override settings in context object,
83 | except for attributes, tags, and additional_tag_map, which are merged.
84 | EOT
85 |
86 | validation {
87 | condition = lookup(var.context, "label_key_case", null) == null ? true : contains(["lower", "title", "upper"], var.context["label_key_case"])
88 | error_message = "Allowed values: `lower`, `title`, `upper`."
89 | }
90 |
91 | validation {
92 | condition = lookup(var.context, "label_value_case", null) == null ? true : contains(["lower", "title", "upper", "none"], var.context["label_value_case"])
93 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
94 | }
95 | }
96 |
97 | variable "enabled" {
98 | type = bool
99 | default = null
100 | description = "Set to false to prevent the module from creating any resources"
101 | }
102 |
103 | variable "namespace" {
104 | type = string
105 | default = null
106 | description = "ID element. Usually an abbreviation of your organization name, e.g. 'eg' or 'cp', to help ensure generated IDs are globally unique"
107 | }
108 |
109 | variable "tenant" {
110 | type = string
111 | default = null
112 | description = "ID element _(Rarely used, not included by default)_. A customer identifier, indicating who this instance of a resource is for"
113 | }
114 |
115 | variable "environment" {
116 | type = string
117 | default = null
118 | description = "ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT'"
119 | }
120 |
121 | variable "stage" {
122 | type = string
123 | default = null
124 | description = "ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release'"
125 | }
126 |
127 | variable "name" {
128 | type = string
129 | default = null
130 | description = <<-EOT
131 | ID element. Usually the component or solution name, e.g. 'app' or 'jenkins'.
132 | This is the only ID element not also included as a `tag`.
133 | The "name" tag is set to the full `id` string. There is no tag with the value of the `name` input.
134 | EOT
135 | }
136 |
137 | variable "delimiter" {
138 | type = string
139 | default = null
140 | description = <<-EOT
141 | Delimiter to be used between ID elements.
142 | Defaults to `-` (hyphen). Set to `""` to use no delimiter at all.
143 | EOT
144 | }
145 |
146 | variable "attributes" {
147 | type = list(string)
148 | default = []
149 | description = <<-EOT
150 | ID element. Additional attributes (e.g. `workers` or `cluster`) to add to `id`,
151 | in the order they appear in the list. New attributes are appended to the
152 | end of the list. The elements of the list are joined by the `delimiter`
153 | and treated as a single ID element.
154 | EOT
155 | }
156 |
157 | variable "labels_as_tags" {
158 | type = set(string)
159 | default = ["default"]
160 | description = <<-EOT
161 | Set of labels (ID elements) to include as tags in the `tags` output.
162 | Default is to include all labels.
163 | Tags with empty values will not be included in the `tags` output.
164 | Set to `[]` to suppress all generated tags.
165 | **Notes:**
166 | The value of the `name` tag, if included, will be the `id`, not the `name`.
167 | Unlike other `null-label` inputs, the initial setting of `labels_as_tags` cannot be
168 | changed in later chained modules. Attempts to change it will be silently ignored.
169 | EOT
170 | }
171 |
172 | variable "tags" {
173 | type = map(string)
174 | default = {}
175 | description = <<-EOT
176 | Additional tags (e.g. `{'BusinessUnit': 'XYZ'}`).
177 | Neither the tag keys nor the tag values will be modified by this module.
178 | EOT
179 | }
180 |
181 | variable "additional_tag_map" {
182 | type = map(string)
183 | default = {}
184 | description = <<-EOT
185 | Additional key-value pairs to add to each map in `tags_as_list_of_maps`. Not added to `tags` or `id`.
186 | This is for some rare cases where resources want additional configuration of tags
187 | and therefore take a list of maps with tag key, value, and additional configuration.
188 | EOT
189 | }
190 |
191 | variable "label_order" {
192 | type = list(string)
193 | default = null
194 | description = <<-EOT
195 | The order in which the labels (ID elements) appear in the `id`.
196 | Defaults to ["namespace", "environment", "stage", "name", "attributes"].
197 | You can omit any of the 6 labels ("tenant" is the 6th), but at least one must be present.
198 | EOT
199 | }
200 |
201 | variable "regex_replace_chars" {
202 | type = string
203 | default = null
204 | description = <<-EOT
205 | Terraform regular expression (regex) string.
206 | Characters matching the regex will be removed from the ID elements.
207 | If not set, `"/[^a-zA-Z0-9-]/"` is used to remove all characters other than hyphens, letters and digits.
208 | EOT
209 | }
210 |
211 | variable "id_length_limit" {
212 | type = number
213 | default = null
214 | description = <<-EOT
215 | Limit `id` to this many characters (minimum 6).
216 | Set to `0` for unlimited length.
217 | Set to `null` for keep the existing setting, which defaults to `0`.
218 | Does not affect `id_full`.
219 | EOT
220 | validation {
221 | condition = var.id_length_limit == null ? true : var.id_length_limit >= 6 || var.id_length_limit == 0
222 | error_message = "The id_length_limit must be >= 6 if supplied (not null), or 0 for unlimited length."
223 | }
224 | }
225 |
226 | variable "label_key_case" {
227 | type = string
228 | default = null
229 | description = <<-EOT
230 | Controls the letter case of the `tags` keys (label names) for tags generated by this module.
231 | Does not affect keys of tags passed in via the `tags` input.
232 | Possible values: `lower`, `title`, `upper`.
233 | Default value: `title`.
234 | EOT
235 |
236 | validation {
237 | condition = var.label_key_case == null ? true : contains(["lower", "title", "upper"], var.label_key_case)
238 | error_message = "Allowed values: `lower`, `title`, `upper`."
239 | }
240 | }
241 |
242 | variable "label_value_case" {
243 | type = string
244 | default = null
245 | description = <<-EOT
246 | Controls the letter case of ID elements (labels) as included in `id`,
247 | set as tag values, and output by this module individually.
248 | Does not affect values of tags passed in via the `tags` input.
249 | Possible values: `lower`, `title`, `upper` and `none` (no transformation).
250 | Set this to `title` and set `delimiter` to `""` to yield Pascal Case IDs.
251 | Default value: `lower`.
252 | EOT
253 |
254 | validation {
255 | condition = var.label_value_case == null ? true : contains(["lower", "title", "upper", "none"], var.label_value_case)
256 | error_message = "Allowed values: `lower`, `title`, `upper`, `none`."
257 | }
258 | }
259 |
260 | variable "descriptor_formats" {
261 | type = any
262 | default = {}
263 | description = <<-EOT
264 | Describe additional descriptors to be output in the `descriptors` output map.
265 | Map of maps. Keys are names of descriptors. Values are maps of the form
266 | `{
267 | format = string
268 | labels = list(string)
269 | }`
270 | (Type is `any` so the map values can later be enhanced to provide additional options.)
271 | `format` is a Terraform format string to be passed to the `format()` function.
272 | `labels` is a list of labels, in order, to pass to `format()` function.
273 | Label values will be normalized before being passed to `format()` so they will be
274 | identical to how they appear in `id`.
275 | Default is `{}` (`descriptors` output will be empty).
276 | EOT
277 | }
278 |
279 | #### End of copy of cloudposse/terraform-null-label/variables.tf
280 |
--------------------------------------------------------------------------------
/examples/complete/fixtures.us-east-2.tfvars:
--------------------------------------------------------------------------------
1 | region = "us-east-2"
2 |
3 | namespace = "eg"
4 |
5 | environment = "ue2"
6 |
7 | stage = "test"
8 |
9 | name = "aws-utils"
10 |
11 |
--------------------------------------------------------------------------------
/examples/complete/main.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | region = var.region
3 | }
4 |
5 | data "aws_caller_identity" "current" {}
6 |
7 | module "s3_bucket" {
8 | source = "cloudposse/s3-bucket/aws"
9 | version = "3.1.3"
10 |
11 | context = module.this.context
12 | }
13 |
14 | module "example" {
15 | source = "../.."
16 |
17 | elb_logging_bucket_resource_arn = "${module.s3_bucket.bucket_arn}/prefix/AWSLogs/${data.aws_caller_identity.current.account_id}/*}"
18 | elb_logging_region = var.region
19 |
20 | context = module.this.context
21 | }
22 |
23 | locals {
24 | code_maps = module.example.region_az_alt_code_maps
25 |
26 | identity_size = length(local.code_maps.identity)
27 | to_short_size = length(local.code_maps.to_short)
28 | to_fixed_size = length(local.code_maps.to_fixed)
29 | from_fixed_size = length(local.code_maps.from_fixed)
30 | from_short_size = length(local.code_maps.from_short)
31 |
32 | # The Display Name map is generated from another source,
33 | # so we can check that all of its keys are in
34 | # one of the maps, which should ensure they are in all of the maps.
35 | # This should fail with a runtime error if a key is missing.
36 | ux_check = [for k, v in module.example.region_display_name_map : local.code_maps.to_short[k]]
37 | }
38 |
39 | resource "aws_s3_bucket_policy" "allow_access_logging" {
40 | count = module.this.enabled ? 1 : 0
41 |
42 | bucket = module.s3_bucket.bucket_id
43 | policy = module.example.elb_logging_s3_bucket_policy_json
44 | }
45 |
--------------------------------------------------------------------------------
/examples/complete/outputs.tf:
--------------------------------------------------------------------------------
1 | output "region" {
2 | description = "Configured region"
3 | value = var.region
4 | }
5 |
6 | output "fixed" {
7 | description = "Configured region mapped to fixed code"
8 | value = local.code_maps.to_fixed[var.region]
9 | }
10 |
11 | output "short" {
12 | description = "Configured region mapped to short code"
13 | value = local.code_maps.to_short[var.region]
14 | }
15 |
16 | output "identity_size" {
17 | description = "Size of identity map"
18 | value = local.identity_size
19 | }
20 |
21 | output "to_short_size" {
22 | description = "Size of to_short map"
23 | value = local.to_short_size
24 | }
25 |
26 | output "to_fixed_size" {
27 | description = "Size of to_fixed map"
28 | value = local.to_fixed_size
29 | }
30 |
31 | output "from_short_size" {
32 | description = "Size of from_short map"
33 | value = local.from_short_size
34 | }
35 |
36 | output "from_fixed_size" {
37 | description = "Size of from_fixed map"
38 | value = local.from_fixed_size
39 | }
40 |
41 | output "fixed_round_trip" {
42 | description = "Configured region mapped to fixed code and back"
43 | value = local.code_maps.from_fixed[local.code_maps.to_fixed[var.region]]
44 | }
45 |
46 | output "short_round_trip" {
47 | description = "Configured region mapped to short code"
48 | value = local.code_maps.from_short[local.code_maps.to_short[var.region]]
49 | }
50 |
51 | output "enabled_regions" {
52 | description = "A list of regions that are enabled in the account"
53 | value = module.example.enabled_regions
54 | }
55 |
56 | output "disabled_regions" {
57 | description = "A list of regions that are disabled in the account"
58 | value = module.example.disabled_regions
59 | }
60 |
61 | output "all_regions" {
62 | description = "A list of regions that are available to the account"
63 | value = module.example.all_regions
64 | }
65 |
66 | output "elb_logging_s3_bucket_policy_json" {
67 | description = <<-EOT
68 | The S3 bucket policy (in JSON) to attach to the S3 bucket to allow Load Balancer logs to be added.
69 | Requires `elb_logging_bucket_resource_arn` and `elb_logging_region` inputs.
70 | EOT
71 | value = module.example.elb_logging_s3_bucket_policy_json
72 | }
73 |
74 | output "region_az_alt_code_maps" {
75 | description = <<-EOT
76 | Collection of maps converting between official AWS Region, Availability Zone, and Local Zone codes and shorter unofficial codes using only lower case letters and digits. Inspired for use in naming and tagging so that region or AZ code will be 1 semantic unit.
77 |
78 | - `to_fixed` = Map of regions to 3-character codes and Availability Zones to 4-character codes
79 | - `to_short` = Map of regions and Availability Zones to compact (usually 4-6 characters) codes
80 | - `from_fixed` = Map of `fixed` codes back to full region or Availability Zone codes
81 | - `from_short` = Map of `short` codes back to full region or Availability Zone codes
82 | - `identity` = Identity map of full region and Availability Zone codes back to themselves
83 | EOT
84 | value = module.example.region_az_alt_code_maps
85 | }
86 |
87 | output "region_display_name_map" {
88 | description = <<-EOT
89 | Map of full region names to user-friendly display names (e.g. "eu-west-3" = "Europe (Paris)").
90 | EOT
91 | value = module.example.region_display_name_map
92 | }
93 |
--------------------------------------------------------------------------------
/examples/complete/variables.tf:
--------------------------------------------------------------------------------
1 | variable "region" {
2 | type = string
3 | description = "A test region"
4 | }
5 |
--------------------------------------------------------------------------------
/examples/complete/versions.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | # S3 bucket module requires at least Terraform v1.0
3 | required_version = ">= 1.0.0"
4 | }
5 |
--------------------------------------------------------------------------------
/main.tf:
--------------------------------------------------------------------------------
1 |
2 | locals {
3 | # Key can be a region, availability zone, or local zone.
4 | # Key CANNOT be an Availability Zone ID or Wavelength Zone.
5 | # Local zone keys may be incomplete.
6 | # WARNING: If a current local zone mapping conflicts with a future region mapping,
7 | # we may change the local zone mapping in order to keep the region mappings consistent.
8 | # This is particularly likely to happen with the "fixed" mappings, so we recommend using
9 | # the "short" mappings if you plan to use local zones.
10 | # For some degree of future proofing, we provide mappings for some AZs that do not yet exist.
11 | # INCLUSION IN THE MAP does NOT necessarily mean the region or AZ exists.
12 |
13 | # See https://github.com/jsonmaur/aws-regions for complete list of regions
14 |
15 | # to_display_name maps full region names to geographic display names
16 | # using https://github.com/aws/aws-sdk-java/blob/master/aws-java-sdk-core/src/main/resources/com/amazonaws/partitions/endpoints.json
17 | # as a reference source, since there is appears to be no API available.
18 | # Note that https://docs.aws.amazon.com/AWSEC2/latest/UserGuide/using-regions-availability-zones.html
19 | # claims you can get display names from `aws lightsail`, but Lightsail is not available in
20 | # all regions, so its list is incomplete.
21 | #
22 | # The map contents can be regenerated (will need to be reformatted with `terraform fmt`) with:
23 | # curl -sSL https://raw.githubusercontent.com/aws/aws-sdk-java/master/aws-java-sdk-core/src/main/resources/com/amazonaws/partitions/endpoints.json \
24 | # | jq -r '.partitions[] |select( .partition | test("aws(-cn|-us-gov)?$") ) | .regions | to_entries |.[] | "\"\(.key)\" = \"\(.value.description)\""'
25 |
26 |
27 | to_display_name = {
28 | "af-south-1" = "Africa (Cape Town)"
29 | "ap-east-1" = "Asia Pacific (Hong Kong)"
30 | "ap-northeast-1" = "Asia Pacific (Tokyo)"
31 | "ap-northeast-2" = "Asia Pacific (Seoul)"
32 | "ap-northeast-3" = "Asia Pacific (Osaka)"
33 | "ap-south-1" = "Asia Pacific (Mumbai)"
34 | "ap-south-2" = "Asia Pacific (Hyderabad)"
35 | "ap-southeast-1" = "Asia Pacific (Singapore)"
36 | "ap-southeast-2" = "Asia Pacific (Sydney)"
37 | "ap-southeast-3" = "Asia Pacific (Jakarta)"
38 | "ap-southeast-4" = "Asia Pacific (Melbourne)"
39 | "ca-central-1" = "Canada (Central)"
40 | "ca-west-1" = "Canada West (Calgary)"
41 | "eu-central-1" = "Europe (Frankfurt)"
42 | "eu-central-2" = "Europe (Zurich)"
43 | "eu-north-1" = "Europe (Stockholm)"
44 | "eu-south-1" = "Europe (Milan)"
45 | "eu-south-2" = "Europe (Milan)"
46 | "eu-west-1" = "Europe (Ireland)"
47 | "eu-west-2" = "Europe (London)"
48 | "eu-west-3" = "Europe (Paris)"
49 | "il-central-1" = "Israel (Tel Aviv)"
50 | "me-central-1" = "Middle East (UAE)"
51 | "me-south-1" = "Middle East (Bahrain)"
52 | "sa-east-1" = "South America (Sao Paulo)"
53 | "us-east-1" = "US East (N. Virginia)"
54 | "us-east-2" = "US East (Ohio)"
55 | "us-west-1" = "US West (N. California)"
56 | "us-west-2" = "US West (Oregon)"
57 | "cn-north-1" = "China (Beijing)"
58 | "cn-northwest-1" = "China (Ningxia)"
59 | "us-gov-east-1" = "AWS GovCloud (US-East)"
60 | "us-gov-west-1" = "AWS GovCloud (US-West)"
61 | }
62 |
63 | to_fixed = {
64 | "ap-east-1" = "ae1"
65 | "ap-east-1a" = "ae1a"
66 | "ap-east-1b" = "ae1b"
67 | "ap-east-1c" = "ae1c"
68 | "ap-east-1d" = "ae1d"
69 | "ap-east-1e" = "ae1e"
70 | "ap-east-1f" = "ae1f"
71 | "ap-east-1g" = "ae1g"
72 | "ap-east-1h" = "ae1h"
73 |
74 | "ap-northeast-1" = "an1"
75 | "ap-northeast-1a" = "an1a"
76 | "ap-northeast-1b" = "an1b"
77 | "ap-northeast-1c" = "an1c"
78 | "ap-northeast-1d" = "an1d"
79 | "ap-northeast-1e" = "an1e"
80 | "ap-northeast-1f" = "an1f"
81 | "ap-northeast-1g" = "an1g"
82 | "ap-northeast-1h" = "an1h"
83 |
84 | "ap-northeast-2" = "an2"
85 | "ap-northeast-2a" = "an2a"
86 | "ap-northeast-2b" = "an2b"
87 | "ap-northeast-2c" = "an2c"
88 | "ap-northeast-2d" = "an2d"
89 | "ap-northeast-2e" = "an2e"
90 | "ap-northeast-2f" = "an2f"
91 | "ap-northeast-2g" = "an2g"
92 | "ap-northeast-2h" = "an2h"
93 |
94 | "ap-northeast-3" = "an3"
95 | "ap-northeast-3a" = "an3a"
96 | "ap-northeast-3b" = "an3b"
97 | "ap-northeast-3c" = "an3c"
98 | "ap-northeast-3d" = "an3d"
99 | "ap-northeast-3e" = "an3e"
100 | "ap-northeast-3f" = "an3f"
101 | "ap-northeast-3g" = "an3g"
102 | "ap-northeast-3h" = "an3h"
103 |
104 | # Abbreviation for ap-south-1 would be "as1" but that is already used for ap-southeast-1
105 | # So we use "as0" for ap-south-1
106 | "ap-south-1" = "as0"
107 | "ap-south-1a" = "as0a"
108 | "ap-south-1b" = "as0b"
109 | "ap-south-1c" = "as0c"
110 | "ap-south-1d" = "as0d"
111 | "ap-south-1e" = "as0e"
112 | "ap-south-1f" = "as0f"
113 | "ap-south-1g" = "as0g"
114 | "ap-south-1h" = "as0h"
115 |
116 | # Abbreviation for ap-south-2 would be "as2" but that is already used for ap-southeast-2
117 | # Using a different number as we did for ap-south-1 in not as extensible as using a different letter,
118 | # which allows us to leaves the region number consistent.
119 | # So we use "ar2" (r is letter before s) for ap-south-2
120 | "ap-south-2" = "ar2"
121 | "ap-south-2a" = "ar2a"
122 | "ap-south-2b" = "ar2b"
123 | "ap-south-2c" = "ar2c"
124 | "ap-south-2d" = "ar2d"
125 | "ap-south-2e" = "ar2e"
126 | "ap-south-2f" = "ar2f"
127 | "ap-south-2g" = "ar2g"
128 | "ap-south-2h" = "ar2h"
129 |
130 | "ap-southeast-1" = "as1"
131 | "ap-southeast-1a" = "as1a"
132 | "ap-southeast-1b" = "as1b"
133 | "ap-southeast-1c" = "as1c"
134 | "ap-southeast-1d" = "as1d"
135 | "ap-southeast-1e" = "as1e"
136 | "ap-southeast-1f" = "as1f"
137 | "ap-southeast-1g" = "as1g"
138 | "ap-southeast-1h" = "as1h"
139 |
140 | "ap-southeast-2" = "as2"
141 | "ap-southeast-2a" = "as2a"
142 | "ap-southeast-2b" = "as2b"
143 | "ap-southeast-2c" = "as2c"
144 | "ap-southeast-2d" = "as2d"
145 | "ap-southeast-2e" = "as2e"
146 | "ap-southeast-2f" = "as2f"
147 | "ap-southeast-2g" = "as2g"
148 | "ap-southeast-2h" = "as2h"
149 |
150 | "ap-southeast-3" = "as3"
151 | "ap-southeast-3a" = "as3a"
152 | "ap-southeast-3b" = "as3b"
153 | "ap-southeast-3c" = "as3c"
154 | "ap-southeast-3d" = "as3d"
155 | "ap-southeast-3e" = "as3e"
156 | "ap-southeast-3f" = "as3f"
157 | "ap-southeast-3g" = "as3g"
158 | "ap-southeast-3h" = "as3h"
159 |
160 | "ap-southeast-4" = "as4"
161 | "ap-southeast-4a" = "as4a"
162 | "ap-southeast-4b" = "as4b"
163 | "ap-southeast-4c" = "as4c"
164 | "ap-southeast-4d" = "as4d"
165 | "ap-southeast-4e" = "as4e"
166 | "ap-southeast-4f" = "as4f"
167 | "ap-southeast-4g" = "as4g"
168 | "ap-southeast-4h" = "as4h"
169 |
170 | "ca-central-1" = "cc1"
171 | "ca-central-1a" = "cc1a"
172 | "ca-central-1b" = "cc1b"
173 | "ca-central-1c" = "cc1c"
174 | "ca-central-1d" = "cc1d"
175 | "ca-central-1e" = "cc1e"
176 | "ca-central-1f" = "cc1f"
177 | "ca-central-1g" = "cc1g"
178 | "ca-central-1h" = "cc1h"
179 |
180 | "ca-west-1" = "cw1"
181 | "ca-west-1a" = "cw1a"
182 | "ca-west-1b" = "cw1b"
183 | "ca-west-1c" = "cw1c"
184 |
185 | "eu-central-1" = "ec1"
186 | "eu-central-1a" = "ec1a"
187 | "eu-central-1b" = "ec1b"
188 | "eu-central-1c" = "ec1c"
189 | "eu-central-1d" = "ec1d"
190 | "eu-central-1e" = "ec1e"
191 | "eu-central-1f" = "ec1f"
192 | "eu-central-1g" = "ec1g"
193 | "eu-central-1h" = "ec1h"
194 |
195 | "eu-central-2" = "ec2"
196 | "eu-central-2a" = "ec2a"
197 | "eu-central-2b" = "ec2b"
198 | "eu-central-2c" = "ec2c"
199 | "eu-central-2d" = "ec2d"
200 | "eu-central-2e" = "ec2e"
201 | "eu-central-2f" = "ec2f"
202 | "eu-central-2g" = "ec2g"
203 | "eu-central-2h" = "ec2h"
204 |
205 | "eu-north-1" = "en1"
206 | "eu-north-1a" = "en1a"
207 | "eu-north-1b" = "en1b"
208 | "eu-north-1c" = "en1c"
209 | "eu-north-1d" = "en1d"
210 | "eu-north-1e" = "en1e"
211 | "eu-north-1f" = "en1f"
212 | "eu-north-1g" = "en1g"
213 | "eu-north-1h" = "en1h"
214 |
215 | "eu-south-1" = "es1"
216 | "eu-south-1a" = "es1a"
217 | "eu-south-1b" = "es1b"
218 | "eu-south-1c" = "es1c"
219 | "eu-south-1d" = "es1d"
220 | "eu-south-1e" = "es1e"
221 | "eu-south-1f" = "es1f"
222 | "eu-south-1g" = "es1g"
223 | "eu-south-1h" = "es1h"
224 |
225 | "eu-south-2" = "es2"
226 | "eu-south-2a" = "es2a"
227 | "eu-south-2b" = "es2b"
228 | "eu-south-2c" = "es2c"
229 | "eu-south-2d" = "es2d"
230 | "eu-south-2e" = "es2e"
231 | "eu-south-2f" = "es2f"
232 | "eu-south-2g" = "es2g"
233 | "eu-south-2h" = "es2h"
234 |
235 | "eu-west-1" = "ew1"
236 | "eu-west-1a" = "ew1a"
237 | "eu-west-1b" = "ew1b"
238 | "eu-west-1c" = "ew1c"
239 | "eu-west-1d" = "ew1d"
240 | "eu-west-1e" = "ew1e"
241 | "eu-west-1f" = "ew1f"
242 | "eu-west-1g" = "ew1g"
243 | "eu-west-1h" = "ew1h"
244 |
245 | "eu-west-2" = "ew2"
246 | "eu-west-2a" = "ew2a"
247 | "eu-west-2b" = "ew2b"
248 | "eu-west-2c" = "ew2c"
249 | "eu-west-2d" = "ew2d"
250 | "eu-west-2e" = "ew2e"
251 | "eu-west-2f" = "ew2f"
252 | "eu-west-2g" = "ew2g"
253 | "eu-west-2h" = "ew2h"
254 |
255 | "eu-west-3" = "ew3"
256 | "eu-west-3a" = "ew3a"
257 | "eu-west-3b" = "ew3b"
258 | "eu-west-3c" = "ew3c"
259 | "eu-west-3d" = "ew3d"
260 | "eu-west-3e" = "ew3e"
261 | "eu-west-3f" = "ew3f"
262 | "eu-west-3g" = "ew3g"
263 | "eu-west-3h" = "ew3h"
264 |
265 | "af-south-1" = "fs1"
266 | "af-south-1a" = "fs1a"
267 | "af-south-1b" = "fs1b"
268 | "af-south-1c" = "fs1c"
269 | "af-south-1d" = "fs1d"
270 | "af-south-1e" = "fs1e"
271 | "af-south-1f" = "fs1f"
272 | "af-south-1g" = "fs1g"
273 | "af-south-1h" = "fs1h"
274 |
275 | "us-gov-east-1" = "ge1"
276 | "us-gov-east-1a" = "ge1a"
277 | "us-gov-east-1b" = "ge1b"
278 | "us-gov-east-1c" = "ge1c"
279 | "us-gov-east-1d" = "ge1d"
280 | "us-gov-east-1e" = "ge1e"
281 | "us-gov-east-1f" = "ge1f"
282 | "us-gov-east-1g" = "ge1g"
283 | "us-gov-east-1h" = "ge1h"
284 |
285 | "us-gov-west-1" = "gw1"
286 | "us-gov-west-1a" = "gw1a"
287 | "us-gov-west-1b" = "gw1b"
288 | "us-gov-west-1c" = "gw1c"
289 | "us-gov-west-1d" = "gw1d"
290 | "us-gov-west-1e" = "gw1e"
291 | "us-gov-west-1f" = "gw1f"
292 | "us-gov-west-1g" = "gw1g"
293 | "us-gov-west-1h" = "gw1h"
294 |
295 | "il-central-1" = "ic1"
296 | "il-central-1a" = "ic1a"
297 | "il-central-1b" = "ic1b"
298 | "il-central-1c" = "ic1c"
299 |
300 | "me-central-1" = "mc1"
301 | "me-central-1a" = "mc1a"
302 | "me-central-1b" = "mc1b"
303 | "me-central-1c" = "mc1c"
304 | "me-central-1d" = "mc1d"
305 | "me-central-1e" = "mc1e"
306 | "me-central-1f" = "mc1f"
307 | "me-central-1g" = "mc1g"
308 | "me-central-1h" = "mc1h"
309 |
310 | "me-south-1" = "ms1"
311 | "me-south-1a" = "ms1a"
312 | "me-south-1b" = "ms1b"
313 | "me-south-1c" = "ms1c"
314 | "me-south-1d" = "ms1d"
315 | "me-south-1e" = "ms1e"
316 | "me-south-1f" = "ms1f"
317 | "me-south-1g" = "ms1g"
318 | "me-south-1h" = "ms1h"
319 |
320 | "cn-north-1" = "nn0"
321 | "cn-north-1a" = "nn0a"
322 | "cn-north-1b" = "nn0b"
323 | "cn-north-1c" = "nn0c"
324 | "cn-north-1d" = "nn0d"
325 | "cn-north-1e" = "nn0e"
326 | "cn-north-1f" = "nn0f"
327 | "cn-north-1g" = "nn0g"
328 | "cn-north-1h" = "nn0h"
329 |
330 | "cn-northwest-1" = "nn1"
331 | "cn-northwest-1a" = "nn1a"
332 | "cn-northwest-1b" = "nn1b"
333 | "cn-northwest-1c" = "nn1c"
334 | "cn-northwest-1d" = "nn1d"
335 | "cn-northwest-1e" = "nn1e"
336 | "cn-northwest-1f" = "nn1f"
337 | "cn-northwest-1g" = "nn1g"
338 | "cn-northwest-1h" = "nn1h"
339 |
340 | "sa-east-1" = "se1"
341 | "sa-east-1a" = "se1a"
342 | "sa-east-1b" = "se1b"
343 | "sa-east-1c" = "se1c"
344 | "sa-east-1d" = "se1d"
345 | "sa-east-1e" = "se1e"
346 | "sa-east-1f" = "se1f"
347 | "sa-east-1g" = "se1g"
348 | "sa-east-1h" = "se1h"
349 |
350 | "us-east-1" = "ue1"
351 | "us-east-1a" = "ue1a"
352 | "us-east-1b" = "ue1b"
353 | "us-east-1c" = "ue1c"
354 | "us-east-1d" = "ue1d"
355 | "us-east-1e" = "ue1e"
356 | "us-east-1f" = "ue1f"
357 | "us-east-1g" = "ue1g"
358 | "us-east-1h" = "ue1h"
359 |
360 | "us-east-1-atl-1" = "at1"
361 | "us-east-1-atl-1a" = "at1a"
362 | "us-east-1-bos-1" = "bo1"
363 | "us-east-1-bos-1a" = "bo1a"
364 | "us-east-1-chi-1" = "ch1"
365 | "us-east-1-chi-1a" = "ch1a"
366 | "us-east-1-dfw-1" = "df1"
367 | "us-east-1-dfw-1a" = "df1a"
368 | "us-east-1-iah-1" = "ia1"
369 | "us-east-1-iah-1a" = "ia1a"
370 | # Cannot use mc for mci, taken by me-central
371 | # Want to avoid second letter "c" as it may be a future "central"
372 | "us-east-1-mci-1" = "ks1"
373 | "us-east-1-mci-1a" = "ks1a"
374 | "us-east-1-mia-1" = "mi1"
375 | "us-east-1-mia-1a" = "mi1a"
376 | # Want to avoid second letter "s" as it may be a future "south"
377 | "us-east-1-msp-1" = "mn1"
378 | "us-east-1-msp-1a" = "mn1a"
379 | "us-east-1-nyc-1" = "ny1"
380 | "us-east-1-nyc-1a" = "ny1a"
381 | # Use pl for phl to avoid clash with phx
382 | "us-east-1-phl-1" = "pl1"
383 | "us-east-1-phl-1a" = "pl1a"
384 |
385 | "us-east-2" = "ue2"
386 | "us-east-2a" = "ue2a"
387 | "us-east-2b" = "ue2b"
388 | "us-east-2c" = "ue2c"
389 | "us-east-2d" = "ue2d"
390 | "us-east-2e" = "ue2e"
391 | "us-east-2f" = "ue2f"
392 | "us-east-2g" = "ue2g"
393 | "us-east-2h" = "ue2h"
394 |
395 | "us-west-1" = "uw1"
396 | "us-west-1a" = "uw1a"
397 | "us-west-1b" = "uw1b"
398 | "us-west-1c" = "uw1c"
399 | "us-west-1d" = "uw1d"
400 | "us-west-1e" = "uw1e"
401 | "us-west-1f" = "uw1f"
402 | "us-west-1g" = "uw1g"
403 | "us-west-1h" = "uw1h"
404 |
405 | "us-west-2" = "uw2"
406 | "us-west-2a" = "uw2a"
407 | "us-west-2b" = "uw2b"
408 | "us-west-2c" = "uw2c"
409 | "us-west-2d" = "uw2d"
410 | "us-west-2e" = "uw2e"
411 | "us-west-2f" = "uw2f"
412 | "us-west-2g" = "uw2g"
413 | "us-west-2h" = "uw2h"
414 |
415 | # Want to avoid second letter "e" or "n" in case of future "east" or "north"
416 | "us-west-2-den-1" = "dv1"
417 | "us-west-2-den-1a" = "dv1a"
418 | # use lv for Las Vegas and lx for Los Angeles (LAX) to reduce confusion
419 | "us-west-2-las-1" = "lv1"
420 | "us-west-2-las-1a" = "lv1a"
421 | "us-west-2-lax-1" = "lx1"
422 | "us-west-2-lax-1a" = "lx1a"
423 | "us-west-2-lax-1b" = "lx1b"
424 | "us-west-2-pdx-1" = "pd1"
425 | "us-west-2-pdx-1a" = "pd1a"
426 | # Use px for phl to avoid clash with phl
427 | "us-west-2-phx-1" = "px1"
428 | "us-west-2-phx-1a" = "px1a"
429 | # Cannot use se for sea, taken by sa-east
430 | "us-west-2-sea-1" = "st1"
431 | "us-west-2-sea-1a" = "st1a"
432 | }
433 |
434 | to_short = {
435 | "ap-east-1" = "ape1"
436 | "ap-east-1a" = "ape1a"
437 | "ap-east-1b" = "ape1b"
438 | "ap-east-1c" = "ape1c"
439 | "ap-east-1d" = "ape1d"
440 | "ap-east-1e" = "ape1e"
441 | "ap-east-1f" = "ape1f"
442 | "ap-east-1g" = "ape1g"
443 | "ap-east-1h" = "ape1h"
444 |
445 | "ap-northeast-1" = "apne1"
446 | "ap-northeast-1a" = "apne1a"
447 | "ap-northeast-1b" = "apne1b"
448 | "ap-northeast-1c" = "apne1c"
449 | "ap-northeast-1d" = "apne1d"
450 | "ap-northeast-1e" = "apne1e"
451 | "ap-northeast-1f" = "apne1f"
452 | "ap-northeast-1g" = "apne1g"
453 | "ap-northeast-1h" = "apne1h"
454 |
455 | "ap-northeast-2" = "apne2"
456 | "ap-northeast-2a" = "apne2a"
457 | "ap-northeast-2b" = "apne2b"
458 | "ap-northeast-2c" = "apne2c"
459 | "ap-northeast-2d" = "apne2d"
460 | "ap-northeast-2e" = "apne2e"
461 | "ap-northeast-2f" = "apne2f"
462 | "ap-northeast-2g" = "apne2g"
463 | "ap-northeast-2h" = "apne2h"
464 |
465 | "ap-northeast-3" = "apne3"
466 | "ap-northeast-3a" = "apne3a"
467 | "ap-northeast-3b" = "apne3b"
468 | "ap-northeast-3c" = "apne3c"
469 | "ap-northeast-3d" = "apne3d"
470 | "ap-northeast-3e" = "apne3e"
471 | "ap-northeast-3f" = "apne3f"
472 | "ap-northeast-3g" = "apne3g"
473 | "ap-northeast-3h" = "apne3h"
474 |
475 | "ap-south-1" = "aps1"
476 | "ap-south-1a" = "aps1a"
477 | "ap-south-1b" = "aps1b"
478 | "ap-south-1c" = "aps1c"
479 | "ap-south-1d" = "aps1d"
480 | "ap-south-1e" = "aps1e"
481 | "ap-south-1f" = "aps1f"
482 | "ap-south-1g" = "aps1g"
483 | "ap-south-1h" = "aps1h"
484 |
485 | "ap-south-2" = "aps2"
486 | "ap-south-2a" = "aps2a"
487 | "ap-south-2b" = "aps2b"
488 | "ap-south-2c" = "aps2c"
489 | "ap-south-2d" = "aps2d"
490 | "ap-south-2e" = "aps2e"
491 | "ap-south-2f" = "aps2f"
492 | "ap-south-2g" = "aps2g"
493 | "ap-south-2h" = "aps2h"
494 |
495 | "ap-southeast-1" = "apse1"
496 | "ap-southeast-1a" = "apse1a"
497 | "ap-southeast-1b" = "apse1b"
498 | "ap-southeast-1c" = "apse1c"
499 | "ap-southeast-1d" = "apse1d"
500 | "ap-southeast-1e" = "apse1e"
501 | "ap-southeast-1f" = "apse1f"
502 | "ap-southeast-1g" = "apse1g"
503 | "ap-southeast-1h" = "apse1h"
504 |
505 | "ap-southeast-2" = "apse2"
506 | "ap-southeast-2a" = "apse2a"
507 | "ap-southeast-2b" = "apse2b"
508 | "ap-southeast-2c" = "apse2c"
509 | "ap-southeast-2d" = "apse2d"
510 | "ap-southeast-2e" = "apse2e"
511 | "ap-southeast-2f" = "apse2f"
512 | "ap-southeast-2g" = "apse2g"
513 | "ap-southeast-2h" = "apse2h"
514 |
515 | "ap-southeast-3" = "apse3"
516 | "ap-southeast-3a" = "apse3a"
517 | "ap-southeast-3b" = "apse3b"
518 | "ap-southeast-3c" = "apse3c"
519 | "ap-southeast-3d" = "apse3d"
520 | "ap-southeast-3e" = "apse3e"
521 | "ap-southeast-3f" = "apse3f"
522 | "ap-southeast-3g" = "apse3g"
523 | "ap-southeast-3h" = "apse3h"
524 |
525 | "ap-southeast-4" = "apse4"
526 | "ap-southeast-4a" = "apse4a"
527 | "ap-southeast-4b" = "apse4b"
528 | "ap-southeast-4c" = "apse4c"
529 | "ap-southeast-4d" = "apse4d"
530 | "ap-southeast-4e" = "apse4e"
531 | "ap-southeast-4f" = "apse4f"
532 | "ap-southeast-4g" = "apse4g"
533 | "ap-southeast-4h" = "apse4h"
534 |
535 | "ca-central-1" = "cac1"
536 | "ca-central-1a" = "cac1a"
537 | "ca-central-1b" = "cac1b"
538 | "ca-central-1c" = "cac1c"
539 | "ca-central-1d" = "cac1d"
540 | "ca-central-1e" = "cac1e"
541 | "ca-central-1f" = "cac1f"
542 | "ca-central-1g" = "cac1g"
543 | "ca-central-1h" = "cac1h"
544 |
545 | "ca-west-1" = "caw1"
546 | "ca-west-1a" = "caw1a"
547 | "ca-west-1b" = "caw1b"
548 | "ca-west-1c" = "caw1c"
549 |
550 | "eu-central-1" = "euc1"
551 | "eu-central-1a" = "euc1a"
552 | "eu-central-1b" = "euc1b"
553 | "eu-central-1c" = "euc1c"
554 | "eu-central-1d" = "euc1d"
555 | "eu-central-1e" = "euc1e"
556 | "eu-central-1f" = "euc1f"
557 | "eu-central-1g" = "euc1g"
558 | "eu-central-1h" = "euc1h"
559 |
560 | "eu-central-2" = "euc2"
561 | "eu-central-2a" = "euc2a"
562 | "eu-central-2b" = "euc2b"
563 | "eu-central-2c" = "euc2c"
564 | "eu-central-2d" = "euc2d"
565 | "eu-central-2e" = "euc2e"
566 | "eu-central-2f" = "euc2f"
567 | "eu-central-2g" = "euc2g"
568 | "eu-central-2h" = "euc2h"
569 |
570 | "eu-north-1" = "eun1"
571 | "eu-north-1a" = "eun1a"
572 | "eu-north-1b" = "eun1b"
573 | "eu-north-1c" = "eun1c"
574 | "eu-north-1d" = "eun1d"
575 | "eu-north-1e" = "eun1e"
576 | "eu-north-1f" = "eun1f"
577 | "eu-north-1g" = "eun1g"
578 | "eu-north-1h" = "eun1h"
579 |
580 | "eu-south-1" = "eus1"
581 | "eu-south-1a" = "eus1a"
582 | "eu-south-1b" = "eus1b"
583 | "eu-south-1c" = "eus1c"
584 | "eu-south-1d" = "eus1d"
585 | "eu-south-1e" = "eus1e"
586 | "eu-south-1f" = "eus1f"
587 | "eu-south-1g" = "eus1g"
588 | "eu-south-1h" = "eus1h"
589 |
590 | "eu-south-2" = "eus2"
591 | "eu-south-2a" = "eus2a"
592 | "eu-south-2b" = "eus2b"
593 | "eu-south-2c" = "eus2c"
594 | "eu-south-2d" = "eus2d"
595 | "eu-south-2e" = "eus2e"
596 | "eu-south-2f" = "eus2f"
597 | "eu-south-2g" = "eus2g"
598 | "eu-south-2h" = "eus2h"
599 |
600 | "eu-west-1" = "euw1"
601 | "eu-west-1a" = "euw1a"
602 | "eu-west-1b" = "euw1b"
603 | "eu-west-1c" = "euw1c"
604 | "eu-west-1d" = "euw1d"
605 | "eu-west-1e" = "euw1e"
606 | "eu-west-1f" = "euw1f"
607 | "eu-west-1g" = "euw1g"
608 | "eu-west-1h" = "euw1h"
609 |
610 | "eu-west-2" = "euw2"
611 | "eu-west-2a" = "euw2a"
612 | "eu-west-2b" = "euw2b"
613 | "eu-west-2c" = "euw2c"
614 | "eu-west-2d" = "euw2d"
615 | "eu-west-2e" = "euw2e"
616 | "eu-west-2f" = "euw2f"
617 | "eu-west-2g" = "euw2g"
618 | "eu-west-2h" = "euw2h"
619 |
620 | "eu-west-3" = "euw3"
621 | "eu-west-3a" = "euw3a"
622 | "eu-west-3b" = "euw3b"
623 | "eu-west-3c" = "euw3c"
624 | "eu-west-3d" = "euw3d"
625 | "eu-west-3e" = "euw3e"
626 | "eu-west-3f" = "euw3f"
627 | "eu-west-3g" = "euw3g"
628 | "eu-west-3h" = "euw3h"
629 |
630 | "af-south-1" = "afs1"
631 | "af-south-1a" = "afs1a"
632 | "af-south-1b" = "afs1b"
633 | "af-south-1c" = "afs1c"
634 | "af-south-1d" = "afs1d"
635 | "af-south-1e" = "afs1e"
636 | "af-south-1f" = "afs1f"
637 | "af-south-1g" = "afs1g"
638 | "af-south-1h" = "afs1h"
639 |
640 | "us-gov-east-1" = "usge1"
641 | "us-gov-east-1a" = "usge1a"
642 | "us-gov-east-1b" = "usge1b"
643 | "us-gov-east-1c" = "usge1c"
644 | "us-gov-east-1d" = "usge1d"
645 | "us-gov-east-1e" = "usge1e"
646 | "us-gov-east-1f" = "usge1f"
647 | "us-gov-east-1g" = "usge1g"
648 | "us-gov-east-1h" = "usge1h"
649 |
650 | "us-gov-west-1" = "usgw1"
651 | "us-gov-west-1a" = "usgw1a"
652 | "us-gov-west-1b" = "usgw1b"
653 | "us-gov-west-1c" = "usgw1c"
654 | "us-gov-west-1d" = "usgw1d"
655 | "us-gov-west-1e" = "usgw1e"
656 | "us-gov-west-1f" = "usgw1f"
657 | "us-gov-west-1g" = "usgw1g"
658 | "us-gov-west-1h" = "usgw1h"
659 |
660 | "il-central-1" = "ilc1"
661 | "il-central-1a" = "ilc1a"
662 | "il-central-1b" = "ilc1b"
663 | "il-central-1c" = "ilc1c"
664 |
665 | "me-central-1" = "mec1"
666 | "me-central-1a" = "mec1a"
667 | "me-central-1b" = "mec1b"
668 | "me-central-1c" = "mec1c"
669 | "me-central-1d" = "mec1d"
670 | "me-central-1e" = "mec1e"
671 | "me-central-1f" = "mec1f"
672 | "me-central-1g" = "mec1g"
673 | "me-central-1h" = "mec1h"
674 |
675 | "me-south-1" = "mes1"
676 | "me-south-1a" = "mes1a"
677 | "me-south-1b" = "mes1b"
678 | "me-south-1c" = "mes1c"
679 | "me-south-1d" = "mes1d"
680 | "me-south-1e" = "mes1e"
681 | "me-south-1f" = "mes1f"
682 | "me-south-1g" = "mes1g"
683 | "me-south-1h" = "mes1h"
684 |
685 | "cn-north-1" = "cnn1"
686 | "cn-north-1a" = "cnn1a"
687 | "cn-north-1b" = "cnn1b"
688 | "cn-north-1c" = "cnn1c"
689 | "cn-north-1d" = "cnn1d"
690 | "cn-north-1e" = "cnn1e"
691 | "cn-north-1f" = "cnn1f"
692 | "cn-north-1g" = "cnn1g"
693 | "cn-north-1h" = "cnn1h"
694 |
695 | "cn-northwest-1" = "cnnw1"
696 | "cn-northwest-1a" = "cnnw1a"
697 | "cn-northwest-1b" = "cnnw1b"
698 | "cn-northwest-1c" = "cnnw1c"
699 | "cn-northwest-1d" = "cnnw1d"
700 | "cn-northwest-1e" = "cnnw1e"
701 | "cn-northwest-1f" = "cnnw1f"
702 | "cn-northwest-1g" = "cnnw1g"
703 | "cn-northwest-1h" = "cnnw1h"
704 |
705 | "sa-east-1" = "sae1"
706 | "sa-east-1a" = "sae1a"
707 | "sa-east-1b" = "sae1b"
708 | "sa-east-1c" = "sae1c"
709 | "sa-east-1d" = "sae1d"
710 | "sa-east-1e" = "sae1e"
711 | "sa-east-1f" = "sae1f"
712 | "sa-east-1g" = "sae1g"
713 | "sa-east-1h" = "sae1h"
714 |
715 | "us-east-1" = "use1"
716 | "us-east-1a" = "use1a"
717 | "us-east-1b" = "use1b"
718 | "us-east-1c" = "use1c"
719 | "us-east-1d" = "use1d"
720 | "us-east-1e" = "use1e"
721 | "us-east-1f" = "use1f"
722 | "us-east-1g" = "use1g"
723 | "us-east-1h" = "use1h"
724 |
725 | "us-east-1-atl-1" = "atl1"
726 | "us-east-1-atl-1a" = "atl1a"
727 | "us-east-1-bos-1" = "bos1"
728 | "us-east-1-bos-1a" = "bos1a"
729 | "us-east-1-chi-1" = "chi1"
730 | "us-east-1-chi-1a" = "chi1a"
731 | "us-east-1-dfw-1" = "dfw1"
732 | "us-east-1-dfw-1a" = "dfw1a"
733 | "us-east-1-iah-1" = "iah1"
734 | "us-east-1-iah-1a" = "iah1a"
735 | "us-east-1-mci-1" = "mci1"
736 | "us-east-1-mci-1a" = "mci1a"
737 | "us-east-1-mia-1" = "mia1"
738 | "us-east-1-mia-1a" = "mia1a"
739 | "us-east-1-msp-1" = "msp1"
740 | "us-east-1-msp-1a" = "msp1a"
741 | "us-east-1-nyc-1" = "nyc1"
742 | "us-east-1-nyc-1a" = "nyc1a"
743 | "us-east-1-phl-1" = "phi1"
744 | "us-east-1-phl-1a" = "phi1a"
745 |
746 | "us-east-2" = "use2"
747 | "us-east-2a" = "use2a"
748 | "us-east-2b" = "use2b"
749 | "us-east-2c" = "use2c"
750 | "us-east-2d" = "use2d"
751 | "us-east-2e" = "use2e"
752 | "us-east-2f" = "use2f"
753 | "us-east-2g" = "use2g"
754 | "us-east-2h" = "use2h"
755 |
756 | "us-west-1" = "usw1"
757 | "us-west-1a" = "usw1a"
758 | "us-west-1b" = "usw1b"
759 | "us-west-1c" = "usw1c"
760 | "us-west-1d" = "usw1d"
761 | "us-west-1e" = "usw1e"
762 | "us-west-1f" = "usw1f"
763 | "us-west-1g" = "usw1g"
764 | "us-west-1h" = "usw1h"
765 |
766 | "us-west-2" = "usw2"
767 | "us-west-2a" = "usw2a"
768 | "us-west-2b" = "usw2b"
769 | "us-west-2c" = "usw2c"
770 | "us-west-2d" = "usw2d"
771 | "us-west-2e" = "usw2e"
772 | "us-west-2f" = "usw2f"
773 | "us-west-2g" = "usw2g"
774 | "us-west-2h" = "usw2h"
775 |
776 | "us-west-2-den-1" = "den1"
777 | "us-west-2-den-1a" = "den1a"
778 | "us-west-2-las-1" = "las1"
779 | "us-west-2-las-1a" = "las1a"
780 | "us-west-2-lax-1" = "lax1"
781 | "us-west-2-lax-1a" = "lax1a"
782 | "us-west-2-lax-1b" = "lax1b"
783 | "us-west-2-pdx-1" = "pdx1"
784 | "us-west-2-pdx-1a" = "pdx1a"
785 | "us-west-2-phx-1" = "phx1"
786 | "us-west-2-phx-1a" = "phx1a"
787 | "us-west-2-sea-1" = "sea1"
788 | "us-west-2-sea-1a" = "sea1a"
789 | }
790 |
791 | from_fixed = zipmap(values(local.to_fixed), keys(local.to_fixed))
792 | from_short = zipmap(values(local.to_short), keys(local.to_short))
793 |
794 | identity = { for k, v in local.to_short : k => k }
795 | }
796 |
797 | data "aws_regions" "default" {
798 | all_regions = true
799 |
800 | filter {
801 | name = "opt-in-status"
802 | values = ["opt-in-not-required"]
803 | }
804 | }
805 |
806 | data "aws_regions" "opted_in" {
807 | all_regions = true
808 |
809 | filter {
810 | name = "opt-in-status"
811 | values = ["opted-in"]
812 | }
813 | }
814 |
815 | data "aws_regions" "not_opted_in" {
816 | all_regions = true
817 |
818 | filter {
819 | name = "opt-in-status"
820 | values = ["not-opted-in"]
821 | }
822 | }
823 |
824 | data "aws_regions" "complete" {
825 | all_regions = true
826 | }
827 |
--------------------------------------------------------------------------------
/outputs.tf:
--------------------------------------------------------------------------------
1 | output "region_az_alt_code_maps" {
2 | description = <<-EOT
3 | Collection of maps converting between official AWS Region, Availability Zone, and Local Zone codes and shorter unofficial codes using only lower case letters and digits. Inspired for use in naming and tagging so that region or AZ code will be 1 semantic unit.
4 |
5 | - `to_fixed` = Map of regions to 3-character codes and Availability Zones to 4-character codes
6 | - `to_short` = Map of regions and Availability Zones to compact (usually 4-6 characters) codes
7 | - `from_fixed` = Map of `fixed` codes back to full region or Availability Zone codes
8 | - `from_short` = Map of `short` codes back to full region or Availability Zone codes
9 | - `identity` = Identity map of full region and Availability Zone codes back to themselves
10 | EOT
11 | value = {
12 | to_fixed = local.to_fixed
13 | to_short = local.to_short
14 | from_fixed = local.from_fixed
15 | from_short = local.from_short
16 | identity = local.identity
17 | }
18 | }
19 |
20 | output "region_display_name_map" {
21 | description = <<-EOT
22 | Map of full region names to user-friendly display names (e.g. "eu-west-3" = "Europe (Paris)").
23 | EOT
24 | value = local.to_display_name
25 | }
26 |
27 | output "elb_logging_account" {
28 | description = "Map of full region to ELB logging account"
29 | value = local.elb_logging_account
30 | }
31 |
32 | output "elb_logging_s3_bucket_policy_json" {
33 | description = <<-EOT
34 | The S3 bucket policy (in JSON) to attach to the S3 bucket to allow Load Balancer logs to be added.
35 | Requires `elb_logging_bucket_resource_arn` and `elb_logging_region` inputs.
36 | EOT
37 | value = join("",
38 | data.aws_iam_policy_document.by_account.*.json,
39 | data.aws_iam_policy_document.by_region.*.json,
40 | )
41 | }
42 |
43 | output "enabled_regions" {
44 | description = "A list of regions that are enabled in the account"
45 | value = setunion(data.aws_regions.default.names, data.aws_regions.opted_in.names)
46 | }
47 |
48 | output "disabled_regions" {
49 | description = "A list of regions that are disabled in the account"
50 | value = data.aws_regions.not_opted_in.names
51 | }
52 |
53 | output "all_regions" {
54 | description = "A list of all regions regardless of availability to the account"
55 | value = data.aws_regions.complete.names
56 | }
57 |
58 |
--------------------------------------------------------------------------------
/test/.gitignore:
--------------------------------------------------------------------------------
1 | .test-harness
2 |
--------------------------------------------------------------------------------
/test/Makefile:
--------------------------------------------------------------------------------
1 | TEST_HARNESS ?= https://github.com/cloudposse/test-harness.git
2 | TEST_HARNESS_BRANCH ?= master
3 | TEST_HARNESS_PATH = $(realpath .test-harness)
4 | BATS_ARGS ?= --tap
5 | BATS_LOG ?= test.log
6 |
7 | # Define a macro to run the tests
8 | define RUN_TESTS
9 | @echo "Running tests in $(1)"
10 | @cd $(1) && bats $(BATS_ARGS) $(addsuffix .bats,$(addprefix $(TEST_HARNESS_PATH)/test/terraform/,$(TESTS)))
11 | endef
12 |
13 | default: all
14 |
15 | -include Makefile.*
16 |
17 | ## Provision the test-harnesss
18 | .test-harness:
19 | [ -d $@ ] || git clone --depth=1 -b $(TEST_HARNESS_BRANCH) $(TEST_HARNESS) $@
20 |
21 | ## Initialize the tests
22 | init: .test-harness
23 |
24 | ## Install all dependencies (OS specific)
25 | deps::
26 | @exit 0
27 |
28 | ## Clean up the test harness
29 | clean:
30 | [ "$(TEST_HARNESS_PATH)" == "/" ] || rm -rf $(TEST_HARNESS_PATH)
31 |
32 | ## Run all tests
33 | all: module examples/complete
34 |
35 | ## Run basic sanity checks against the module itself
36 | module: export TESTS ?= installed lint module-pinning provider-pinning validate terraform-docs input-descriptions output-descriptions
37 | module: deps
38 | $(call RUN_TESTS, ../)
39 |
40 | ## Run tests against example
41 | examples/complete: export TESTS ?= installed lint validate
42 | examples/complete: deps
43 | $(call RUN_TESTS, ../$@)
44 |
--------------------------------------------------------------------------------
/test/Makefile.alpine:
--------------------------------------------------------------------------------
1 | ifneq (,$(wildcard /sbin/apk))
2 | ## Install all dependencies for alpine
3 | deps:: init
4 | @apk add --update terraform-docs@cloudposse json2hcl@cloudposse
5 | endif
6 |
--------------------------------------------------------------------------------
/test/src/.gitignore:
--------------------------------------------------------------------------------
1 | .gopath
2 | vendor/
3 |
--------------------------------------------------------------------------------
/test/src/Makefile:
--------------------------------------------------------------------------------
1 | export TERRAFORM_VERSION ?= $(shell curl -s https://checkpoint-api.hashicorp.com/v1/check/terraform | jq -r -M '.current_version' | cut -d. -f1)
2 |
3 | .DEFAULT_GOAL : all
4 | .PHONY: all
5 |
6 | ## Default target
7 | all: test
8 |
9 | .PHONY : init
10 | ## Initialize tests
11 | init:
12 | @exit 0
13 |
14 | .PHONY : test
15 | ## Run tests
16 | test: init
17 | go mod download
18 | go test -v -timeout 20m
19 |
20 | ## Run tests in docker container
21 | docker/test:
22 | docker run --name terratest --rm -it -e AWS_ACCESS_KEY_ID -e AWS_SECRET_ACCESS_KEY -e AWS_SESSION_TOKEN -e GITHUB_TOKEN \
23 | -e PATH="/usr/local/terraform/$(TERRAFORM_VERSION)/bin:/go/bin:/usr/local/go/bin:/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin" \
24 | -v $(CURDIR)/../../:/module/ cloudposse/test-harness:latest -C /module/test/src test
25 |
26 | .PHONY : clean
27 | ## Clean up files
28 | clean:
29 | rm -rf ../../examples/complete/*.tfstate*
30 |
--------------------------------------------------------------------------------
/test/src/examples_complete_test.go:
--------------------------------------------------------------------------------
1 | package test
2 |
3 | import (
4 | "os"
5 | "regexp"
6 | "strings"
7 | "testing"
8 |
9 | "github.com/gruntwork-io/terratest/modules/random"
10 | "github.com/gruntwork-io/terratest/modules/terraform"
11 | testStructure "github.com/gruntwork-io/terratest/modules/test-structure"
12 | "github.com/stretchr/testify/assert"
13 | )
14 |
15 | func cleanup(t *testing.T, terraformOptions *terraform.Options, tempTestFolder string) {
16 | terraform.Destroy(t, terraformOptions)
17 | os.RemoveAll(tempTestFolder)
18 | }
19 |
20 | // Test the Terraform module in examples/complete using Terratest.
21 | func TestExamplesComplete(t *testing.T) {
22 | t.Parallel()
23 | randID := strings.ToLower(random.UniqueId())
24 | attributes := []string{randID}
25 |
26 | rootFolder := "../../"
27 | terraformFolderRelativeToRoot := "examples/complete"
28 | varFiles := []string{"fixtures.us-east-2.tfvars"}
29 |
30 | tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
31 |
32 | terraformOptions := &terraform.Options{
33 | // The path to where our Terraform code is located
34 | TerraformDir: tempTestFolder,
35 | Upgrade: true,
36 | // Variables to pass to our Terraform code using -var-file options
37 | VarFiles: varFiles,
38 | Vars: map[string]interface{}{
39 | "attributes": attributes,
40 | },
41 | }
42 |
43 | // At the end of the test, run `terraform destroy` to clean up any resources that were created
44 | defer cleanup(t, terraformOptions, tempTestFolder)
45 |
46 | // This will run `terraform init` and `terraform apply` and fail the test if there are any errors
47 | terraform.InitAndApply(t, terraformOptions)
48 |
49 | // Run `terraform output` to get the value of an output variable
50 | region := terraform.Output(t, terraformOptions, "region")
51 | fixed := terraform.Output(t, terraformOptions, "fixed")
52 | short := terraform.Output(t, terraformOptions, "short")
53 | fixedRoundTrip := terraform.Output(t, terraformOptions, "fixed_round_trip")
54 | shortRoundTrip := terraform.Output(t, terraformOptions, "short_round_trip")
55 | enabledRegions := terraform.OutputList(t, terraformOptions, "enabled_regions")
56 | allRegions := terraform.OutputList(t, terraformOptions, "all_regions")
57 | displayNames := terraform.OutputMap(t, terraformOptions, "region_display_name_map")
58 | abbreviationMaps := terraform.OutputMapOfObjects(t, terraformOptions, "region_az_alt_code_maps")
59 |
60 | for _, reg := range allRegions {
61 | for _, k := range []string{"to_fixed", "to_short", "identity"} {
62 | assert.Contains(t, abbreviationMaps[k], reg, "Abbreviation map "+k+" is missing entry for region "+reg)
63 | }
64 | assert.Contains(t, displayNames, reg, "Display Names map is missing entry for region "+reg)
65 | }
66 |
67 | //disabledRegions := terraform.OutputList(t, terraformOptions, "disabled_regions")
68 | idSize := terraform.Output(t, terraformOptions, "identity_size")
69 |
70 | // Verify we're getting back the outputs we expect
71 | assert.Len(t, fixed, 3)
72 | assert.GreaterOrEqual(t, len(short), 4)
73 | assert.LessOrEqual(t, len(short), 6)
74 | assert.Equal(t, region, fixedRoundTrip)
75 | assert.Equal(t, region, shortRoundTrip)
76 | assert.Contains(t, enabledRegions, "us-east-1")
77 | // We may enable all regions in the test account
78 | //assert.Contains(t, disabledRegions, "af-south-1")
79 |
80 | assert.Equal(t, idSize, terraform.Output(t, terraformOptions, "to_short_size"), "Transformation maps are different sizes")
81 | assert.Equal(t, idSize, terraform.Output(t, terraformOptions, "to_fixed_size"), "Transformation maps are different sizes")
82 | assert.Equal(t, idSize, terraform.Output(t, terraformOptions, "from_short_size"), "Transformation maps are different sizes")
83 | assert.Equal(t, idSize, terraform.Output(t, terraformOptions, "from_fixed_size"), "Transformation maps are different sizes")
84 | }
85 |
86 | func TestExamplesCompleteDisabled(t *testing.T) {
87 | t.Parallel()
88 | randID := strings.ToLower(random.UniqueId())
89 | attributes := []string{randID}
90 |
91 | rootFolder := "../../"
92 | terraformFolderRelativeToRoot := "examples/complete"
93 | varFiles := []string{"fixtures.us-east-2.tfvars"}
94 |
95 | tempTestFolder := testStructure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
96 |
97 | terraformOptions := &terraform.Options{
98 | // The path to where our Terraform code is located
99 | TerraformDir: tempTestFolder,
100 | Upgrade: true,
101 | // Variables to pass to our Terraform code using -var-file options
102 | VarFiles: varFiles,
103 | Vars: map[string]interface{}{
104 | "attributes": attributes,
105 | "enabled": "false",
106 | },
107 | }
108 |
109 | // At the end of the test, run `terraform destroy` to clean up any resources that were created
110 | defer cleanup(t, terraformOptions, tempTestFolder)
111 |
112 | // This will run `terraform init` and `terraform apply` and fail the test if there are any errors
113 | results := terraform.InitAndApply(t, terraformOptions)
114 |
115 | // Should complete successfully without creating or changing any resources.
116 | // Extract the "Resources:" section of the output to make the error message more readable.
117 | re := regexp.MustCompile(`Resources: [^.]+\.`)
118 | match := re.FindString(results)
119 | assert.Equal(t, "Resources: 0 added, 0 changed, 0 destroyed.", match, "Deploying with `enabled = false` should not create any resources.")
120 | }
121 |
--------------------------------------------------------------------------------
/test/src/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/cloudposse/terraform-aws-utils
2 |
3 | go 1.20
4 |
5 | require (
6 | github.com/gruntwork-io/terratest v0.41.16
7 | github.com/stretchr/testify v1.8.2
8 | )
9 |
10 | require (
11 | cloud.google.com/go v0.105.0 // indirect
12 | cloud.google.com/go/compute v1.12.1 // indirect
13 | cloud.google.com/go/compute/metadata v0.2.1 // indirect
14 | cloud.google.com/go/iam v0.7.0 // indirect
15 | cloud.google.com/go/storage v1.27.0 // indirect
16 | github.com/agext/levenshtein v1.2.3 // indirect
17 | github.com/apparentlymart/go-textseg/v13 v13.0.0 // indirect
18 | github.com/aws/aws-sdk-go v1.44.122 // indirect
19 | github.com/bgentry/go-netrc v0.0.0-20140422174119-9fd32a8b3d3d // indirect
20 | github.com/boombuler/barcode v1.0.1-0.20190219062509-6c824513bacc // indirect
21 | github.com/cpuguy83/go-md2man/v2 v2.0.0 // indirect
22 | github.com/davecgh/go-spew v1.1.1 // indirect
23 | github.com/docker/spdystream v0.0.0-20181023171402-6480d4af844c // indirect
24 | github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
25 | github.com/go-logr/logr v0.2.0 // indirect
26 | github.com/go-sql-driver/mysql v1.4.1 // indirect
27 | github.com/gogo/protobuf v1.3.2 // indirect
28 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
29 | github.com/golang/protobuf v1.5.2 // indirect
30 | github.com/google/go-cmp v0.5.9 // indirect
31 | github.com/google/gofuzz v1.1.0 // indirect
32 | github.com/google/uuid v1.3.0 // indirect
33 | github.com/googleapis/enterprise-certificate-proxy v0.2.0 // indirect
34 | github.com/googleapis/gax-go/v2 v2.7.0 // indirect
35 | github.com/googleapis/gnostic v0.4.1 // indirect
36 | github.com/gruntwork-io/go-commons v0.8.0 // indirect
37 | github.com/hashicorp/errwrap v1.0.0 // indirect
38 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
39 | github.com/hashicorp/go-getter v1.7.1 // indirect
40 | github.com/hashicorp/go-multierror v1.1.0 // indirect
41 | github.com/hashicorp/go-safetemp v1.0.0 // indirect
42 | github.com/hashicorp/go-version v1.6.0 // indirect
43 | github.com/hashicorp/hcl/v2 v2.9.1 // indirect
44 | github.com/hashicorp/terraform-json v0.13.0 // indirect
45 | github.com/imdario/mergo v0.3.11 // indirect
46 | github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
47 | github.com/jmespath/go-jmespath v0.4.0 // indirect
48 | github.com/json-iterator/go v1.1.11 // indirect
49 | github.com/klauspost/compress v1.15.11 // indirect
50 | github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
51 | github.com/mitchellh/go-homedir v1.1.0 // indirect
52 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect
53 | github.com/mitchellh/go-wordwrap v1.0.1 // indirect
54 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
55 | github.com/modern-go/reflect2 v1.0.1 // indirect
56 | github.com/pmezard/go-difflib v1.0.0 // indirect
57 | github.com/pquerna/otp v1.2.0 // indirect
58 | github.com/russross/blackfriday/v2 v2.1.0 // indirect
59 | github.com/spf13/pflag v1.0.5 // indirect
60 | github.com/tmccombs/hcl2json v0.3.3 // indirect
61 | github.com/ulikunitz/xz v0.5.10 // indirect
62 | github.com/urfave/cli v1.22.2 // indirect
63 | github.com/zclconf/go-cty v1.9.1 // indirect
64 | go.opencensus.io v0.24.0 // indirect
65 | golang.org/x/crypto v0.1.0 // indirect
66 | golang.org/x/net v0.7.0 // indirect
67 | golang.org/x/oauth2 v0.1.0 // indirect
68 | golang.org/x/sys v0.5.0 // indirect
69 | golang.org/x/term v0.5.0 // indirect
70 | golang.org/x/text v0.7.0 // indirect
71 | golang.org/x/time v0.0.0-20200630173020-3af7569d3a1e // indirect
72 | golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
73 | google.golang.org/api v0.103.0 // indirect
74 | google.golang.org/appengine v1.6.7 // indirect
75 | google.golang.org/genproto v0.0.0-20221201164419-0e50fba7f41c // indirect
76 | google.golang.org/grpc v1.51.0 // indirect
77 | google.golang.org/protobuf v1.28.1 // indirect
78 | gopkg.in/inf.v0 v0.9.1 // indirect
79 | gopkg.in/yaml.v2 v2.4.0 // indirect
80 | gopkg.in/yaml.v3 v3.0.1 // indirect
81 | k8s.io/api v0.20.6 // indirect
82 | k8s.io/apimachinery v0.20.6 // indirect
83 | k8s.io/client-go v0.20.6 // indirect
84 | k8s.io/klog/v2 v2.4.0 // indirect
85 | k8s.io/utils v0.0.0-20201110183641-67b214c5f920 // indirect
86 | sigs.k8s.io/structured-merge-diff/v4 v4.0.3 // indirect
87 | sigs.k8s.io/yaml v1.2.0 // indirect
88 | )
89 |
--------------------------------------------------------------------------------
/variables.tf:
--------------------------------------------------------------------------------
1 | variable "elb_logging_bucket_resource_arn" {
2 | type = string
3 | description = <<-EOT
4 | The AWS Resource ARN to use in the policy granting access to Load Balancer Logging.
5 | Typically of the form `arn:aws:s3:::_bucket-name_/_prefix_/AWSLogs/_your-aws-account-id_/*`.
6 | Required to generate `elb_logging_s3_bucket_policy_json`.
7 | See [AWS Documentation](https://docs.aws.amazon.com/elasticloadbalancing/latest/application/enable-access-logging.html#attach-bucket-policy).
8 | EOT
9 | default = ""
10 | }
11 |
12 | variable "elb_logging_region" {
13 | description = <<-EOT
14 | Full region (e.g. `us-east-1`) where ELB logging is taking place. Required to generate `elb_s3_bucket_policy_json`.
15 | Must be known at "plan" time.
16 | EOT
17 | default = ""
18 | }
19 |
--------------------------------------------------------------------------------
/versions.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_version = ">= 0.14.0"
3 |
4 | required_providers {
5 | aws = {
6 | source = "hashicorp/aws"
7 | version = ">= 2"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------