├── .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
├── 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
├── userdata.tpl
├── variables.tf
└── versions.tf
/.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-eks-workers/f77430b09e59db7c4038a8e4f13b4fb5bb50d6f9/.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-eks-workers/f77430b09e59db7c4038a8e4f13b4fb5bb50d6f9/.github/banner.png
--------------------------------------------------------------------------------
/.github/mergify.yml:
--------------------------------------------------------------------------------
1 | extends: .github
2 |
--------------------------------------------------------------------------------
/.github/renovate.json:
--------------------------------------------------------------------------------
1 | {
2 | "extends": [
3 | "config:base",
4 | ":preserveSemverRanges"
5 | ],
6 | "baseBranches": ["main", "master", "/^release\\/v\\d{1,2}$/"],
7 | "labels": ["auto-update"],
8 | "dependencyDashboardAutoclose": true,
9 | "enabledManagers": ["terraform"],
10 | "terraform": {
11 | "ignorePaths": ["**/context.tf", "examples/**"]
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/.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-eks-workers
5 | description: Terraform module to provision an AWS AutoScaling Group, IAM Role, and Security Group for EKS Workers
6 | homepage: https://cloudposse.com/accelerate
7 | topics: terraform, terraform-module, eks, aws, kubernetes, nodes, workers, cluster, k8s, ec2, hcl2
8 |
9 |
10 |
11 |
--------------------------------------------------------------------------------
/.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.lock.hcl
8 |
9 | **/.idea
10 | **/*.iml
11 |
12 | **/.build-harness
13 | **/build-harness
14 |
15 | # vim editor
16 | *.swp
17 |
--------------------------------------------------------------------------------
/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 2018-2019 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 | Terraform module to provision AWS resources to run EC2 worker nodes for [Elastic Kubernetes Service](https://aws.amazon.com/eks/).
31 |
32 | Instantiate it multiple times to create many EKS worker node pools with specific settings such as GPUs, EC2 instance types, or autoscale parameters.
33 |
34 |
35 | > [!TIP]
36 | > #### 👽 Use Atmos with Terraform
37 | > Cloud Posse uses [`atmos`](https://atmos.tools) to easily orchestrate multiple environments using Terraform.
38 | > Works with [Github Actions](https://atmos.tools/integrations/github-actions/), [Atlantis](https://atmos.tools/integrations/atlantis), or [Spacelift](https://atmos.tools/integrations/spacelift).
39 | >
40 | >
41 | > Watch demo of using Atmos with Terraform
42 | > 
43 | > Example of running atmos
to manage infrastructure from our Quick Start tutorial.
44 | >
45 |
46 |
47 | ## Introduction
48 |
49 | The module provisions the following resources:
50 |
51 | - IAM Role and Instance Profile to allow Kubernetes nodes to access other AWS services
52 | - Security Group with rules for EKS workers to allow networking traffic
53 | - AutoScaling Group with Launch Template to configure and launch worker instances
54 | - AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down.
55 | If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable `autoscaling_policies_enabled` to `"false"`.
56 |
57 |
58 |
59 |
60 | ## Usage
61 |
62 | For a complete example, see [examples/complete](examples/complete)
63 |
64 | ```hcl
65 | provider "aws" {
66 | region = var.region
67 | }
68 |
69 | locals {
70 | # The usage of the specific kubernetes.io/cluster/* resource tags below are required
71 | # for EKS and Kubernetes to discover and manage networking resources
72 | # https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#base-vpc-networking
73 | tags = merge(var.tags, map("kubernetes.io/cluster/${var.cluster_name}", "shared"))
74 | }
75 |
76 | module "vpc" {
77 | source = "cloudposse/vpc/aws"
78 | version = "2.1.1"
79 |
80 | namespace = var.namespace
81 | stage = var.stage
82 | name = var.name
83 |
84 | ipv4_primary_cidr_block = "172.16.0.0/16"
85 | tags = local.tags
86 | }
87 |
88 | module "subnets" {
89 | source = "cloudposse/dynamic-subnets/aws"
90 | version = "2.4.1"
91 |
92 | namespace = var.namespace
93 | stage = var.stage
94 | name = var.name
95 |
96 | availability_zones = var.availability_zones
97 | vpc_id = module.vpc.vpc_id
98 | igw_id = [module.vpc.igw_id]
99 | ipv4_cidr_block = [module.vpc.vpc_cidr_block]
100 | nat_gateway_enabled = false
101 | nat_instance_enabled = false
102 | tags = local.tags
103 | }
104 |
105 | module "eks_workers" {
106 | source = "cloudposse/eks-workers/aws"
107 | # Cloud Posse recommends pinning every module to a specific version
108 | # version = "x.x.x"
109 | namespace = var.namespace
110 | stage = var.stage
111 | name = var.name
112 | instance_type = var.instance_type
113 | vpc_id = module.vpc.vpc_id
114 | subnet_ids = module.subnets.public_subnet_ids
115 | health_check_type = var.health_check_type
116 | min_size = var.min_size
117 | max_size = var.max_size
118 | wait_for_capacity_timeout = var.wait_for_capacity_timeout
119 | cluster_name = var.cluster_name
120 | cluster_endpoint = var.cluster_endpoint
121 | cluster_certificate_authority_data = var.cluster_certificate_authority_data
122 | cluster_security_group_id = var.cluster_security_group_id
123 |
124 | # Auto-scaling policies and CloudWatch metric alarms
125 | autoscaling_policies_enabled = var.autoscaling_policies_enabled
126 | cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent
127 | cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent
128 | }
129 | ```
130 |
131 | > [!IMPORTANT]
132 | > In Cloud Posse's examples, we avoid pinning modules to specific versions to prevent discrepancies between the documentation
133 | > and the latest released versions. However, for your own projects, we strongly advise pinning each module to the exact version
134 | > you're using. This practice ensures the stability of your infrastructure. Additionally, we recommend implementing a systematic
135 | > approach for updating versions to avoid unexpected changes.
136 |
137 |
138 |
139 |
140 |
141 |
142 |
143 |
144 |
145 | ## Requirements
146 |
147 | | Name | Version |
148 | |------|---------|
149 | | [terraform](#requirement\_terraform) | >= 1.0 |
150 | | [aws](#requirement\_aws) | >= 5.16.0 |
151 |
152 | ## Providers
153 |
154 | | Name | Version |
155 | |------|---------|
156 | | [aws](#provider\_aws) | >= 5.16.0 |
157 |
158 | ## Modules
159 |
160 | | Name | Source | Version |
161 | |------|--------|---------|
162 | | [autoscale\_group](#module\_autoscale\_group) | cloudposse/ec2-autoscale-group/aws | 0.40.0 |
163 | | [label](#module\_label) | cloudposse/label/null | 0.25.0 |
164 | | [this](#module\_this) | cloudposse/label/null | 0.25.0 |
165 |
166 | ## Resources
167 |
168 | | Name | Type |
169 | |------|------|
170 | | [aws_iam_instance_profile.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource |
171 | | [aws_iam_role.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource |
172 | | [aws_iam_role_policy_attachment.amazon_ec2_container_registry_read_only](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
173 | | [aws_iam_role_policy_attachment.amazon_eks_cni_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
174 | | [aws_iam_role_policy_attachment.amazon_eks_worker_node_policy](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
175 | | [aws_iam_role_policy_attachment.existing_policies_attach_to_eks_workers_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource |
176 | | [aws_security_group.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group) | resource |
177 | | [aws_security_group_rule.egress](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
178 | | [aws_security_group_rule.ingress_cidr_blocks](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
179 | | [aws_security_group_rule.ingress_cluster](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
180 | | [aws_security_group_rule.ingress_security_groups](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
181 | | [aws_security_group_rule.ingress_self](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/security_group_rule) | resource |
182 | | [aws_ami.eks_worker](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/ami) | data source |
183 | | [aws_iam_instance_profile.default](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_instance_profile) | data source |
184 | | [aws_iam_policy_document.assume_role](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source |
185 | | [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source |
186 |
187 | ## Inputs
188 |
189 | | Name | Description | Type | Default | Required |
190 | |------|-------------|------|---------|:--------:|
191 | | [additional\_security\_group\_ids](#input\_additional\_security\_group\_ids) | Additional list of security groups that will be attached to the autoscaling group | `list(string)` | `[]` | no |
192 | | [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 |
193 | | [after\_cluster\_joining\_userdata](#input\_after\_cluster\_joining\_userdata) | Additional commands to execute on each worker node after joining the EKS cluster (after executing the `bootstrap.sh` script). For mot info, see https://kubedex.com/90-days-of-aws-eks-in-production | `string` | `""` | no |
194 | | [allowed\_cidr\_blocks](#input\_allowed\_cidr\_blocks) | List of CIDR blocks to be allowed to connect to the worker nodes | `list(string)` | `[]` | no |
195 | | [allowed\_security\_groups](#input\_allowed\_security\_groups) | List of Security Group IDs to be allowed to connect to the worker nodes | `list(string)` | `[]` | no |
196 | | [associate\_public\_ip\_address](#input\_associate\_public\_ip\_address) | Associate a public IP address with an instance in a VPC | `bool` | `false` | no |
197 | | [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 |
198 | | [autoscaling\_group\_tags](#input\_autoscaling\_group\_tags) | Additional tags only for the autoscaling group, e.g. "k8s.io/cluster-autoscaler/node-template/taint/dedicated" = "ci-cd:NoSchedule". | `map(string)` | `{}` | no |
199 | | [autoscaling\_policies\_enabled](#input\_autoscaling\_policies\_enabled) | Whether to create `aws_autoscaling_policy` and `aws_cloudwatch_metric_alarm` resources to control Auto Scaling | `bool` | `true` | no |
200 | | [aws\_iam\_instance\_profile\_name](#input\_aws\_iam\_instance\_profile\_name) | The name of the existing instance profile that will be used in autoscaling group for EKS workers. If empty will create a new instance profile. | `string` | `""` | no |
201 | | [before\_cluster\_joining\_userdata](#input\_before\_cluster\_joining\_userdata) | Additional commands to execute on each worker node before joining the EKS cluster (before executing the `bootstrap.sh` script). For mot info, see https://kubedex.com/90-days-of-aws-eks-in-production | `string` | `""` | no |
202 | | [block\_device\_mappings](#input\_block\_device\_mappings) | Specify volumes to attach to the instance besides the volumes specified by the AMI | list(object({
device_name = string
no_device = bool
virtual_name = string
ebs = object({
delete_on_termination = bool
encrypted = bool
iops = number
kms_key_id = string
snapshot_id = string
volume_size = number
volume_type = string
})
}))
| `[]` | no |
203 | | [bootstrap\_extra\_args](#input\_bootstrap\_extra\_args) | Extra arguments to the `bootstrap.sh` script to enable `--enable-docker-bridge` or `--use-max-pods` | `string` | `""` | no |
204 | | [cluster\_certificate\_authority\_data](#input\_cluster\_certificate\_authority\_data) | The base64 encoded certificate data required to communicate with the cluster | `string` | n/a | yes |
205 | | [cluster\_endpoint](#input\_cluster\_endpoint) | EKS cluster endpoint | `string` | n/a | yes |
206 | | [cluster\_name](#input\_cluster\_name) | The name of the EKS cluster | `string` | n/a | yes |
207 | | [cluster\_security\_group\_id](#input\_cluster\_security\_group\_id) | Security Group ID of the EKS cluster | `string` | n/a | yes |
208 | | [cluster\_security\_group\_ingress\_enabled](#input\_cluster\_security\_group\_ingress\_enabled) | Whether to enable the EKS cluster Security Group as ingress to workers Security Group | `bool` | `true` | no |
209 | | [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 |
210 | | [cpu\_utilization\_high\_evaluation\_periods](#input\_cpu\_utilization\_high\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold | `number` | `2` | no |
211 | | [cpu\_utilization\_high\_period\_seconds](#input\_cpu\_utilization\_high\_period\_seconds) | The period in seconds over which the specified statistic is applied | `number` | `300` | no |
212 | | [cpu\_utilization\_high\_statistic](#input\_cpu\_utilization\_high\_statistic) | The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` | `string` | `"Average"` | no |
213 | | [cpu\_utilization\_high\_threshold\_percent](#input\_cpu\_utilization\_high\_threshold\_percent) | The value against which the specified statistic is compared | `number` | `90` | no |
214 | | [cpu\_utilization\_low\_evaluation\_periods](#input\_cpu\_utilization\_low\_evaluation\_periods) | The number of periods over which data is compared to the specified threshold | `number` | `2` | no |
215 | | [cpu\_utilization\_low\_period\_seconds](#input\_cpu\_utilization\_low\_period\_seconds) | The period in seconds over which the specified statistic is applied | `number` | `300` | no |
216 | | [cpu\_utilization\_low\_statistic](#input\_cpu\_utilization\_low\_statistic) | The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum` | `string` | `"Average"` | no |
217 | | [cpu\_utilization\_low\_threshold\_percent](#input\_cpu\_utilization\_low\_threshold\_percent) | The value against which the specified statistic is compared | `number` | `10` | no |
218 | | [credit\_specification](#input\_credit\_specification) | Customize the credit specification of the instances | object({
cpu_credits = string
})
| `null` | no |
219 | | [default\_cooldown](#input\_default\_cooldown) | The amount of time, in seconds, after a scaling activity completes before another scaling activity can start | `number` | `300` | no |
220 | | [delimiter](#input\_delimiter) | Delimiter to be used between ID elements.
Defaults to `-` (hyphen). Set to `""` to use no delimiter at all. | `string` | `null` | no |
221 | | [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 |
222 | | [disable\_api\_termination](#input\_disable\_api\_termination) | If `true`, enables EC2 Instance Termination Protection | `bool` | `false` | no |
223 | | [ebs\_optimized](#input\_ebs\_optimized) | If true, the launched EC2 instance will be EBS-optimized | `bool` | `false` | no |
224 | | [eks\_worker\_ami\_name\_filter](#input\_eks\_worker\_ami\_name\_filter) | AMI name filter to lookup the most recent EKS AMI if `image_id` is not provided | `string` | `"amazon-eks-node-*"` | no |
225 | | [eks\_worker\_ami\_name\_regex](#input\_eks\_worker\_ami\_name\_regex) | A regex string to apply to the AMI list returned by AWS | `string` | `"^amazon-eks-node-[0-9,.]+-v[0-9]{8}$"` | no |
226 | | [elastic\_gpu\_specifications](#input\_elastic\_gpu\_specifications) | Specifications of Elastic GPU to attach to the instances | object({
type = string
})
| `null` | no |
227 | | [enable\_monitoring](#input\_enable\_monitoring) | Enable/disable detailed monitoring | `bool` | `true` | no |
228 | | [enabled](#input\_enabled) | Set to false to prevent the module from creating any resources | `bool` | `null` | no |
229 | | [enabled\_metrics](#input\_enabled\_metrics) | A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances` | `list(string)` | [
"GroupMinSize",
"GroupMaxSize",
"GroupDesiredCapacity",
"GroupInServiceInstances",
"GroupPendingInstances",
"GroupStandbyInstances",
"GroupTerminatingInstances",
"GroupTotalInstances"
]
| no |
230 | | [environment](#input\_environment) | ID element. Usually used for region e.g. 'uw2', 'us-west-2', OR role 'prod', 'staging', 'dev', 'UAT' | `string` | `null` | no |
231 | | [force\_delete](#input\_force\_delete) | Allows deleting the autoscaling group without waiting for all instances in the pool to terminate. You can force an autoscaling group to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the instances before deleting the group. This bypasses that behavior and potentially leaves resources dangling | `bool` | `false` | no |
232 | | [health\_check\_grace\_period](#input\_health\_check\_grace\_period) | Time (in seconds) after instance comes into service before checking health | `number` | `300` | no |
233 | | [health\_check\_type](#input\_health\_check\_type) | Controls how health checking is done. Valid values are `EC2` or `ELB` | `string` | `"EC2"` | no |
234 | | [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 |
235 | | [image\_id](#input\_image\_id) | EC2 image ID to launch. If not provided, the module will lookup the most recent EKS AMI. See https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html for more details on EKS-optimized images | `string` | `""` | no |
236 | | [instance\_initiated\_shutdown\_behavior](#input\_instance\_initiated\_shutdown\_behavior) | Shutdown behavior for the instances. Can be `stop` or `terminate` | `string` | `"terminate"` | no |
237 | | [instance\_market\_options](#input\_instance\_market\_options) | The market (purchasing) option for the instances | object({
market_type = string
spot_options = object({
block_duration_minutes = number
instance_interruption_behavior = string
max_price = number
spot_instance_type = string
valid_until = string
})
})
| `null` | no |
238 | | [instance\_type](#input\_instance\_type) | Instance type to launch | `string` | n/a | yes |
239 | | [key\_name](#input\_key\_name) | SSH key name that should be used for the instance | `string` | `""` | no |
240 | | [kubelet\_extra\_args](#input\_kubelet\_extra\_args) | Extra arguments to pass to kubelet, like "--register-with-taints=dedicated=ci-cd:NoSchedule --node-labels=purpose=ci-worker" | `string` | `""` | no |
241 | | [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 |
242 | | [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 |
243 | | [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 |
244 | | [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 |
245 | | [load\_balancers](#input\_load\_balancers) | A list of elastic load balancer names to add to the autoscaling group. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead | `list(string)` | `[]` | no |
246 | | [max\_instance\_lifetime](#input\_max\_instance\_lifetime) | The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 seconds | `number` | `null` | no |
247 | | [max\_size](#input\_max\_size) | The maximum size of the autoscale group | `number` | n/a | yes |
248 | | [metadata\_http\_endpoint\_enabled](#input\_metadata\_http\_endpoint\_enabled) | Set false to disable the Instance Metadata Service. | `bool` | `true` | no |
249 | | [metadata\_http\_put\_response\_hop\_limit](#input\_metadata\_http\_put\_response\_hop\_limit) | The desired HTTP PUT response hop limit (between 1 and 64) for Instance Metadata Service requests.
The default is `2` to support containerized workloads. | `number` | `2` | no |
250 | | [metadata\_http\_tokens\_required](#input\_metadata\_http\_tokens\_required) | Set true to require IMDS session tokens, disabling Instance Metadata Service Version 1. | `bool` | `true` | no |
251 | | [metrics\_granularity](#input\_metrics\_granularity) | The granularity to associate with the metrics to collect. The only valid value is 1Minute | `string` | `"1Minute"` | no |
252 | | [min\_elb\_capacity](#input\_min\_elb\_capacity) | Setting this causes Terraform to wait for this number of instances to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes | `number` | `0` | no |
253 | | [min\_size](#input\_min\_size) | The minimum size of the autoscale group | `number` | n/a | yes |
254 | | [mixed\_instances\_policy](#input\_mixed\_instances\_policy) | policy to used mixed group of on demand/spot of differing types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1 | object({
instances_distribution = object({
on_demand_allocation_strategy = string
on_demand_base_capacity = number
on_demand_percentage_above_base_capacity = number
spot_allocation_strategy = string
spot_instance_pools = number
spot_max_price = string
})
override = list(object({
instance_type = string
weighted_capacity = number
}))
})
| `null` | no |
255 | | [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 |
256 | | [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 |
257 | | [placement](#input\_placement) | The placement specifications of the instances | object({
affinity = string
availability_zone = string
group_name = string
host_id = string
tenancy = string
})
| `null` | no |
258 | | [placement\_group](#input\_placement\_group) | The name of the placement group into which you'll launch your instances, if any | `string` | `""` | no |
259 | | [protect\_from\_scale\_in](#input\_protect\_from\_scale\_in) | Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events | `bool` | `false` | no |
260 | | [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 |
261 | | [scale\_down\_adjustment\_type](#input\_scale\_down\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no |
262 | | [scale\_down\_cooldown\_seconds](#input\_scale\_down\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no |
263 | | [scale\_down\_policy\_type](#input\_scale\_down\_policy\_type) | The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling` | `string` | `"SimpleScaling"` | no |
264 | | [scale\_down\_scaling\_adjustment](#input\_scale\_down\_scaling\_adjustment) | The number of instances by which to scale. `scale_down_scaling_adjustment` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `-1` | no |
265 | | [scale\_up\_adjustment\_type](#input\_scale\_up\_adjustment\_type) | Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity` | `string` | `"ChangeInCapacity"` | no |
266 | | [scale\_up\_cooldown\_seconds](#input\_scale\_up\_cooldown\_seconds) | The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start | `number` | `300` | no |
267 | | [scale\_up\_policy\_type](#input\_scale\_up\_policy\_type) | The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling` | `string` | `"SimpleScaling"` | no |
268 | | [scale\_up\_scaling\_adjustment](#input\_scale\_up\_scaling\_adjustment) | The number of instances by which to scale. `scale_up_adjustment_type` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity | `number` | `1` | no |
269 | | [service\_linked\_role\_arn](#input\_service\_linked\_role\_arn) | The ARN of the service-linked role that the ASG will use to call other AWS services | `string` | `""` | no |
270 | | [stage](#input\_stage) | ID element. Usually used to indicate role, e.g. 'prod', 'staging', 'source', 'build', 'test', 'deploy', 'release' | `string` | `null` | no |
271 | | [subnet\_ids](#input\_subnet\_ids) | A list of subnet IDs to launch resources in | `list(string)` | n/a | yes |
272 | | [suspended\_processes](#input\_suspended\_processes) | A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly. | `list(string)` | `[]` | no |
273 | | [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 |
274 | | [target\_group\_arns](#input\_target\_group\_arns) | A list of aws\_alb\_target\_group ARNs, for use with Application Load Balancing | `list(string)` | `[]` | no |
275 | | [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 |
276 | | [termination\_policies](#input\_termination\_policies) | A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `Default` | `list(string)` | [
"Default"
]
| no |
277 | | [use\_custom\_image\_id](#input\_use\_custom\_image\_id) | If set to `true`, will use variable `image_id` for the EKS workers inside autoscaling group | `bool` | `false` | no |
278 | | [use\_existing\_aws\_iam\_instance\_profile](#input\_use\_existing\_aws\_iam\_instance\_profile) | If set to `true`, will use variable `aws_iam_instance_profile_name` to run EKS workers using an existing AWS instance profile that was created outside of this module, workaround for error like `count cannot be computed` | `bool` | `false` | no |
279 | | [use\_existing\_security\_group](#input\_use\_existing\_security\_group) | If set to `true`, will use variable `workers_security_group_id` to run EKS workers using an existing security group that was created outside of this module, workaround for errors like `count cannot be computed` | `bool` | `false` | no |
280 | | [vpc\_id](#input\_vpc\_id) | VPC ID for the EKS cluster | `string` | n/a | yes |
281 | | [wait\_for\_capacity\_timeout](#input\_wait\_for\_capacity\_timeout) | A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to '0' causes Terraform to skip all Capacity Waiting behavior | `string` | `"10m"` | no |
282 | | [wait\_for\_elb\_capacity](#input\_wait\_for\_elb\_capacity) | Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over `min_elb_capacity` behavior | `number` | `0` | no |
283 | | [workers\_role\_policy\_arns](#input\_workers\_role\_policy\_arns) | List of policy ARNs that will be attached to the workers default role on creation | `list(string)` | `[]` | no |
284 | | [workers\_role\_policy\_arns\_count](#input\_workers\_role\_policy\_arns\_count) | Count of policy ARNs that will be attached to the workers default role on creation. Needed to prevent Terraform error `count can't be computed` | `number` | `0` | no |
285 | | [workers\_security\_group\_id](#input\_workers\_security\_group\_id) | The name of the existing security group that will be used in autoscaling group for EKS workers. If empty, a new security group will be created | `string` | `""` | no |
286 |
287 | ## Outputs
288 |
289 | | Name | Description |
290 | |------|-------------|
291 | | [autoscaling\_group\_arn](#output\_autoscaling\_group\_arn) | ARN of the AutoScaling Group |
292 | | [autoscaling\_group\_default\_cooldown](#output\_autoscaling\_group\_default\_cooldown) | Time between a scaling activity and the succeeding scaling activity |
293 | | [autoscaling\_group\_desired\_capacity](#output\_autoscaling\_group\_desired\_capacity) | The number of Amazon EC2 instances that should be running in the group |
294 | | [autoscaling\_group\_health\_check\_grace\_period](#output\_autoscaling\_group\_health\_check\_grace\_period) | Time after instance comes into service before checking health |
295 | | [autoscaling\_group\_health\_check\_type](#output\_autoscaling\_group\_health\_check\_type) | `EC2` or `ELB`. Controls how health checking is done |
296 | | [autoscaling\_group\_id](#output\_autoscaling\_group\_id) | The AutoScaling Group ID |
297 | | [autoscaling\_group\_max\_size](#output\_autoscaling\_group\_max\_size) | The maximum size of the AutoScaling Group |
298 | | [autoscaling\_group\_min\_size](#output\_autoscaling\_group\_min\_size) | The minimum size of the AutoScaling Group |
299 | | [autoscaling\_group\_name](#output\_autoscaling\_group\_name) | The AutoScaling Group name |
300 | | [autoscaling\_group\_tags](#output\_autoscaling\_group\_tags) | A list of tag settings associated with the AutoScaling Group |
301 | | [launch\_template\_arn](#output\_launch\_template\_arn) | ARN of the launch template |
302 | | [launch\_template\_id](#output\_launch\_template\_id) | The ID of the launch template |
303 | | [security\_group\_arn](#output\_security\_group\_arn) | ARN of the worker nodes Security Group |
304 | | [security\_group\_id](#output\_security\_group\_id) | ID of the worker nodes Security Group |
305 | | [security\_group\_name](#output\_security\_group\_name) | Name of the worker nodes Security Group |
306 | | [workers\_role\_arn](#output\_workers\_role\_arn) | ARN of the worker nodes IAM role |
307 | | [workers\_role\_name](#output\_workers\_role\_name) | Name of the worker nodes IAM role |
308 |
309 |
310 |
311 |
312 |
313 |
314 |
315 |
316 | ## Related Projects
317 |
318 | Check out these related projects.
319 |
320 | - [terraform-aws-ec2-autoscale-group](https://github.com/cloudposse/terraform-aws-ec2-autoscale-group) - Terraform module to provision Auto Scaling Group and Launch Template on AWS
321 | - [terraform-aws-ecs-container-definition](https://github.com/cloudposse/terraform-aws-ecs-container-definition) - Terraform module to generate well-formed JSON documents (container definitions) that are passed to the aws_ecs_task_definition Terraform resource
322 | - [terraform-aws-ecs-alb-service-task](https://github.com/cloudposse/terraform-aws-ecs-alb-service-task) - Terraform module which implements an ECS service which exposes a web service via ALB
323 | - [terraform-aws-ecs-web-app](https://github.com/cloudposse/terraform-aws-ecs-web-app) - Terraform module that implements a web app on ECS and supports autoscaling, CI/CD, monitoring, ALB integration, and much more
324 | - [terraform-aws-ecs-codepipeline](https://github.com/cloudposse/terraform-aws-ecs-codepipeline) - Terraform module for CI/CD with AWS Code Pipeline and Code Build for ECS
325 | - [terraform-aws-ecs-cloudwatch-autoscaling](https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-autoscaling) - Terraform module to autoscale ECS Service based on CloudWatch metrics
326 | - [terraform-aws-ecs-cloudwatch-sns-alarms](https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms) - Terraform module to create CloudWatch Alarms on ECS Service level metrics
327 | - [terraform-aws-ec2-instance](https://github.com/cloudposse/terraform-aws-ec2-instance) - Terraform module for providing a general purpose EC2 instance
328 | - [terraform-aws-ec2-instance-group](https://github.com/cloudposse/terraform-aws-ec2-instance-group) - Terraform module for provisioning multiple general purpose EC2 hosts for stateful applications
329 |
330 |
331 | > [!TIP]
332 | > #### Use Terraform Reference Architectures for AWS
333 | >
334 | > Use Cloud Posse's ready-to-go [terraform architecture blueprints](https://cloudposse.com/reference-architecture/) for AWS to get up and running quickly.
335 | >
336 | > ✅ We build it together with your team.
337 | > ✅ Your team owns everything.
338 | > ✅ 100% Open Source and backed by fanatical support.
339 | >
340 | >
341 | > 📚 Learn More
342 | >
343 | >
344 | >
345 | > Cloud Posse is the leading [**DevOps Accelerator**](https://cpco.io/commercial-support?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-eks-workers&utm_content=commercial_support) for funded startups and enterprises.
346 | >
347 | > *Your team can operate like a pro today.*
348 | >
349 | > Ensure that your team succeeds by using Cloud Posse's proven process and turnkey blueprints. Plus, we stick around until you succeed.
350 | > #### Day-0: Your Foundation for Success
351 | > - **Reference Architecture.** You'll get everything you need from the ground up built using 100% infrastructure as code.
352 | > - **Deployment Strategy.** Adopt a proven deployment strategy with GitHub Actions, enabling automated, repeatable, and reliable software releases.
353 | > - **Site Reliability Engineering.** Gain total visibility into your applications and services with Datadog, ensuring high availability and performance.
354 | > - **Security Baseline.** Establish a secure environment from the start, with built-in governance, accountability, and comprehensive audit logs, safeguarding your operations.
355 | > - **GitOps.** Empower your team to manage infrastructure changes confidently and efficiently through Pull Requests, leveraging the full power of GitHub Actions.
356 | >
357 | >
358 | >
359 | > #### Day-2: Your Operational Mastery
360 | > - **Training.** Equip your team with the knowledge and skills to confidently manage the infrastructure, ensuring long-term success and self-sufficiency.
361 | > - **Support.** Benefit from a seamless communication over Slack with our experts, ensuring you have the support you need, whenever you need it.
362 | > - **Troubleshooting.** Access expert assistance to quickly resolve any operational challenges, minimizing downtime and maintaining business continuity.
363 | > - **Code Reviews.** Enhance your team’s code quality with our expert feedback, fostering continuous improvement and collaboration.
364 | > - **Bug Fixes.** Rely on our team to troubleshoot and resolve any issues, ensuring your systems run smoothly.
365 | > - **Migration Assistance.** Accelerate your migration process with our dedicated support, minimizing disruption and speeding up time-to-value.
366 | > - **Customer Workshops.** Engage with our team in weekly workshops, gaining insights and strategies to continuously improve and innovate.
367 | >
368 | >
369 | >
370 |
371 | ## ✨ Contributing
372 |
373 | This project is under active development, and we encourage contributions from our community.
374 |
375 |
376 |
377 | Many thanks to our outstanding contributors:
378 |
379 |
380 |
381 |
382 |
383 | For 🐛 bug reports & feature requests, please use the [issue tracker](https://github.com/cloudposse/terraform-aws-eks-workers/issues).
384 |
385 | In general, PRs are welcome. We follow the typical "fork-and-pull" Git workflow.
386 | 1. Review our [Code of Conduct](https://github.com/cloudposse/terraform-aws-eks-workers/?tab=coc-ov-file#code-of-conduct) and [Contributor Guidelines](https://github.com/cloudposse/.github/blob/main/CONTRIBUTING.md).
387 | 2. **Fork** the repo on GitHub
388 | 3. **Clone** the project to your own machine
389 | 4. **Commit** changes to your own branch
390 | 5. **Push** your work back up to your fork
391 | 6. Submit a **Pull Request** so that we can review your changes
392 |
393 | **NOTE:** Be sure to merge the latest changes from "upstream" before making a pull request!
394 |
395 | ### 🌎 Slack Community
396 |
397 | Join our [Open Source Community](https://cpco.io/slack?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-eks-workers&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.
398 |
399 | ### 📰 Newsletter
400 |
401 | Sign up for [our newsletter](https://cpco.io/newsletter?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-eks-workers&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.
402 | Dropped straight into your Inbox every week — and usually a 5-minute read.
403 |
404 | ### 📆 Office Hours
405 |
406 | [Join us every Wednesday via Zoom](https://cloudposse.com/office-hours?utm_source=github&utm_medium=readme&utm_campaign=cloudposse/terraform-aws-eks-workers&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.
407 | It's **FREE** for everyone!
408 | ## License
409 |
410 |
411 |
412 |
413 | Preamble to the Apache License, Version 2.0
414 |
415 |
416 |
417 | Complete license is available in the [`LICENSE`](LICENSE) file.
418 |
419 | ```text
420 | Licensed to the Apache Software Foundation (ASF) under one
421 | or more contributor license agreements. See the NOTICE file
422 | distributed with this work for additional information
423 | regarding copyright ownership. The ASF licenses this file
424 | to you under the Apache License, Version 2.0 (the
425 | "License"); you may not use this file except in compliance
426 | with the License. You may obtain a copy of the License at
427 |
428 | https://www.apache.org/licenses/LICENSE-2.0
429 |
430 | Unless required by applicable law or agreed to in writing,
431 | software distributed under the License is distributed on an
432 | "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
433 | KIND, either express or implied. See the License for the
434 | specific language governing permissions and limitations
435 | under the License.
436 | ```
437 |
438 |
439 | ## Trademarks
440 |
441 | All other trademarks referenced herein are the property of their respective owners.
442 |
443 |
444 | ---
445 | Copyright © 2017-2025 [Cloud Posse, LLC](https://cpco.io/copyright)
446 |
447 |
448 |
449 |
450 |
451 |
--------------------------------------------------------------------------------
/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-eks-workers
8 | # Logo for this project
9 | #logo: docs/logo.png
10 |
11 | # License of this project
12 | license: "APACHE2"
13 | # Canonical GitHub repo
14 | github_repo: cloudposse/terraform-aws-eks-workers
15 | # Badges to display
16 | badges:
17 | - name: Latest Release
18 | image: https://img.shields.io/github/release/cloudposse/terraform-aws-eks-workers.svg?style=for-the-badge
19 | url: https://github.com/cloudposse/terraform-aws-eks-workers/releases/latest
20 | - name: Last Updated
21 | image: https://img.shields.io/github/last-commit/cloudposse/terraform-aws-eks-workers.svg?style=for-the-badge
22 | url: https://github.com/cloudposse/terraform-aws-eks-workers/commits
23 | - name: Slack Community
24 | image: https://slack.cloudposse.com/for-the-badge.svg
25 | url: https://cloudposse.com/slack
26 |
27 | # List any related terraform modules that this module may be used with or that this module depends on.
28 | related:
29 | - name: "terraform-aws-ec2-autoscale-group"
30 | description: "Terraform module to provision Auto Scaling Group and Launch Template on AWS"
31 | url: "https://github.com/cloudposse/terraform-aws-ec2-autoscale-group"
32 | - name: "terraform-aws-ecs-container-definition"
33 | description: "Terraform module to generate well-formed JSON documents (container definitions) that are passed to the aws_ecs_task_definition Terraform resource"
34 | url: "https://github.com/cloudposse/terraform-aws-ecs-container-definition"
35 | - name: "terraform-aws-ecs-alb-service-task"
36 | description: "Terraform module which implements an ECS service which exposes a web service via ALB"
37 | url: "https://github.com/cloudposse/terraform-aws-ecs-alb-service-task"
38 | - name: "terraform-aws-ecs-web-app"
39 | description: "Terraform module that implements a web app on ECS and supports autoscaling, CI/CD, monitoring, ALB integration, and much more"
40 | url: "https://github.com/cloudposse/terraform-aws-ecs-web-app"
41 | - name: "terraform-aws-ecs-codepipeline"
42 | description: "Terraform module for CI/CD with AWS Code Pipeline and Code Build for ECS"
43 | url: "https://github.com/cloudposse/terraform-aws-ecs-codepipeline"
44 | - name: "terraform-aws-ecs-cloudwatch-autoscaling"
45 | description: "Terraform module to autoscale ECS Service based on CloudWatch metrics"
46 | url: "https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-autoscaling"
47 | - name: "terraform-aws-ecs-cloudwatch-sns-alarms"
48 | description: "Terraform module to create CloudWatch Alarms on ECS Service level metrics"
49 | url: "https://github.com/cloudposse/terraform-aws-ecs-cloudwatch-sns-alarms"
50 | - name: "terraform-aws-ec2-instance"
51 | description: "Terraform module for providing a general purpose EC2 instance"
52 | url: "https://github.com/cloudposse/terraform-aws-ec2-instance"
53 | - name: "terraform-aws-ec2-instance-group"
54 | description: "Terraform module for provisioning multiple general purpose EC2 hosts for stateful applications"
55 | url: "https://github.com/cloudposse/terraform-aws-ec2-instance-group"
56 | # Short description of this project
57 | description: |-
58 | Terraform module to provision AWS resources to run EC2 worker nodes for [Elastic Kubernetes Service](https://aws.amazon.com/eks/).
59 |
60 | Instantiate it multiple times to create many EKS worker node pools with specific settings such as GPUs, EC2 instance types, or autoscale parameters.
61 | introduction: |-
62 | The module provisions the following resources:
63 |
64 | - IAM Role and Instance Profile to allow Kubernetes nodes to access other AWS services
65 | - Security Group with rules for EKS workers to allow networking traffic
66 | - AutoScaling Group with Launch Template to configure and launch worker instances
67 | - AutoScaling Policies and CloudWatch Metric Alarms to monitor CPU utilization on the EC2 instances and scale the number of instance in the AutoScaling Group up or down.
68 | If you don't want to use the provided functionality, or want to provide your own policies, disable it by setting the variable `autoscaling_policies_enabled` to `"false"`.
69 | # How to use this project
70 | usage: |2-
71 |
72 | For a complete example, see [examples/complete](examples/complete)
73 |
74 | ```hcl
75 | provider "aws" {
76 | region = var.region
77 | }
78 |
79 | locals {
80 | # The usage of the specific kubernetes.io/cluster/* resource tags below are required
81 | # for EKS and Kubernetes to discover and manage networking resources
82 | # https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#base-vpc-networking
83 | tags = merge(var.tags, map("kubernetes.io/cluster/${var.cluster_name}", "shared"))
84 | }
85 |
86 | module "vpc" {
87 | source = "cloudposse/vpc/aws"
88 | version = "2.1.1"
89 |
90 | namespace = var.namespace
91 | stage = var.stage
92 | name = var.name
93 |
94 | ipv4_primary_cidr_block = "172.16.0.0/16"
95 | tags = local.tags
96 | }
97 |
98 | module "subnets" {
99 | source = "cloudposse/dynamic-subnets/aws"
100 | version = "2.4.1"
101 |
102 | namespace = var.namespace
103 | stage = var.stage
104 | name = var.name
105 |
106 | availability_zones = var.availability_zones
107 | vpc_id = module.vpc.vpc_id
108 | igw_id = [module.vpc.igw_id]
109 | ipv4_cidr_block = [module.vpc.vpc_cidr_block]
110 | nat_gateway_enabled = false
111 | nat_instance_enabled = false
112 | tags = local.tags
113 | }
114 |
115 | module "eks_workers" {
116 | source = "cloudposse/eks-workers/aws"
117 | # Cloud Posse recommends pinning every module to a specific version
118 | # version = "x.x.x"
119 | namespace = var.namespace
120 | stage = var.stage
121 | name = var.name
122 | instance_type = var.instance_type
123 | vpc_id = module.vpc.vpc_id
124 | subnet_ids = module.subnets.public_subnet_ids
125 | health_check_type = var.health_check_type
126 | min_size = var.min_size
127 | max_size = var.max_size
128 | wait_for_capacity_timeout = var.wait_for_capacity_timeout
129 | cluster_name = var.cluster_name
130 | cluster_endpoint = var.cluster_endpoint
131 | cluster_certificate_authority_data = var.cluster_certificate_authority_data
132 | cluster_security_group_id = var.cluster_security_group_id
133 |
134 | # Auto-scaling policies and CloudWatch metric alarms
135 | autoscaling_policies_enabled = var.autoscaling_policies_enabled
136 | cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent
137 | cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent
138 | }
139 | ```
140 | include: []
141 | contributors: []
142 |
--------------------------------------------------------------------------------
/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 |
--------------------------------------------------------------------------------
/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 | availability_zones = ["us-east-2a", "us-east-2b"]
4 |
5 | namespace = "eg"
6 |
7 | stage = "test"
8 |
9 | name = "suite"
10 |
11 | instance_type = "t2.small"
12 |
13 | health_check_type = "EC2"
14 |
15 | wait_for_capacity_timeout = "10m"
16 |
17 | max_size = 3
18 |
19 | min_size = 2
20 |
21 | autoscaling_policies_enabled = true
22 |
23 | cpu_utilization_high_threshold_percent = 80
24 |
25 | cpu_utilization_low_threshold_percent = 20
26 |
27 | cluster_name = "eg-test-eks-workers-cluster"
28 |
29 | cluster_endpoint = ""
30 |
31 | cluster_certificate_authority_data = ""
32 |
33 | cluster_security_group_ingress_enabled = false
34 |
--------------------------------------------------------------------------------
/examples/complete/main.tf:
--------------------------------------------------------------------------------
1 | provider "aws" {
2 | region = var.region
3 | }
4 |
5 | locals {
6 | # The usage of the specific kubernetes.io/cluster/* resource tags below are required
7 | # for EKS and Kubernetes to discover and manage networking resources
8 | # https://www.terraform.io/docs/providers/aws/guides/eks-getting-started.html#base-vpc-networking
9 | tags = { "kubernetes.io/cluster/${var.cluster_name}" = "shared" }
10 | }
11 |
12 | module "vpc" {
13 | source = "cloudposse/vpc/aws"
14 | version = "2.1.1"
15 |
16 | ipv4_primary_cidr_block = "172.16.0.0/16"
17 | tags = local.tags
18 |
19 | context = module.this.context
20 | }
21 |
22 | module "subnets" {
23 | source = "cloudposse/dynamic-subnets/aws"
24 | version = "2.4.1"
25 |
26 | availability_zones = var.availability_zones
27 | vpc_id = module.vpc.vpc_id
28 | igw_id = [module.vpc.igw_id]
29 | ipv4_cidr_block = [module.vpc.vpc_cidr_block]
30 | nat_gateway_enabled = false
31 | nat_instance_enabled = false
32 |
33 | context = module.this.context
34 | }
35 |
36 | module "eks_workers" {
37 | source = "../../"
38 |
39 | instance_type = var.instance_type
40 | vpc_id = module.vpc.vpc_id
41 | subnet_ids = module.subnets.public_subnet_ids
42 | health_check_type = var.health_check_type
43 | min_size = var.min_size
44 | max_size = var.max_size
45 | wait_for_capacity_timeout = var.wait_for_capacity_timeout
46 | cluster_name = var.cluster_name
47 | cluster_endpoint = var.cluster_endpoint
48 | cluster_certificate_authority_data = var.cluster_certificate_authority_data
49 | cluster_security_group_id = var.cluster_security_group_id
50 | cluster_security_group_ingress_enabled = var.cluster_security_group_ingress_enabled
51 | bootstrap_extra_args = "--use-max-pods false"
52 | kubelet_extra_args = "--node-labels=purpose=ci-worker"
53 |
54 | # Auto-scaling policies and CloudWatch metric alarms
55 | autoscaling_policies_enabled = var.autoscaling_policies_enabled
56 | cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent
57 | cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent
58 |
59 | context = module.this.context
60 | }
61 |
--------------------------------------------------------------------------------
/examples/complete/outputs.tf:
--------------------------------------------------------------------------------
1 | output "public_subnet_cidrs" {
2 | value = module.subnets.public_subnet_cidrs
3 | description = "Public subnet CIDRs"
4 | }
5 |
6 | output "private_subnet_cidrs" {
7 | value = module.subnets.private_subnet_cidrs
8 | description = "Private subnet CIDRs"
9 | }
10 |
11 | output "vpc_cidr" {
12 | value = module.vpc.vpc_cidr_block
13 | description = "VPC ID"
14 | }
15 |
16 | output "launch_template_id" {
17 | description = "ID of the launch template"
18 | value = module.eks_workers.launch_template_id
19 | }
20 |
21 | output "launch_template_arn" {
22 | description = "ARN of the launch template"
23 | value = module.eks_workers.launch_template_arn
24 | }
25 |
26 | output "autoscaling_group_id" {
27 | description = "The AutoScaling Group ID"
28 | value = module.eks_workers.autoscaling_group_id
29 | }
30 |
31 | output "autoscaling_group_name" {
32 | description = "The AutoScaling Group name"
33 | value = module.eks_workers.autoscaling_group_name
34 | }
35 |
36 | output "autoscaling_group_tags" {
37 | description = "A list of tag settings associated with the AutoScaling Group"
38 | value = module.eks_workers.autoscaling_group_tags
39 | }
40 |
41 | output "autoscaling_group_arn" {
42 | description = "ARN of the AutoScaling Group"
43 | value = module.eks_workers.autoscaling_group_arn
44 | }
45 |
46 | output "autoscaling_group_min_size" {
47 | description = "The minimum size of the AutoScaling Group"
48 | value = module.eks_workers.autoscaling_group_min_size
49 | }
50 |
51 | output "autoscaling_group_max_size" {
52 | description = "The maximum size of the AutoScaling Group"
53 | value = module.eks_workers.autoscaling_group_max_size
54 | }
55 |
56 | output "autoscaling_group_desired_capacity" {
57 | description = "The number of Amazon EC2 instances that should be running in the group"
58 | value = module.eks_workers.autoscaling_group_desired_capacity
59 | }
60 |
61 | output "autoscaling_group_default_cooldown" {
62 | description = "Time between a scaling activity and the succeeding scaling activity"
63 | value = module.eks_workers.autoscaling_group_default_cooldown
64 | }
65 |
66 | output "autoscaling_group_health_check_grace_period" {
67 | description = "Time after instance comes into service before checking health"
68 | value = module.eks_workers.autoscaling_group_health_check_grace_period
69 | }
70 |
71 | output "autoscaling_group_health_check_type" {
72 | description = "`EC2` or `ELB`. Controls how health checking is done"
73 | value = module.eks_workers.autoscaling_group_health_check_type
74 | }
75 |
76 | output "security_group_id" {
77 | description = "ID of the worker nodes Security Group"
78 | value = module.eks_workers.security_group_id
79 | }
80 |
81 | output "security_group_arn" {
82 | description = "ARN of the worker nodes Security Group"
83 | value = module.eks_workers.security_group_arn
84 | }
85 |
86 | output "security_group_name" {
87 | description = "Name of the worker nodes Security Group"
88 | value = module.eks_workers.security_group_name
89 | }
90 |
91 | output "workers_role_arn" {
92 | description = "ARN of the worker nodes IAM role"
93 | value = module.eks_workers.workers_role_arn
94 | }
95 |
96 | output "workers_role_name" {
97 | description = "Name of the worker nodes IAM role"
98 | value = module.eks_workers.workers_role_name
99 | }
100 |
--------------------------------------------------------------------------------
/examples/complete/variables.tf:
--------------------------------------------------------------------------------
1 | variable "region" {
2 | type = string
3 | description = "AWS Region"
4 | }
5 |
6 | variable "availability_zones" {
7 | type = list(string)
8 | description = "List of availability zones"
9 | }
10 |
11 |
12 | variable "cluster_name" {
13 | type = string
14 | description = "The name of the EKS cluster"
15 | }
16 |
17 | variable "cluster_endpoint" {
18 | type = string
19 | description = "EKS cluster endpoint"
20 | }
21 |
22 | variable "cluster_certificate_authority_data" {
23 | type = string
24 | description = "The base64 encoded certificate data required to communicate with the cluster"
25 | }
26 |
27 | variable "cluster_security_group_ingress_enabled" {
28 | type = bool
29 | description = "Whether to enable the EKS cluster Security Group as ingress to workers Security Group"
30 | }
31 |
32 | variable "cluster_security_group_id" {
33 | type = string
34 | description = "Security Group ID of the EKS cluster"
35 | default = ""
36 | }
37 |
38 | variable "instance_type" {
39 | type = string
40 | description = "Instance type to launch"
41 | }
42 |
43 | variable "max_size" {
44 | type = number
45 | description = "The maximum size of the autoscale group"
46 | }
47 |
48 | variable "min_size" {
49 | type = number
50 | description = "The minimum size of the autoscale group"
51 | }
52 |
53 | variable "health_check_type" {
54 | type = string
55 | description = "Controls how health checking is done. Valid values are `EC2` or `ELB`"
56 | }
57 |
58 | variable "wait_for_capacity_timeout" {
59 | type = string
60 | description = "A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to '0' causes Terraform to skip all Capacity Waiting behavior"
61 | }
62 |
63 | variable "autoscaling_policies_enabled" {
64 | type = bool
65 | description = "Whether to create `aws_autoscaling_policy` and `aws_cloudwatch_metric_alarm` resources to control Auto Scaling"
66 | }
67 |
68 | variable "cpu_utilization_high_threshold_percent" {
69 | type = number
70 | description = "The value against which the specified statistic is compared"
71 | }
72 |
73 | variable "cpu_utilization_low_threshold_percent" {
74 | type = number
75 | description = "The value against which the specified statistic is compared"
76 | }
77 |
--------------------------------------------------------------------------------
/examples/complete/versions.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_version = ">= 1.1.0"
3 |
4 | required_providers {
5 | aws = {
6 | source = "hashicorp/aws"
7 | version = ">= 5.0"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/main.tf:
--------------------------------------------------------------------------------
1 | locals {
2 | enabled = module.this.enabled
3 | tags = {
4 | "kubernetes.io/cluster/${var.cluster_name}" = "owned"
5 | }
6 |
7 | workers_role_arn = var.use_existing_aws_iam_instance_profile ? join("", data.aws_iam_instance_profile.default[*].role_arn) : join("", aws_iam_role.default[*].arn)
8 | workers_role_name = var.use_existing_aws_iam_instance_profile ? join("", data.aws_iam_instance_profile.default[*].role_name) : join("", aws_iam_role.default[*].name)
9 |
10 | userdata = templatefile("${path.module}/userdata.tpl", {
11 | cluster_endpoint = var.cluster_endpoint
12 | certificate_authority_data = var.cluster_certificate_authority_data
13 | cluster_name = var.cluster_name
14 | bootstrap_extra_args = var.bootstrap_extra_args
15 | kubelet_extra_args = var.kubelet_extra_args
16 | before_cluster_joining_userdata = var.before_cluster_joining_userdata
17 | after_cluster_joining_userdata = var.after_cluster_joining_userdata
18 | })
19 | }
20 |
21 | module "label" {
22 | source = "cloudposse/label/null"
23 | version = "0.25.0"
24 |
25 | attributes = ["workers"]
26 | tags = local.tags
27 |
28 | context = module.this.context
29 | }
30 |
31 | data "aws_partition" "current" {}
32 |
33 | data "aws_iam_policy_document" "assume_role" {
34 | count = local.enabled && var.use_existing_aws_iam_instance_profile == false ? 1 : 0
35 |
36 | statement {
37 | effect = "Allow"
38 | actions = ["sts:AssumeRole"]
39 |
40 | principals {
41 | type = "Service"
42 | identifiers = ["ec2.amazonaws.com"]
43 | }
44 | }
45 | }
46 |
47 | resource "aws_iam_role" "default" {
48 | count = local.enabled && var.use_existing_aws_iam_instance_profile == false ? 1 : 0
49 | name = module.label.id
50 | assume_role_policy = join("", data.aws_iam_policy_document.assume_role[*].json)
51 | tags = module.label.tags
52 | }
53 |
54 | resource "aws_iam_role_policy_attachment" "amazon_eks_worker_node_policy" {
55 | count = local.enabled && var.use_existing_aws_iam_instance_profile == false ? 1 : 0
56 | policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonEKSWorkerNodePolicy"
57 | role = join("", aws_iam_role.default[*].name)
58 | }
59 |
60 | resource "aws_iam_role_policy_attachment" "amazon_eks_cni_policy" {
61 | count = local.enabled && var.use_existing_aws_iam_instance_profile == false ? 1 : 0
62 | policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonEKS_CNI_Policy"
63 | role = join("", aws_iam_role.default[*].name)
64 | }
65 |
66 | resource "aws_iam_role_policy_attachment" "amazon_ec2_container_registry_read_only" {
67 | count = local.enabled && var.use_existing_aws_iam_instance_profile == false ? 1 : 0
68 | policy_arn = "arn:${data.aws_partition.current.partition}:iam::aws:policy/AmazonEC2ContainerRegistryReadOnly"
69 | role = join("", aws_iam_role.default[*].name)
70 | }
71 |
72 | resource "aws_iam_role_policy_attachment" "existing_policies_attach_to_eks_workers_role" {
73 | count = local.enabled && var.use_existing_aws_iam_instance_profile == false ? var.workers_role_policy_arns_count : 0
74 | policy_arn = var.workers_role_policy_arns[count.index]
75 | role = join("", aws_iam_role.default[*].name)
76 | }
77 |
78 | resource "aws_iam_instance_profile" "default" {
79 | count = local.enabled && var.use_existing_aws_iam_instance_profile == false ? 1 : 0
80 | name = module.label.id
81 | role = join("", aws_iam_role.default[*].name)
82 | }
83 |
84 | resource "aws_security_group" "default" {
85 | count = local.enabled && var.use_existing_security_group == false ? 1 : 0
86 | name = module.label.id
87 | description = "Security Group for EKS worker nodes"
88 | vpc_id = var.vpc_id
89 | tags = module.label.tags
90 | }
91 |
92 | resource "aws_security_group_rule" "egress" {
93 | count = local.enabled && var.use_existing_security_group == false ? 1 : 0
94 | description = "Allow all egress traffic"
95 | from_port = 0
96 | to_port = 0
97 | protocol = "-1"
98 | cidr_blocks = ["0.0.0.0/0"]
99 | security_group_id = join("", aws_security_group.default[*].id)
100 | type = "egress"
101 | }
102 |
103 | resource "aws_security_group_rule" "ingress_self" {
104 | count = local.enabled && var.use_existing_security_group == false ? 1 : 0
105 | description = "Allow nodes to communicate with each other"
106 | from_port = 0
107 | to_port = 65535
108 | protocol = "-1"
109 | security_group_id = join("", aws_security_group.default[*].id)
110 | source_security_group_id = join("", aws_security_group.default[*].id)
111 | type = "ingress"
112 | }
113 |
114 | resource "aws_security_group_rule" "ingress_cluster" {
115 | count = local.enabled && var.cluster_security_group_ingress_enabled && var.use_existing_security_group == false ? 1 : 0
116 | description = "Allow worker kubelets and pods to receive communication from the cluster control plane"
117 | from_port = 0
118 | to_port = 65535
119 | protocol = "-1"
120 | security_group_id = join("", aws_security_group.default[*].id)
121 | source_security_group_id = var.cluster_security_group_id
122 | type = "ingress"
123 | }
124 |
125 | resource "aws_security_group_rule" "ingress_security_groups" {
126 | count = local.enabled && var.use_existing_security_group == false ? length(var.allowed_security_groups) : 0
127 | description = "Allow inbound traffic from existing Security Groups"
128 | from_port = 0
129 | to_port = 65535
130 | protocol = "-1"
131 | source_security_group_id = var.allowed_security_groups[count.index]
132 | security_group_id = join("", aws_security_group.default[*].id)
133 | type = "ingress"
134 | }
135 |
136 | resource "aws_security_group_rule" "ingress_cidr_blocks" {
137 | count = local.enabled && length(var.allowed_cidr_blocks) > 0 && var.use_existing_security_group == false ? 1 : 0
138 | description = "Allow inbound traffic from CIDR blocks"
139 | from_port = 0
140 | to_port = 0
141 | protocol = "-1"
142 | cidr_blocks = var.allowed_cidr_blocks
143 | security_group_id = join("", aws_security_group.default[*].id)
144 | type = "ingress"
145 | }
146 |
147 | data "aws_ami" "eks_worker" {
148 | count = local.enabled && var.use_custom_image_id == false ? 1 : 0
149 |
150 | most_recent = true
151 | name_regex = var.eks_worker_ami_name_regex
152 |
153 | filter {
154 | name = "name"
155 | values = [var.eks_worker_ami_name_filter]
156 | }
157 |
158 | owners = ["602401143452"] # Amazon
159 | }
160 |
161 | data "aws_iam_instance_profile" "default" {
162 | count = local.enabled && var.use_existing_aws_iam_instance_profile ? 1 : 0
163 | name = var.aws_iam_instance_profile_name
164 | }
165 |
166 | module "autoscale_group" {
167 | source = "cloudposse/ec2-autoscale-group/aws"
168 | version = "0.40.0"
169 |
170 | enabled = local.enabled
171 | tags = merge(local.tags, var.autoscaling_group_tags)
172 |
173 | image_id = var.use_custom_image_id ? var.image_id : join("", data.aws_ami.eks_worker[*].id)
174 | iam_instance_profile_name = var.use_existing_aws_iam_instance_profile == false ? join("", aws_iam_instance_profile.default[*].name) : var.aws_iam_instance_profile_name
175 |
176 | security_group_ids = compact(
177 | concat(
178 | [
179 | var.use_existing_security_group == false ? join("", aws_security_group.default[*].id) : var.workers_security_group_id
180 | ],
181 | var.additional_security_group_ids
182 | )
183 | )
184 |
185 | user_data_base64 = base64encode(local.userdata)
186 |
187 | instance_type = var.instance_type
188 | subnet_ids = var.subnet_ids
189 | min_size = var.min_size
190 | max_size = var.max_size
191 | associate_public_ip_address = var.associate_public_ip_address
192 | block_device_mappings = var.block_device_mappings
193 | credit_specification = var.credit_specification
194 | disable_api_termination = var.disable_api_termination
195 | ebs_optimized = var.ebs_optimized
196 | elastic_gpu_specifications = var.elastic_gpu_specifications
197 | instance_initiated_shutdown_behavior = var.instance_initiated_shutdown_behavior
198 | instance_market_options = var.instance_market_options
199 | mixed_instances_policy = var.mixed_instances_policy
200 | key_name = var.key_name
201 | placement = var.placement
202 | enable_monitoring = var.enable_monitoring
203 | load_balancers = var.load_balancers
204 | health_check_grace_period = var.health_check_grace_period
205 | health_check_type = var.health_check_type
206 | min_elb_capacity = var.min_elb_capacity
207 | wait_for_elb_capacity = var.wait_for_elb_capacity
208 | target_group_arns = var.target_group_arns
209 | default_cooldown = var.default_cooldown
210 | force_delete = var.force_delete
211 | termination_policies = var.termination_policies
212 | suspended_processes = var.suspended_processes
213 | placement_group = var.placement_group
214 | enabled_metrics = var.enabled_metrics
215 | metrics_granularity = var.metrics_granularity
216 | wait_for_capacity_timeout = var.wait_for_capacity_timeout
217 | protect_from_scale_in = var.protect_from_scale_in
218 | service_linked_role_arn = var.service_linked_role_arn
219 | autoscaling_policies_enabled = var.autoscaling_policies_enabled
220 | scale_up_cooldown_seconds = var.scale_up_cooldown_seconds
221 | scale_up_scaling_adjustment = var.scale_up_scaling_adjustment
222 | scale_up_adjustment_type = var.scale_up_adjustment_type
223 | scale_up_policy_type = var.scale_up_policy_type
224 | scale_down_cooldown_seconds = var.scale_down_cooldown_seconds
225 | scale_down_scaling_adjustment = var.scale_down_scaling_adjustment
226 | scale_down_adjustment_type = var.scale_down_adjustment_type
227 | scale_down_policy_type = var.scale_down_policy_type
228 | cpu_utilization_high_evaluation_periods = var.cpu_utilization_high_evaluation_periods
229 | cpu_utilization_high_period_seconds = var.cpu_utilization_high_period_seconds
230 | cpu_utilization_high_threshold_percent = var.cpu_utilization_high_threshold_percent
231 | cpu_utilization_high_statistic = var.cpu_utilization_high_statistic
232 | cpu_utilization_low_evaluation_periods = var.cpu_utilization_low_evaluation_periods
233 | cpu_utilization_low_period_seconds = var.cpu_utilization_low_period_seconds
234 | cpu_utilization_low_statistic = var.cpu_utilization_low_statistic
235 | cpu_utilization_low_threshold_percent = var.cpu_utilization_low_threshold_percent
236 | metadata_http_endpoint_enabled = var.metadata_http_endpoint_enabled
237 | metadata_http_put_response_hop_limit = var.metadata_http_put_response_hop_limit
238 | metadata_http_tokens_required = var.metadata_http_tokens_required
239 | max_instance_lifetime = var.max_instance_lifetime
240 |
241 | context = module.this.context
242 | }
243 |
--------------------------------------------------------------------------------
/outputs.tf:
--------------------------------------------------------------------------------
1 | output "launch_template_id" {
2 | description = "The ID of the launch template"
3 | value = module.autoscale_group.launch_template_id
4 | }
5 |
6 | output "launch_template_arn" {
7 | description = "ARN of the launch template"
8 | value = module.autoscale_group.launch_template_arn
9 | }
10 |
11 | output "autoscaling_group_id" {
12 | description = "The AutoScaling Group ID"
13 | value = module.autoscale_group.autoscaling_group_id
14 | }
15 |
16 | output "autoscaling_group_name" {
17 | description = "The AutoScaling Group name"
18 | value = module.autoscale_group.autoscaling_group_name
19 | }
20 |
21 | output "autoscaling_group_tags" {
22 | description = "A list of tag settings associated with the AutoScaling Group"
23 | value = module.autoscale_group.autoscaling_group_tags
24 | }
25 |
26 | output "autoscaling_group_arn" {
27 | description = "ARN of the AutoScaling Group"
28 | value = module.autoscale_group.autoscaling_group_arn
29 | }
30 |
31 | output "autoscaling_group_min_size" {
32 | description = "The minimum size of the AutoScaling Group"
33 | value = module.autoscale_group.autoscaling_group_min_size
34 | }
35 |
36 | output "autoscaling_group_max_size" {
37 | description = "The maximum size of the AutoScaling Group"
38 | value = module.autoscale_group.autoscaling_group_max_size
39 | }
40 |
41 | output "autoscaling_group_desired_capacity" {
42 | description = "The number of Amazon EC2 instances that should be running in the group"
43 | value = module.autoscale_group.autoscaling_group_desired_capacity
44 | }
45 |
46 | output "autoscaling_group_default_cooldown" {
47 | description = "Time between a scaling activity and the succeeding scaling activity"
48 | value = module.autoscale_group.autoscaling_group_default_cooldown
49 | }
50 |
51 | output "autoscaling_group_health_check_grace_period" {
52 | description = "Time after instance comes into service before checking health"
53 | value = module.autoscale_group.autoscaling_group_health_check_grace_period
54 | }
55 |
56 | output "autoscaling_group_health_check_type" {
57 | description = "`EC2` or `ELB`. Controls how health checking is done"
58 | value = module.autoscale_group.autoscaling_group_health_check_type
59 | }
60 |
61 | output "security_group_id" {
62 | description = "ID of the worker nodes Security Group"
63 | value = join("", aws_security_group.default[*].id)
64 | }
65 |
66 | output "security_group_arn" {
67 | description = "ARN of the worker nodes Security Group"
68 | value = join("", aws_security_group.default[*].arn)
69 | }
70 |
71 | output "security_group_name" {
72 | description = "Name of the worker nodes Security Group"
73 | value = join("", aws_security_group.default[*].name)
74 | }
75 |
76 | output "workers_role_arn" {
77 | description = "ARN of the worker nodes IAM role"
78 | value = local.workers_role_arn
79 | }
80 |
81 | output "workers_role_name" {
82 | description = "Name of the worker nodes IAM role"
83 | value = local.workers_role_name
84 | }
85 |
--------------------------------------------------------------------------------
/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 60m
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 | "github.com/gruntwork-io/terratest/modules/logger"
5 | "github.com/gruntwork-io/terratest/modules/random"
6 | "github.com/gruntwork-io/terratest/modules/terraform"
7 | test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
8 | "github.com/stretchr/testify/assert"
9 | "os"
10 | "regexp"
11 | "strings"
12 | "testing"
13 | )
14 |
15 | type ASGTagStruct struct {
16 | Key string `json:"key"`
17 | Value string `json:"value"`
18 | PropagateAtLaunch bool `json:"propagate_at_launch"`
19 | }
20 |
21 | func cleanup(t *testing.T, terraformOptions *terraform.Options, tempTestFolder string) {
22 | terraform.Destroy(t, terraformOptions)
23 | os.RemoveAll(tempTestFolder)
24 | }
25 |
26 | // Test the Terraform module in examples/complete using Terratest.
27 | func TestExamplesComplete(t *testing.T) {
28 | t.Parallel()
29 | randID := strings.ToLower(random.UniqueId())
30 | attributes := []string{randID}
31 |
32 | rootFolder := "../../"
33 | terraformFolderRelativeToRoot := "examples/complete"
34 | varFiles := []string{"fixtures.us-east-2.tfvars"}
35 |
36 | tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
37 |
38 | terraformOptions := &terraform.Options{
39 | // The path to where our Terraform code is located
40 | TerraformDir: tempTestFolder,
41 | Upgrade: true,
42 | // Variables to pass to our Terraform code using -var-file options
43 | VarFiles: varFiles,
44 | Vars: map[string]interface{}{
45 | "attributes": attributes,
46 | },
47 | }
48 | // Keep the output quiet
49 | if !testing.Verbose() {
50 | terraformOptions.Logger = logger.Discard
51 | }
52 |
53 | // At the end of the test, run `terraform destroy` to clean up any resources that were created
54 | defer cleanup(t, terraformOptions, tempTestFolder)
55 |
56 | // This will run `terraform init` and `terraform apply` and fail the test if there are any errors
57 | terraform.InitAndApply(t, terraformOptions)
58 |
59 | expectedPrefix := "eg-test-suite-" + randID
60 |
61 | // Run `terraform output` to get the value of an output variable
62 | vpcCidr := terraform.Output(t, terraformOptions, "vpc_cidr")
63 | // Verify we're getting back the outputs we expect
64 | assert.Equal(t, "172.16.0.0/16", vpcCidr)
65 |
66 | // Run `terraform output` to get the value of an output variable
67 | privateSubnetCidrs := terraform.OutputList(t, terraformOptions, "private_subnet_cidrs")
68 | // Verify we're getting back the outputs we expect
69 | assert.Equal(t, []string{"172.16.0.0/19", "172.16.32.0/19"}, privateSubnetCidrs)
70 |
71 | // Run `terraform output` to get the value of an output variable
72 | publicSubnetCidrs := terraform.OutputList(t, terraformOptions, "public_subnet_cidrs")
73 | // Verify we're getting back the outputs we expect
74 | assert.Equal(t, []string{"172.16.96.0/19", "172.16.128.0/19"}, publicSubnetCidrs)
75 |
76 | // Run `terraform output` to get the value of an output variable
77 | // autoscaling_group_name = eg-test-suite-20210416185727403200000006
78 | autoscalingGroupName := terraform.Output(t, terraformOptions, "autoscaling_group_name")
79 | // Verify we're getting back the outputs we expect
80 | assert.Regexp(t, regexp.MustCompile(`^`+expectedPrefix+`-`), autoscalingGroupName, "Autoscaling Group name should be our expected prefix plus a random suffix")
81 |
82 | // Run `terraform output` to get the value of an output variable
83 | var tags []ASGTagStruct
84 |
85 | terraform.OutputStruct(t, terraformOptions, "autoscaling_group_tags", &tags)
86 | expectedTag := ASGTagStruct{
87 | Key: "Name",
88 | Value: expectedPrefix,
89 | PropagateAtLaunch: true,
90 | }
91 |
92 | assert.Contains(t, tags, expectedTag, `Tag "Name" should match eks-workers module ID`)
93 |
94 | // "kubernetes.io/cluster/${var.cluster_name}" = "owned"
95 | expectedTag = ASGTagStruct{
96 | Key: "kubernetes.io/cluster/eg-test-eks-workers-cluster",
97 | Value: "owned",
98 | PropagateAtLaunch: true,
99 | }
100 |
101 | assert.Contains(t, tags, expectedTag, `Tag "kubernetes.io/cluster/eg-test-eks-workers-cluster" = "owned" should be present and propagate`)
102 |
103 | // Run `terraform output` to get the value of an output variable
104 | launchTemplateArn := terraform.Output(t, terraformOptions, "launch_template_arn")
105 | launchTemplateId := terraform.Output(t, terraformOptions, "launch_template_id")
106 | // Verify we're getting back the outputs we expect, but allow for any region or account
107 | // arn:aws:ec2:us-east-2:126450723953:launch-template/
108 | assert.Regexp(t, "arn:aws:ec2:[^:]+:\\d{12}:launch-template/"+launchTemplateId, launchTemplateArn)
109 |
110 | // Run `terraform output` to get the value of an output variable
111 | securityGroupName := terraform.Output(t, terraformOptions, "security_group_name")
112 | // Verify we're getting back the outputs we expect
113 | assert.Equal(t, expectedPrefix+"-workers", securityGroupName)
114 |
115 | // Run `terraform output` to get the value of an output variable
116 | workerRoleName := terraform.Output(t, terraformOptions, "workers_role_name")
117 | // Verify we're getting back the outputs we expect
118 | assert.Equal(t, expectedPrefix+"-workers", workerRoleName)
119 | }
120 |
121 | func TestExamplesCompleteDisabled(t *testing.T) {
122 | t.Parallel()
123 | randID := strings.ToLower(random.UniqueId())
124 | attributes := []string{randID}
125 |
126 | rootFolder := "../../"
127 | terraformFolderRelativeToRoot := "examples/complete"
128 | varFiles := []string{"fixtures.us-east-2.tfvars"}
129 |
130 | tempTestFolder := test_structure.CopyTerraformFolderToTemp(t, rootFolder, terraformFolderRelativeToRoot)
131 |
132 | terraformOptions := &terraform.Options{
133 | // The path to where our Terraform code is located
134 | TerraformDir: tempTestFolder,
135 | Upgrade: true,
136 | // Variables to pass to our Terraform code using -var-file options
137 | VarFiles: varFiles,
138 | Vars: map[string]interface{}{
139 | "attributes": attributes,
140 | "enabled": "false",
141 | },
142 | }
143 | // Keep the output quiet
144 | if !testing.Verbose() {
145 | terraformOptions.Logger = logger.Discard
146 | }
147 |
148 | // At the end of the test, run `terraform destroy` to clean up any resources that were created
149 | defer cleanup(t, terraformOptions, tempTestFolder)
150 |
151 | // This will run `terraform init` and `terraform apply` and fail the test if there are any errors
152 | terraform.InitAndApply(t, terraformOptions)
153 |
154 | // Get all the output and lookup a field. Pass if the field is missing or empty.
155 | datadogMonitorNames := terraform.OutputAll(t, terraformOptions)["datadog_monitor_names"]
156 |
157 | // Verify we're getting back the outputs we expect
158 | assert.Empty(t, datadogMonitorNames, "When disabled, module should have no outputs.")
159 | }
160 |
--------------------------------------------------------------------------------
/test/src/go.mod:
--------------------------------------------------------------------------------
1 | module github.com/cloudposse/terraform-aws-eks-workers
2 |
3 | go 1.21
4 |
5 | require (
6 | github.com/gruntwork-io/terratest v0.46.11
7 | github.com/stretchr/testify v1.8.4
8 | )
9 |
10 | require (
11 | cloud.google.com/go v0.110.0 // indirect
12 | cloud.google.com/go/compute v1.19.1 // indirect
13 | cloud.google.com/go/compute/metadata v0.2.3 // indirect
14 | cloud.google.com/go/iam v0.13.0 // indirect
15 | cloud.google.com/go/storage v1.28.1 // 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/emicklei/go-restful/v3 v3.9.0 // indirect
24 | github.com/go-errors/errors v1.0.2-0.20180813162953-d98b870cc4e0 // indirect
25 | github.com/go-logr/logr v1.2.4 // indirect
26 | github.com/go-openapi/jsonpointer v0.19.6 // indirect
27 | github.com/go-openapi/jsonreference v0.20.2 // indirect
28 | github.com/go-openapi/swag v0.22.3 // indirect
29 | github.com/go-sql-driver/mysql v1.4.1 // indirect
30 | github.com/gogo/protobuf v1.3.2 // indirect
31 | github.com/golang/groupcache v0.0.0-20210331224755-41bb18bfe9da // indirect
32 | github.com/golang/protobuf v1.5.3 // indirect
33 | github.com/google/gnostic-models v0.6.8 // indirect
34 | github.com/google/go-cmp v0.5.9 // indirect
35 | github.com/google/gofuzz v1.2.0 // indirect
36 | github.com/google/uuid v1.3.0 // indirect
37 | github.com/googleapis/enterprise-certificate-proxy v0.2.3 // indirect
38 | github.com/googleapis/gax-go/v2 v2.7.1 // indirect
39 | github.com/gruntwork-io/go-commons v0.8.0 // indirect
40 | github.com/hashicorp/errwrap v1.0.0 // indirect
41 | github.com/hashicorp/go-cleanhttp v0.5.2 // indirect
42 | github.com/hashicorp/go-getter v1.7.5 // indirect
43 | github.com/hashicorp/go-multierror v1.1.0 // indirect
44 | github.com/hashicorp/go-safetemp v1.0.0 // indirect
45 | github.com/hashicorp/go-version v1.6.0 // indirect
46 | github.com/hashicorp/hcl/v2 v2.9.1 // indirect
47 | github.com/hashicorp/terraform-json v0.13.0 // indirect
48 | github.com/imdario/mergo v0.3.11 // indirect
49 | github.com/jinzhu/copier v0.0.0-20190924061706-b57f9002281a // indirect
50 | github.com/jmespath/go-jmespath v0.4.0 // indirect
51 | github.com/josharian/intern v1.0.0 // indirect
52 | github.com/json-iterator/go v1.1.12 // indirect
53 | github.com/klauspost/compress v1.15.11 // indirect
54 | github.com/mailru/easyjson v0.7.7 // indirect
55 | github.com/mattn/go-zglob v0.0.2-0.20190814121620-e3c945676326 // indirect
56 | github.com/mitchellh/go-homedir v1.1.0 // indirect
57 | github.com/mitchellh/go-testing-interface v1.14.1 // indirect
58 | github.com/mitchellh/go-wordwrap v1.0.1 // indirect
59 | github.com/moby/spdystream v0.2.0 // indirect
60 | github.com/modern-go/concurrent v0.0.0-20180306012644-bacd9c7ef1dd // indirect
61 | github.com/modern-go/reflect2 v1.0.2 // indirect
62 | github.com/munnerz/goautoneg v0.0.0-20191010083416-a7dc8b61c822 // indirect
63 | github.com/pmezard/go-difflib v1.0.0 // indirect
64 | github.com/pquerna/otp v1.2.0 // indirect
65 | github.com/russross/blackfriday/v2 v2.1.0 // indirect
66 | github.com/spf13/pflag v1.0.5 // indirect
67 | github.com/tmccombs/hcl2json v0.3.3 // indirect
68 | github.com/ulikunitz/xz v0.5.10 // indirect
69 | github.com/urfave/cli v1.22.2 // indirect
70 | github.com/zclconf/go-cty v1.9.1 // indirect
71 | go.opencensus.io v0.24.0 // indirect
72 | golang.org/x/crypto v0.31.0 // indirect
73 | golang.org/x/net v0.23.0 // indirect
74 | golang.org/x/oauth2 v0.8.0 // indirect
75 | golang.org/x/sys v0.28.0 // indirect
76 | golang.org/x/term v0.27.0 // indirect
77 | golang.org/x/text v0.21.0 // indirect
78 | golang.org/x/time v0.3.0 // indirect
79 | golang.org/x/xerrors v0.0.0-20220907171357-04be3eba64a2 // indirect
80 | google.golang.org/api v0.114.0 // indirect
81 | google.golang.org/appengine v1.6.7 // indirect
82 | google.golang.org/genproto v0.0.0-20230410155749-daa745c078e1 // indirect
83 | google.golang.org/grpc v1.56.3 // indirect
84 | google.golang.org/protobuf v1.33.0 // indirect
85 | gopkg.in/inf.v0 v0.9.1 // indirect
86 | gopkg.in/yaml.v2 v2.4.0 // indirect
87 | gopkg.in/yaml.v3 v3.0.1 // indirect
88 | k8s.io/api v0.28.4 // indirect
89 | k8s.io/apimachinery v0.28.4 // indirect
90 | k8s.io/client-go v0.28.4 // indirect
91 | k8s.io/klog/v2 v2.100.1 // indirect
92 | k8s.io/kube-openapi v0.0.0-20230717233707-2695361300d9 // indirect
93 | k8s.io/utils v0.0.0-20230406110748-d93618cff8a2 // indirect
94 | sigs.k8s.io/json v0.0.0-20221116044647-bc3834ca7abd // indirect
95 | sigs.k8s.io/structured-merge-diff/v4 v4.2.3 // indirect
96 | sigs.k8s.io/yaml v1.3.0 // indirect
97 | )
98 |
--------------------------------------------------------------------------------
/userdata.tpl:
--------------------------------------------------------------------------------
1 | #!/bin/bash
2 |
3 | # userdata for EKS worker nodes to properly configure Kubernetes applications on EC2 instances
4 | # https://docs.aws.amazon.com/eks/latest/userguide/launch-workers.html
5 | # https://aws.amazon.com/blogs/opensource/improvements-eks-worker-node-provisioning/
6 | # https://github.com/awslabs/amazon-eks-ami/blob/master/files/bootstrap.sh#L97
7 |
8 | ${before_cluster_joining_userdata}
9 |
10 | export KUBELET_EXTRA_ARGS="${kubelet_extra_args}"
11 |
12 | /etc/eks/bootstrap.sh --apiserver-endpoint '${cluster_endpoint}' --b64-cluster-ca '${certificate_authority_data}' ${bootstrap_extra_args} '${cluster_name}'
13 |
14 | ${after_cluster_joining_userdata}
15 |
--------------------------------------------------------------------------------
/variables.tf:
--------------------------------------------------------------------------------
1 | variable "cluster_name" {
2 | type = string
3 | description = "The name of the EKS cluster"
4 | }
5 |
6 | variable "cluster_endpoint" {
7 | type = string
8 | description = "EKS cluster endpoint"
9 | }
10 |
11 | variable "cluster_certificate_authority_data" {
12 | type = string
13 | description = "The base64 encoded certificate data required to communicate with the cluster"
14 | }
15 |
16 | variable "cluster_security_group_ingress_enabled" {
17 | type = bool
18 | description = "Whether to enable the EKS cluster Security Group as ingress to workers Security Group"
19 | default = true
20 | }
21 |
22 | variable "cluster_security_group_id" {
23 | type = string
24 | description = "Security Group ID of the EKS cluster"
25 | }
26 |
27 | variable "vpc_id" {
28 | type = string
29 | description = "VPC ID for the EKS cluster"
30 | }
31 |
32 | variable "allowed_security_groups" {
33 | type = list(string)
34 | default = []
35 | description = "List of Security Group IDs to be allowed to connect to the worker nodes"
36 | }
37 |
38 | variable "allowed_cidr_blocks" {
39 | type = list(string)
40 | default = []
41 | description = "List of CIDR blocks to be allowed to connect to the worker nodes"
42 | }
43 |
44 | variable "metadata_http_endpoint_enabled" {
45 | type = bool
46 | default = true
47 | description = "Set false to disable the Instance Metadata Service."
48 | }
49 |
50 | variable "metadata_http_put_response_hop_limit" {
51 | type = number
52 | default = 2
53 | description = <<-EOT
54 | The desired HTTP PUT response hop limit (between 1 and 64) for Instance Metadata Service requests.
55 | The default is `2` to support containerized workloads.
56 | EOT
57 | }
58 |
59 | variable "metadata_http_tokens_required" {
60 | type = bool
61 | default = true
62 | description = "Set true to require IMDS session tokens, disabling Instance Metadata Service Version 1."
63 | }
64 |
65 | variable "instance_initiated_shutdown_behavior" {
66 | type = string
67 | description = "Shutdown behavior for the instances. Can be `stop` or `terminate`"
68 | default = "terminate"
69 | }
70 |
71 | variable "image_id" {
72 | type = string
73 | description = "EC2 image ID to launch. If not provided, the module will lookup the most recent EKS AMI. See https://docs.aws.amazon.com/eks/latest/userguide/eks-optimized-ami.html for more details on EKS-optimized images"
74 | default = ""
75 | }
76 |
77 | variable "use_custom_image_id" {
78 | type = bool
79 | description = "If set to `true`, will use variable `image_id` for the EKS workers inside autoscaling group"
80 | default = false
81 | }
82 |
83 | variable "eks_worker_ami_name_filter" {
84 | type = string
85 | description = "AMI name filter to lookup the most recent EKS AMI if `image_id` is not provided"
86 | default = "amazon-eks-node-*"
87 | }
88 |
89 | variable "eks_worker_ami_name_regex" {
90 | type = string
91 | description = "A regex string to apply to the AMI list returned by AWS"
92 | default = "^amazon-eks-node-[0-9,.]+-v[0-9]{8}$"
93 | }
94 |
95 | variable "instance_type" {
96 | type = string
97 | description = "Instance type to launch"
98 | }
99 |
100 | variable "key_name" {
101 | type = string
102 | description = "SSH key name that should be used for the instance"
103 | default = ""
104 | }
105 |
106 | variable "associate_public_ip_address" {
107 | type = bool
108 | description = "Associate a public IP address with an instance in a VPC"
109 | default = false
110 | }
111 |
112 | variable "enable_monitoring" {
113 | type = bool
114 | description = "Enable/disable detailed monitoring"
115 | default = true
116 | }
117 |
118 | variable "ebs_optimized" {
119 | type = bool
120 | description = "If true, the launched EC2 instance will be EBS-optimized"
121 | default = false
122 | }
123 |
124 | variable "disable_api_termination" {
125 | type = bool
126 | description = "If `true`, enables EC2 Instance Termination Protection"
127 | default = false
128 | }
129 |
130 | variable "max_size" {
131 | type = number
132 | description = "The maximum size of the autoscale group"
133 | }
134 |
135 | variable "min_size" {
136 | type = number
137 | description = "The minimum size of the autoscale group"
138 | }
139 |
140 | variable "subnet_ids" {
141 | description = "A list of subnet IDs to launch resources in"
142 | type = list(string)
143 | }
144 |
145 | variable "default_cooldown" {
146 | type = number
147 | description = "The amount of time, in seconds, after a scaling activity completes before another scaling activity can start"
148 | default = 300
149 | }
150 |
151 | variable "health_check_grace_period" {
152 | type = number
153 | description = "Time (in seconds) after instance comes into service before checking health"
154 | default = 300
155 | }
156 |
157 | variable "health_check_type" {
158 | type = string
159 | description = "Controls how health checking is done. Valid values are `EC2` or `ELB`"
160 | default = "EC2"
161 | }
162 |
163 | variable "force_delete" {
164 | type = bool
165 | description = "Allows deleting the autoscaling group without waiting for all instances in the pool to terminate. You can force an autoscaling group to delete even if it's in the process of scaling a resource. Normally, Terraform drains all the instances before deleting the group. This bypasses that behavior and potentially leaves resources dangling"
166 | default = false
167 | }
168 |
169 | variable "load_balancers" {
170 | type = list(string)
171 | description = "A list of elastic load balancer names to add to the autoscaling group. Only valid for classic load balancers. For ALBs, use `target_group_arns` instead"
172 | default = []
173 | }
174 |
175 | variable "target_group_arns" {
176 | type = list(string)
177 | description = "A list of aws_alb_target_group ARNs, for use with Application Load Balancing"
178 | default = []
179 | }
180 |
181 | variable "termination_policies" {
182 | description = "A list of policies to decide how the instances in the auto scale group should be terminated. The allowed values are `OldestInstance`, `NewestInstance`, `OldestLaunchConfiguration`, `ClosestToNextInstanceHour`, `Default`"
183 | type = list(string)
184 | default = ["Default"]
185 | }
186 |
187 | variable "suspended_processes" {
188 | type = list(string)
189 | description = "A list of processes to suspend for the AutoScaling Group. The allowed values are `Launch`, `Terminate`, `HealthCheck`, `ReplaceUnhealthy`, `AZRebalance`, `AlarmNotification`, `ScheduledActions`, `AddToLoadBalancer`. Note that if you suspend either the `Launch` or `Terminate` process types, it can prevent your autoscaling group from functioning properly."
190 | default = []
191 | }
192 |
193 | variable "placement_group" {
194 | type = string
195 | description = "The name of the placement group into which you'll launch your instances, if any"
196 | default = ""
197 | }
198 |
199 | variable "metrics_granularity" {
200 | type = string
201 | description = "The granularity to associate with the metrics to collect. The only valid value is 1Minute"
202 | default = "1Minute"
203 | }
204 |
205 | variable "enabled_metrics" {
206 | description = "A list of metrics to collect. The allowed values are `GroupMinSize`, `GroupMaxSize`, `GroupDesiredCapacity`, `GroupInServiceInstances`, `GroupPendingInstances`, `GroupStandbyInstances`, `GroupTerminatingInstances`, `GroupTotalInstances`"
207 | type = list(string)
208 |
209 | default = [
210 | "GroupMinSize",
211 | "GroupMaxSize",
212 | "GroupDesiredCapacity",
213 | "GroupInServiceInstances",
214 | "GroupPendingInstances",
215 | "GroupStandbyInstances",
216 | "GroupTerminatingInstances",
217 | "GroupTotalInstances",
218 | ]
219 | }
220 |
221 | variable "wait_for_capacity_timeout" {
222 | type = string
223 | description = "A maximum duration that Terraform should wait for ASG instances to be healthy before timing out. Setting this to '0' causes Terraform to skip all Capacity Waiting behavior"
224 | default = "10m"
225 | }
226 |
227 | variable "min_elb_capacity" {
228 | type = number
229 | description = "Setting this causes Terraform to wait for this number of instances to show up healthy in the ELB only on creation. Updates will not wait on ELB instance number changes"
230 | default = 0
231 | }
232 |
233 | variable "wait_for_elb_capacity" {
234 | type = number
235 | description = "Setting this will cause Terraform to wait for exactly this number of healthy instances in all attached load balancers on both create and update operations. Takes precedence over `min_elb_capacity` behavior"
236 | default = 0
237 | }
238 |
239 | variable "protect_from_scale_in" {
240 | type = bool
241 | description = "Allows setting instance protection. The autoscaling group will not select instances with this setting for terminination during scale in events"
242 | default = false
243 | }
244 |
245 | variable "service_linked_role_arn" {
246 | type = string
247 | description = "The ARN of the service-linked role that the ASG will use to call other AWS services"
248 | default = ""
249 | }
250 |
251 | variable "autoscaling_group_tags" {
252 | type = map(string)
253 | default = {}
254 | description = "Additional tags only for the autoscaling group, e.g. \"k8s.io/cluster-autoscaler/node-template/taint/dedicated\" = \"ci-cd:NoSchedule\"."
255 | }
256 |
257 | variable "autoscaling_policies_enabled" {
258 | type = bool
259 | default = true
260 | description = "Whether to create `aws_autoscaling_policy` and `aws_cloudwatch_metric_alarm` resources to control Auto Scaling"
261 | }
262 |
263 | variable "scale_up_cooldown_seconds" {
264 | type = number
265 | default = 300
266 | description = "The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start"
267 | }
268 |
269 | variable "scale_up_scaling_adjustment" {
270 | type = number
271 | default = 1
272 | description = "The number of instances by which to scale. `scale_up_adjustment_type` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity"
273 | }
274 |
275 | variable "scale_up_adjustment_type" {
276 | type = string
277 | default = "ChangeInCapacity"
278 | description = "Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity`"
279 | }
280 |
281 | variable "scale_up_policy_type" {
282 | type = string
283 | default = "SimpleScaling"
284 | description = "The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling`"
285 | }
286 |
287 | variable "scale_down_cooldown_seconds" {
288 | type = number
289 | default = 300
290 | description = "The amount of time, in seconds, after a scaling activity completes and before the next scaling activity can start"
291 | }
292 |
293 | variable "scale_down_scaling_adjustment" {
294 | type = number
295 | default = -1
296 | description = "The number of instances by which to scale. `scale_down_scaling_adjustment` determines the interpretation of this number (e.g. as an absolute number or as a percentage of the existing Auto Scaling group size). A positive increment adds to the current capacity and a negative value removes from the current capacity"
297 | }
298 |
299 | variable "scale_down_adjustment_type" {
300 | type = string
301 | default = "ChangeInCapacity"
302 | description = "Specifies whether the adjustment is an absolute number or a percentage of the current capacity. Valid values are `ChangeInCapacity`, `ExactCapacity` and `PercentChangeInCapacity`"
303 | }
304 |
305 | variable "scale_down_policy_type" {
306 | type = string
307 | default = "SimpleScaling"
308 | description = "The scalling policy type, either `SimpleScaling`, `StepScaling` or `TargetTrackingScaling`"
309 | }
310 |
311 | variable "cpu_utilization_high_evaluation_periods" {
312 | type = number
313 | default = 2
314 | description = "The number of periods over which data is compared to the specified threshold"
315 | }
316 |
317 | variable "cpu_utilization_high_period_seconds" {
318 | type = number
319 | default = 300
320 | description = "The period in seconds over which the specified statistic is applied"
321 | }
322 |
323 | variable "cpu_utilization_high_threshold_percent" {
324 | type = number
325 | default = 90
326 | description = "The value against which the specified statistic is compared"
327 | }
328 |
329 | variable "cpu_utilization_high_statistic" {
330 | type = string
331 | default = "Average"
332 | description = "The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum`"
333 | }
334 |
335 | variable "cpu_utilization_low_evaluation_periods" {
336 | type = number
337 | default = 2
338 | description = "The number of periods over which data is compared to the specified threshold"
339 | }
340 |
341 | variable "cpu_utilization_low_period_seconds" {
342 | type = number
343 | default = 300
344 | description = "The period in seconds over which the specified statistic is applied"
345 | }
346 |
347 | variable "cpu_utilization_low_threshold_percent" {
348 | type = number
349 | default = 10
350 | description = "The value against which the specified statistic is compared"
351 | }
352 |
353 | variable "cpu_utilization_low_statistic" {
354 | type = string
355 | default = "Average"
356 | description = "The statistic to apply to the alarm's associated metric. Either of the following is supported: `SampleCount`, `Average`, `Sum`, `Minimum`, `Maximum`"
357 | }
358 |
359 | variable "bootstrap_extra_args" {
360 | type = string
361 | default = ""
362 | description = "Extra arguments to the `bootstrap.sh` script to enable `--enable-docker-bridge` or `--use-max-pods`"
363 | }
364 |
365 | variable "kubelet_extra_args" {
366 | type = string
367 | default = ""
368 | description = "Extra arguments to pass to kubelet, like \"--register-with-taints=dedicated=ci-cd:NoSchedule --node-labels=purpose=ci-worker\""
369 | }
370 |
371 |
372 | variable "before_cluster_joining_userdata" {
373 | type = string
374 | default = ""
375 | description = "Additional commands to execute on each worker node before joining the EKS cluster (before executing the `bootstrap.sh` script). For mot info, see https://kubedex.com/90-days-of-aws-eks-in-production"
376 | }
377 |
378 | variable "after_cluster_joining_userdata" {
379 | type = string
380 | default = ""
381 | description = "Additional commands to execute on each worker node after joining the EKS cluster (after executing the `bootstrap.sh` script). For mot info, see https://kubedex.com/90-days-of-aws-eks-in-production"
382 | }
383 |
384 | variable "aws_iam_instance_profile_name" {
385 | type = string
386 | default = ""
387 | description = "The name of the existing instance profile that will be used in autoscaling group for EKS workers. If empty will create a new instance profile."
388 | }
389 |
390 | variable "workers_security_group_id" {
391 | type = string
392 | default = ""
393 | description = "The name of the existing security group that will be used in autoscaling group for EKS workers. If empty, a new security group will be created"
394 | }
395 |
396 | variable "use_existing_security_group" {
397 | type = bool
398 | description = "If set to `true`, will use variable `workers_security_group_id` to run EKS workers using an existing security group that was created outside of this module, workaround for errors like `count cannot be computed`"
399 | default = false
400 | }
401 |
402 | variable "additional_security_group_ids" {
403 | type = list(string)
404 | default = []
405 | description = "Additional list of security groups that will be attached to the autoscaling group"
406 | }
407 |
408 | variable "use_existing_aws_iam_instance_profile" {
409 | type = bool
410 | description = "If set to `true`, will use variable `aws_iam_instance_profile_name` to run EKS workers using an existing AWS instance profile that was created outside of this module, workaround for error like `count cannot be computed`"
411 | default = false
412 | }
413 |
414 | variable "workers_role_policy_arns" {
415 | type = list(string)
416 | default = []
417 | description = "List of policy ARNs that will be attached to the workers default role on creation"
418 | }
419 |
420 | variable "workers_role_policy_arns_count" {
421 | type = number
422 | default = 0
423 | description = "Count of policy ARNs that will be attached to the workers default role on creation. Needed to prevent Terraform error `count can't be computed`"
424 | }
425 |
426 | variable "block_device_mappings" {
427 | description = "Specify volumes to attach to the instance besides the volumes specified by the AMI"
428 |
429 | type = list(object({
430 | device_name = string
431 | no_device = bool
432 | virtual_name = string
433 | ebs = object({
434 | delete_on_termination = bool
435 | encrypted = bool
436 | iops = number
437 | kms_key_id = string
438 | snapshot_id = string
439 | volume_size = number
440 | volume_type = string
441 | })
442 | }))
443 |
444 | default = []
445 | }
446 |
447 | variable "instance_market_options" {
448 | description = "The market (purchasing) option for the instances"
449 |
450 | type = object({
451 | market_type = string
452 | spot_options = object({
453 | block_duration_minutes = number
454 | instance_interruption_behavior = string
455 | max_price = number
456 | spot_instance_type = string
457 | valid_until = string
458 | })
459 | })
460 |
461 | default = null
462 | }
463 |
464 | variable "mixed_instances_policy" {
465 | description = "policy to used mixed group of on demand/spot of differing types. Launch template is automatically generated. https://www.terraform.io/docs/providers/aws/r/autoscaling_group.html#mixed_instances_policy-1"
466 |
467 | type = object({
468 | instances_distribution = object({
469 | on_demand_allocation_strategy = string
470 | on_demand_base_capacity = number
471 | on_demand_percentage_above_base_capacity = number
472 | spot_allocation_strategy = string
473 | spot_instance_pools = number
474 | spot_max_price = string
475 | })
476 | override = list(object({
477 | instance_type = string
478 | weighted_capacity = number
479 | }))
480 | })
481 | default = null
482 | }
483 |
484 | variable "placement" {
485 | description = "The placement specifications of the instances"
486 |
487 | type = object({
488 | affinity = string
489 | availability_zone = string
490 | group_name = string
491 | host_id = string
492 | tenancy = string
493 | })
494 |
495 | default = null
496 | }
497 |
498 | variable "credit_specification" {
499 | description = "Customize the credit specification of the instances"
500 |
501 | type = object({
502 | cpu_credits = string
503 | })
504 |
505 | default = null
506 | }
507 |
508 | variable "elastic_gpu_specifications" {
509 | description = "Specifications of Elastic GPU to attach to the instances"
510 |
511 | type = object({
512 | type = string
513 | })
514 |
515 | default = null
516 | }
517 |
518 | variable "max_instance_lifetime" {
519 | description = "The maximum amount of time, in seconds, that an instance can be in service, values must be either equal to 0 or between 604800 and 31536000 seconds"
520 | type = number
521 | default = null
522 | }
523 |
--------------------------------------------------------------------------------
/versions.tf:
--------------------------------------------------------------------------------
1 | terraform {
2 | required_version = ">= 1.0"
3 |
4 | required_providers {
5 | aws = {
6 | source = "hashicorp/aws"
7 | version = ">= 5.16.0"
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------