├── .github ├── CODEOWNERS ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── ISSUE_TEMPLATE │ ├── bug_report.md │ ├── config.yml │ ├── feature_request.md │ └── question.md ├── PULL_REQUEST_TEMPLATE.md └── workflows │ ├── pr-title.yaml │ ├── pre-commit.yaml │ └── stale-issue-pr.yaml ├── .gitignore ├── .pre-commit-config.yaml ├── LICENSE ├── NOTICE.txt ├── README.md ├── main.tf ├── outputs.tf ├── tests ├── README.md ├── main.tf ├── outputs.tf ├── variables.tf └── versions.tf ├── variables.tf └── versions.tf /.github/CODEOWNERS: -------------------------------------------------------------------------------- 1 | * @aws-ia/internal-terraform-eks-admins 2 | -------------------------------------------------------------------------------- /.github/CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 3 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 4 | opensource-codeofconduct@amazon.com with any additional questions or comments. 5 | -------------------------------------------------------------------------------- /.github/CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing Guidelines 2 | 3 | Thank you for your interest in contributing to our project. Whether it's a bug report, new feature, correction, or additional 4 | documentation, we greatly value feedback and contributions from our community. 5 | 6 | Please read through this document before submitting any issues or pull requests to ensure we have all the necessary 7 | information to effectively respond to your bug report or contribution. 8 | 9 | ## Reporting Bugs/Feature Requests 10 | 11 | We welcome you to use the GitHub issue tracker to report bugs or suggest features. 12 | 13 | When filing an issue, please check existing open, or recently closed, issues to make sure somebody else hasn't already 14 | reported the issue. Please try to include as much information as you can. Details like these are incredibly useful: 15 | 16 | - A reproducible test case or series of steps 17 | - The version of our code being used 18 | - Any modifications you've made relevant to the bug 19 | - Anything unusual about your environment or deployment 20 | 21 | ## Contributing via Pull Requests 22 | 23 | Contributions via pull requests are much appreciated. Before sending us a pull request, please ensure that: 24 | 25 | 1. You are working against the latest source on the _main_ branch. 26 | 2. You check existing open, and recently merged, pull requests to make sure someone else hasn't addressed the problem already. 27 | 3. You open an issue to discuss any significant work - we would hate for your time to be wasted. 28 | 29 | To send us a pull request, please: 30 | 31 | 1. Fork the repository. 32 | 2. Modify the source; please focus on the specific change you are contributing. If you also reformat all the code, it will be hard for us to focus on your change. 33 | 3. Ensure local tests pass. 34 | 4. Commit to your fork using clear commit messages. 35 | 5. Send us a pull request, answering any default questions in the pull request interface. 36 | 6. Pay attention to any automated CI failures reported in the pull request, and stay involved in the conversation. 37 | 38 | GitHub provides additional document on [forking a repository](https://help.github.com/articles/fork-a-repo/) and 39 | [creating a pull request](https://help.github.com/articles/creating-a-pull-request/). 40 | 41 | ## Finding contributions to work on 42 | 43 | Looking at the existing issues is a great way to find something to contribute on. As our projects, by default, use the default GitHub issue labels (enhancement/bug/duplicate/help wanted/invalid/question/wontfix), looking at any 'help wanted' issues is a great place to start. 44 | 45 | ## Code of Conduct 46 | 47 | This project has adopted the [Amazon Open Source Code of Conduct](https://aws.github.io/code-of-conduct). 48 | For more information see the [Code of Conduct FAQ](https://aws.github.io/code-of-conduct-faq) or contact 49 | opensource-codeofconduct@amazon.com with any additional questions or comments. 50 | 51 | ## Security issue notifications 52 | 53 | If you discover a potential security issue in this project we ask that you notify AWS/Amazon Security via our [vulnerability reporting page](http://aws.amazon.com/security/vulnerability-reporting/). Please do **not** create a public github issue. 54 | 55 | ## Licensing 56 | 57 | See the [LICENSE](LICENSE) file for our project's licensing. We will ask you to confirm the licensing of your contribution. 58 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/bug_report.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Bug report 3 | about: Create a report to help us improve 4 | --- 5 | 6 | ## Description 7 | 8 | Please provide a clear and concise description of the issue you are encountering, and a reproduction of your configuration (see the `examples/*` directory for references that you can copy+paste and tailor to match your configs if you are unable to copy your exact configuration). The reproduction MUST be executable by running `terraform init && terraform apply` without any further changes. 9 | 10 | If your request is for a new feature, please use the `Feature request` template. 11 | 12 | - [ ] ✋ I have searched the open/closed issues and my issue is not listed. 13 | 14 | ## ⚠️ Note 15 | 16 | Before you submit an issue, please perform the following first: 17 | 18 | 1. Remove the local `.terraform` directory (! ONLY if state is stored remotely, which hopefully you are following that best practice!): `rm -rf .terraform/` 19 | 2. Re-initialize the project root to pull down modules: `terraform init` 20 | 3. Re-attempt your terraform plan or apply and check if the issue still persists 21 | 22 | ## Versions 23 | 24 | - Module version [Required]: 25 | 26 | - Terraform version: 27 | 28 | - Provider version(s): 29 | 30 | 31 | ## Reproduction Code [Required] 32 | 33 | 34 | 35 | Steps to reproduce the behavior: 36 | 37 | 38 | 39 | 40 | 41 | ## Expected behavior 42 | 43 | 44 | 45 | ## Actual behavior 46 | 47 | 48 | 49 | ### Terminal Output Screenshot(s) 50 | 51 | 52 | 53 | ## Additional context 54 | 55 | 56 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Feature request 3 | about: Suggest an idea for this project 4 | --- 5 | 6 | 7 | 8 | ### Community Note 9 | 10 | * Please vote on this issue by adding a 👍 [reaction](https://blog.github.com/2016-03-10-add-reactions-to-pull-requests-issues-and-comments/) to the original issue to help the community and maintainers prioritize this request 11 | * Please do not leave "+1" or other comments that do not add relevant new information or questions, they generate extra noise for issue followers and do not help prioritize the request 12 | * If you are interested in working on this issue or have submitted a pull request, please leave a comment 13 | 14 | 15 | 16 | #### What is the outcome that you are trying to reach? 17 | 18 | 19 | 20 | #### Describe the solution you would like 21 | 22 | 23 | 24 | #### Describe alternatives you have considered 25 | 26 | 27 | 28 | #### Additional context 29 | 30 | 31 | -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/question.md: -------------------------------------------------------------------------------- 1 | --- 2 | name: Question 3 | about: I have a Question 4 | --- 5 | 6 | - [ ] ✋ I have searched the open/closed issues and my issue is not listed. 7 | 8 | #### Please describe your question here 9 | 10 | 11 | 12 | #### Provide a link to the example/module related to the question 13 | 14 | 15 | 16 | #### Additional context 17 | 18 | 19 | -------------------------------------------------------------------------------- /.github/PULL_REQUEST_TEMPLATE.md: -------------------------------------------------------------------------------- 1 | ### What does this PR do? 2 | 3 | 🛑 Please open an issue first to discuss any significant work and flesh out details/direction - we would hate for your time to be wasted. 4 | Consult the [CONTRIBUTING](https://github.com/aws-ia/terraform-aws-eks-addon/.github/blob/main/CONTRIBUTING.md#contributing-via-pull-requests) guide for submitting pull-requests. 5 | 6 | 7 | 8 | ### Motivation 9 | 10 | 11 | - Resolves # 12 | 13 | ### Test Results 14 | 15 | 16 | 17 | ### Additional Notes 18 | 19 | 20 | -------------------------------------------------------------------------------- /.github/workflows/pr-title.yaml: -------------------------------------------------------------------------------- 1 | name: 'PR title' 2 | 3 | on: 4 | pull_request_target: 5 | types: 6 | - opened 7 | - edited 8 | - synchronize 9 | 10 | jobs: 11 | main: 12 | name: Validate PR title 13 | runs-on: ubuntu-latest 14 | steps: 15 | - uses: amannn/action-semantic-pull-request@v5.2.0 16 | env: 17 | GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} 18 | with: 19 | requireScope: false 20 | subjectPattern: ^[A-Z].+$ 21 | subjectPatternError: | 22 | The subject "{subject}" found in the pull request title "{title}" 23 | didn't match the configured pattern. Please ensure that the subject 24 | starts with an uppercase character. 25 | wip: true 26 | validateSingleCommit: false 27 | -------------------------------------------------------------------------------- /.github/workflows/pre-commit.yaml: -------------------------------------------------------------------------------- 1 | name: pre-commit 2 | 3 | on: 4 | pull_request: 5 | branches: 6 | - main 7 | paths: 8 | - '**.tf' 9 | - '**.yml' 10 | - '**.yaml' 11 | 12 | permissions: read-all 13 | 14 | env: 15 | TERRAFORM_DOCS_VERSION: v0.16.0 16 | TFSEC_VERSION: v1.28.1 17 | TF_PLUGIN_CACHE_DIR: ${{ github.workspace }}/.terraform.d/plugin-cache 18 | TFLINT_VERSION: v0.45.0 19 | 20 | concurrency: 21 | group: '${{ github.workflow }} @ ${{ github.event.pull_request.head.label || github.head_ref || github.ref }}' 22 | cancel-in-progress: true 23 | 24 | jobs: 25 | collectInputs: 26 | name: Collect workflow inputs 27 | runs-on: ubuntu-latest 28 | outputs: 29 | directories: ${{ steps.dirs.outputs.directories }} 30 | steps: 31 | - name: Checkout 32 | uses: actions/checkout@v3 33 | 34 | - name: Get root directories 35 | id: dirs 36 | uses: clowdhaus/terraform-composite-actions/directories@v1.8.3 37 | 38 | preCommitMinVersions: 39 | name: Min TF pre-commit 40 | needs: collectInputs 41 | runs-on: ubuntu-latest 42 | strategy: 43 | matrix: 44 | directory: ${{ fromJson(needs.collectInputs.outputs.directories) }} 45 | steps: 46 | - name: Remove default Terraform 47 | run: rm -rf $(which terraform) 48 | 49 | - name: Checkout 50 | uses: actions/checkout@v3 51 | 52 | - uses: dorny/paths-filter@v2 53 | id: changes 54 | with: 55 | # We only need to check Terraform files for the current directory 56 | # because the `preCommitMaxVersion` job will run the full, 57 | # exhaustive checks (always) 58 | filters: | 59 | src: 60 | - '${{ matrix.directory }}/*.tf' 61 | 62 | - name: Config Terraform plugin cache 63 | if: steps.changes.outputs.src== 'true' 64 | run: mkdir --parents ${{ env.TERRAFORM_DOCS_VERSION }} 65 | 66 | - name: Cache Terraform 67 | uses: actions/cache@v3 68 | if: steps.changes.outputs.src== 'true' 69 | with: 70 | path: ${{ env.TERRAFORM_DOCS_VERSION }} 71 | key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }} 72 | restore-keys: ${{ runner.os }}-terraform- 73 | 74 | - name: Terraform min/max versions 75 | uses: clowdhaus/terraform-min-max@v1.2.4 76 | if: steps.changes.outputs.src== 'true' 77 | id: minMax 78 | with: 79 | directory: ${{ matrix.directory }} 80 | 81 | - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} 82 | uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3 83 | # Run only validate pre-commit check on min version supported 84 | if: ${{ matrix.directory != '.' && steps.changes.outputs.src== 'true' }} 85 | with: 86 | terraform-version: ${{ steps.minMax.outputs.minVersion }} 87 | args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*' 88 | 89 | - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} 90 | uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3 91 | # Run only validate pre-commit check on min version supported 92 | if: ${{ matrix.directory == '.' && steps.changes.outputs.src== 'true' }} 93 | with: 94 | terraform-version: ${{ steps.minMax.outputs.minVersion }} 95 | args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)' 96 | 97 | preCommitMaxVersion: 98 | name: Max TF pre-commit 99 | runs-on: ubuntu-latest 100 | needs: collectInputs 101 | steps: 102 | - name: Remove default Terraform 103 | run: rm -rf $(which terraform) 104 | 105 | - name: Checkout 106 | uses: actions/checkout@v3 107 | 108 | - uses: dorny/paths-filter@v2 109 | id: changes 110 | with: 111 | filters: | 112 | src: 113 | - '**/*.tf' 114 | 115 | - name: Config Terraform plugin cache 116 | if: steps.changes.outputs.src== 'true' 117 | run: mkdir --parents ${{ env.TERRAFORM_DOCS_VERSION }} 118 | 119 | - name: Cache Terraform 120 | uses: actions/cache@v3 121 | if: steps.changes.outputs.src== 'true' 122 | with: 123 | path: ${{ env.TF_PLUGIN_CACHE_DIR }} 124 | key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }} 125 | restore-keys: ${{ runner.os }}-terraform- 126 | 127 | - name: Install tfsec 128 | if: steps.changes.outputs.src== 'true' 129 | run: curl -sSLo ./tfsec https://github.com/aquasecurity/tfsec/releases/download/${{ env.TFSEC_VERSION }}/tfsec-$(uname)-amd64 && chmod +x tfsec && sudo mv tfsec /usr/bin/ 130 | 131 | - name: Terraform min/max versions 132 | id: minMax 133 | uses: clowdhaus/terraform-min-max@v1.2.4 134 | if: steps.changes.outputs.src== 'true' 135 | 136 | - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }} 137 | uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3 138 | if: steps.changes.outputs.src== 'true' 139 | with: 140 | terraform-version: ${{ steps.minMax.outputs.maxVersion }} 141 | terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }} 142 | tflint-version: ${{ env.TFLINT_VERSION }} 143 | -------------------------------------------------------------------------------- /.github/workflows/stale-issue-pr.yaml: -------------------------------------------------------------------------------- 1 | name: 'Stale Issue/PR' 2 | 3 | on: 4 | workflow_dispatch: 5 | schedule: 6 | - cron: '0 0 * * *' 7 | 8 | permissions: read-all 9 | 10 | jobs: 11 | stale: 12 | runs-on: ubuntu-latest 13 | permissions: 14 | issues: write 15 | pull-requests: write 16 | steps: 17 | - uses: actions/stale@v6 18 | id: stale 19 | with: 20 | ascending: true 21 | close-issue-message: 'Issue closed due to inactivity.' 22 | close-pr-message: 'Pull request closed due to inactivity.' 23 | days-before-close: 10 24 | days-before-stale: 30 25 | stale-issue-label: stale 26 | stale-pr-label: stale 27 | # Not stale if have this labels 28 | exempt-issue-labels: 'bug,enhancement' 29 | exempt-pr-labels: 'bug,enhancement' 30 | operations-per-run: 100 31 | stale-issue-message: | 32 | This issue has been automatically marked as stale because it has been open 30 days 33 | with no activity. Remove stale label or comment or this issue will be closed in 10 days 34 | stale-pr-message: | 35 | This PR has been automatically marked as stale because it has been open 30 days 36 | with no activity. Remove stale label or comment or this PR will be closed in 10 days 37 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | .DS_Store 2 | 3 | # Local .terraform directories 4 | **/.terraform/* 5 | 6 | # Terraform lockfile 7 | .terraform.lock.hcl 8 | 9 | # .tfstate files 10 | *.tfstate 11 | *.tfstate.* 12 | *.tfplan 13 | 14 | # Crash log files 15 | crash.log 16 | 17 | # Exclude all .tfvars files, which are likely to contain sentitive data, such as 18 | # password, private keys, and other secrets. These should not be part of version 19 | # control as they are data points which are potentially sensitive and subject 20 | # to change depending on the environment. 21 | *.tfvars 22 | 23 | # Ignore override files as they are usually used to override resources locally and so 24 | # are not checked in 25 | override.tf 26 | override.tf.json 27 | *_override.tf 28 | *_override.tf.json 29 | 30 | # Ignore CLI configuration files 31 | .terraformrc 32 | terraform.rc 33 | -------------------------------------------------------------------------------- /.pre-commit-config.yaml: -------------------------------------------------------------------------------- 1 | repos: 2 | - repo: https://github.com/antonbabenko/pre-commit-terraform 3 | rev: v1.96.1 4 | hooks: 5 | - id: terraform_fmt 6 | - id: terraform_validate 7 | - id: terraform_docs 8 | args: 9 | - '--args=--lockfile=false' 10 | - id: terraform_tflint 11 | args: 12 | - '--args=--only=terraform_deprecated_interpolation' 13 | - '--args=--only=terraform_deprecated_index' 14 | - '--args=--only=terraform_unused_declarations' 15 | - '--args=--only=terraform_comment_syntax' 16 | - '--args=--only=terraform_documented_outputs' 17 | - '--args=--only=terraform_documented_variables' 18 | - '--args=--only=terraform_typed_variables' 19 | - '--args=--only=terraform_module_pinned_source' 20 | - '--args=--only=terraform_naming_convention' 21 | - '--args=--only=terraform_required_version' 22 | - '--args=--only=terraform_required_providers' 23 | - '--args=--only=terraform_standard_module_structure' 24 | - '--args=--only=terraform_workspace_remote' 25 | - repo: https://github.com/pre-commit/pre-commit-hooks 26 | rev: v4.6.0 27 | hooks: 28 | - id: check-merge-conflict 29 | - id: end-of-file-fixer 30 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /NOTICE.txt: -------------------------------------------------------------------------------- 1 | Copyright 2016-2022 Amazon.com, Inc. or its affiliates. All Rights Reserved. 2 | 3 | Licensed under the Apache License, Version 2.0 (the "License"). You may not use this file except in compliance with the License. A copy of the License is located at 4 | 5 | http://aws.amazon.com/apache2.0/ 6 | 7 | or in the "license" file accompanying this file. This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License. 8 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # Amazon EKS Blueprints Addon Terraform module 2 | 3 | Terraform module which provisions an addon ([Helm release](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release)) and an [IAM role for service accounts (IRSA)](https://docs.aws.amazon.com/eks/latest/userguide/iam-roles-for-service-accounts.html). 4 | 5 | ## Usage 6 | 7 | ### Create Addon (Helm Release) w/ IAM Role for Service Account (IRSA) 8 | 9 | ```hcl 10 | module "eks_blueprints_addon" { 11 | source = "aws-ia/eks-blueprints-addon/aws" 12 | version = "~> 1.0" #ensure to update this to the latest/desired version 13 | 14 | chart = "karpenter" 15 | chart_version = "0.16.2" 16 | repository = "https://charts.karpenter.sh/" 17 | description = "Kubernetes Node Autoscaling: built for flexibility, performance, and simplicity" 18 | namespace = "karpenter" 19 | create_namespace = true 20 | 21 | set = [ 22 | { 23 | name = "clusterName" 24 | value = "eks-blueprints-addon-example" 25 | }, 26 | { 27 | name = "clusterEndpoint" 28 | value = "https://EXAMPLED539D4633E53DE1B71EXAMPLE.gr7.us-west-2.eks.amazonaws.com" 29 | }, 30 | { 31 | name = "aws.defaultInstanceProfile" 32 | value = "arn:aws:iam::111111111111:instance-profile/KarpenterNodeInstanceProfile-complete" 33 | } 34 | ] 35 | 36 | set_irsa_names = ["serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"] 37 | # # Equivalent to the following but the ARN is only known internally to the module 38 | # set = [{ 39 | # name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn" 40 | # value = iam_role_arn.this[0].arn 41 | # }] 42 | 43 | # IAM role for service account (IRSA) 44 | create_role = true 45 | role_name = "karpenter-controller" 46 | role_policies = { 47 | karpenter = "arn:aws:iam::111111111111:policy/Karpenter_Controller_Policy-20221008165117447500000007" 48 | } 49 | 50 | oidc_providers = { 51 | this = { 52 | provider_arn = "oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE" 53 | # namespace is inherited from chart 54 | service_account = "karpenter" 55 | } 56 | } 57 | 58 | tags = { 59 | Environment = "dev" 60 | } 61 | } 62 | ``` 63 | 64 | ### Create Addon (Helm Release) Only 65 | 66 | ```hcl 67 | module "eks_blueprints_addon" { 68 | source = "aws-ia/eks-blueprints-addon/aws" 69 | version = "~> 1.0" #ensure to update this to the latest/desired version 70 | 71 | chart = "metrics-server" 72 | chart_version = "3.8.2" 73 | repository = "https://kubernetes-sigs.github.io/metrics-server/" 74 | description = "Metric server helm Chart deployment configuration" 75 | namespace = "kube-system" 76 | 77 | values = [ 78 | <<-EOT 79 | podDisruptionBudget: 80 | maxUnavailable: 1 81 | metrics: 82 | enabled: true 83 | EOT 84 | ] 85 | 86 | set = [ 87 | { 88 | name = "replicas" 89 | value = 3 90 | } 91 | ] 92 | } 93 | ``` 94 | 95 | ### Create IAM Role for Service Account (IRSA) Only 96 | 97 | ```hcl 98 | module "eks_blueprints_addon" { 99 | source = "aws-ia/eks-blueprints-addon/aws" 100 | version = "~> 1.0" #ensure to update this to the latest/desired version 101 | 102 | # Disable helm release 103 | create_release = false 104 | 105 | # IAM role for service account (IRSA) 106 | create_role = true 107 | create_policy = false 108 | role_name = "aws-vpc-cni-ipv4" 109 | role_policies = { 110 | AmazonEKS_CNI_Policy = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" 111 | } 112 | 113 | oidc_providers = { 114 | this = { 115 | provider_arn = "oidc.eks.us-west-2.amazonaws.com/id/EXAMPLED539D4633E53DE1B71EXAMPLE" 116 | namespace = "kube-system" 117 | service_account = "aws-node" 118 | } 119 | } 120 | 121 | tags = { 122 | Environment = "dev" 123 | } 124 | } 125 | ``` 126 | 127 | ## Support & Feedback 128 | 129 | > [!IMPORTANT] 130 | > EKS Blueprints for Terraform is maintained by AWS Solution Architects. It is not part of an AWS 131 | > service and support is provided as a best-effort by the EKS Blueprints community. To provide feedback, 132 | > please use the [issues templates](https://github.com/aws-ia/terraform-aws-eks-blueprints-addon/issues) 133 | > provided. If you are interested in contributing to EKS Blueprints, see the 134 | > [Contribution guide](https://github.com/aws-ia/terraform-aws-eks-blueprints-addon/blob/main/.github/CONTRIBUTING.md). 135 | 136 | 137 | ## Requirements 138 | 139 | | Name | Version | 140 | |------|---------| 141 | | [terraform](#requirement\_terraform) | >= 1.0 | 142 | | [aws](#requirement\_aws) | >= 4.47 | 143 | | [helm](#requirement\_helm) | >= 2.9 | 144 | 145 | ## Providers 146 | 147 | | Name | Version | 148 | |------|---------| 149 | | [aws](#provider\_aws) | >= 4.47 | 150 | | [helm](#provider\_helm) | >= 2.9 | 151 | 152 | ## Modules 153 | 154 | No modules. 155 | 156 | ## Resources 157 | 158 | | Name | Type | 159 | |------|------| 160 | | [aws_iam_policy.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | 161 | | [aws_iam_role.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role) | resource | 162 | | [aws_iam_role_policy_attachment.additional](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | 163 | | [aws_iam_role_policy_attachment.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_role_policy_attachment) | resource | 164 | | [helm_release.this](https://registry.terraform.io/providers/hashicorp/helm/latest/docs/resources/release) | resource | 165 | | [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | 166 | | [aws_iam_policy_document.assume](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 167 | | [aws_iam_policy_document.this](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 168 | | [aws_partition.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/partition) | data source | 169 | 170 | ## Inputs 171 | 172 | | Name | Description | Type | Default | Required | 173 | |------|-------------|------|---------|:--------:| 174 | | [allow\_self\_assume\_role](#input\_allow\_self\_assume\_role) | Determines whether to allow the role to be [assume itself](https://aws.amazon.com/blogs/security/announcing-an-update-to-iam-role-trust-policy-behavior/) | `bool` | `false` | no | 175 | | [assume\_role\_condition\_test](#input\_assume\_role\_condition\_test) | Name of the [IAM condition operator](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html) to evaluate when assuming the role | `string` | `"StringEquals"` | no | 176 | | [atomic](#input\_atomic) | If set, installation process purges chart on fail. The wait flag will be set automatically if atomic is used. Defaults to `false` | `bool` | `null` | no | 177 | | [chart](#input\_chart) | Chart name to be installed. The chart name can be local path, a URL to a chart, or the name of the chart if `repository` is specified | `string` | `""` | no | 178 | | [chart\_version](#input\_chart\_version) | Specify the exact chart version to install. If this is not specified, the latest version is installed | `string` | `null` | no | 179 | | [cleanup\_on\_fail](#input\_cleanup\_on\_fail) | Allow deletion of new resources created in this upgrade when upgrade fails. Defaults to `false` | `bool` | `null` | no | 180 | | [create](#input\_create) | Controls if resources should be created (affects all resources) | `bool` | `true` | no | 181 | | [create\_namespace](#input\_create\_namespace) | Create the namespace if it does not yet exist. Defaults to `false` | `bool` | `null` | no | 182 | | [create\_policy](#input\_create\_policy) | Whether to create an IAM policy that is attached to the IAM role created | `bool` | `true` | no | 183 | | [create\_release](#input\_create\_release) | Determines whether the Helm release is created | `bool` | `true` | no | 184 | | [create\_role](#input\_create\_role) | Determines whether to create an IAM role | `bool` | `false` | no | 185 | | [dependency\_update](#input\_dependency\_update) | Runs helm dependency update before installing the chart. Defaults to `false` | `bool` | `null` | no | 186 | | [description](#input\_description) | Set release description attribute (visible in the history) | `string` | `null` | no | 187 | | [devel](#input\_devel) | Use chart development versions, too. Equivalent to version '>0.0.0-0'. If version is set, this is ignored | `bool` | `null` | no | 188 | | [disable\_openapi\_validation](#input\_disable\_openapi\_validation) | If set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema. Defaults to `false` | `bool` | `null` | no | 189 | | [disable\_webhooks](#input\_disable\_webhooks) | Prevent hooks from running. Defaults to `false` | `bool` | `null` | no | 190 | | [force\_update](#input\_force\_update) | Force resource update through delete/recreate if needed. Defaults to `false` | `bool` | `null` | no | 191 | | [keyring](#input\_keyring) | Location of public keys used for verification. Used only if verify is true. Defaults to `/.gnupg/pubring.gpg` in the location set by `home` | `string` | `null` | no | 192 | | [lint](#input\_lint) | Run the helm chart linter during the plan. Defaults to `false` | `bool` | `null` | no | 193 | | [max\_history](#input\_max\_history) | Maximum number of release versions stored per release. Defaults to `0` (no limit) | `number` | `null` | no | 194 | | [max\_session\_duration](#input\_max\_session\_duration) | Maximum CLI/API session duration in seconds between 3600 and 43200 | `number` | `null` | no | 195 | | [name](#input\_name) | Name of the Helm release | `string` | `""` | no | 196 | | [namespace](#input\_namespace) | The namespace to install the release into. Defaults to `default` | `string` | `null` | no | 197 | | [oidc\_providers](#input\_oidc\_providers) | Map of OIDC providers where each provider map should contain the `provider_arn`, and `service_accounts` | `any` | `{}` | no | 198 | | [override\_policy\_documents](#input\_override\_policy\_documents) | List of IAM policy documents that are merged together into the exported document. In merging, statements with non-blank `sid`s will override statements with the same `sid` | `list(string)` | `[]` | no | 199 | | [policy\_description](#input\_policy\_description) | IAM policy description | `string` | `null` | no | 200 | | [policy\_name](#input\_policy\_name) | Name of IAM policy | `string` | `null` | no | 201 | | [policy\_name\_use\_prefix](#input\_policy\_name\_use\_prefix) | Determines whether the IAM policy name (`policy_name`) is used as a prefix | `bool` | `true` | no | 202 | | [policy\_path](#input\_policy\_path) | Path of IAM policy | `string` | `null` | no | 203 | | [policy\_statements](#input\_policy\_statements) | List of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement) | `any` | `[]` | no | 204 | | [postrender](#input\_postrender) | Configure a command to run after helm renders the manifest which can alter the manifest contents | `any` | `{}` | no | 205 | | [recreate\_pods](#input\_recreate\_pods) | Perform pods restart during upgrade/rollback. Defaults to `false` | `bool` | `null` | no | 206 | | [render\_subchart\_notes](#input\_render\_subchart\_notes) | If set, render subchart notes along with the parent. Defaults to `true` | `bool` | `null` | no | 207 | | [replace](#input\_replace) | Re-use the given name, only if that name is a deleted release which remains in the history. This is unsafe in production. Defaults to `false` | `bool` | `null` | no | 208 | | [repository](#input\_repository) | Repository URL where to locate the requested chart | `string` | `null` | no | 209 | | [repository\_ca\_file](#input\_repository\_ca\_file) | The Repositories CA File | `string` | `null` | no | 210 | | [repository\_cert\_file](#input\_repository\_cert\_file) | The repositories cert file | `string` | `null` | no | 211 | | [repository\_key\_file](#input\_repository\_key\_file) | The repositories cert key file | `string` | `null` | no | 212 | | [repository\_password](#input\_repository\_password) | Password for HTTP basic authentication against the repository | `string` | `null` | no | 213 | | [repository\_username](#input\_repository\_username) | Username for HTTP basic authentication against the repository | `string` | `null` | no | 214 | | [reset\_values](#input\_reset\_values) | When upgrading, reset the values to the ones built into the chart. Defaults to `false` | `bool` | `null` | no | 215 | | [reuse\_values](#input\_reuse\_values) | When upgrading, reuse the last release's values and merge in any overrides. If `reset_values` is specified, this is ignored. Defaults to `false` | `bool` | `null` | no | 216 | | [role\_description](#input\_role\_description) | IAM Role description | `string` | `null` | no | 217 | | [role\_name](#input\_role\_name) | Name of IAM role | `string` | `null` | no | 218 | | [role\_name\_use\_prefix](#input\_role\_name\_use\_prefix) | Determines whether the IAM role name (`role_name`) is used as a prefix | `bool` | `true` | no | 219 | | [role\_path](#input\_role\_path) | Path of IAM role | `string` | `"/"` | no | 220 | | [role\_permissions\_boundary\_arn](#input\_role\_permissions\_boundary\_arn) | Permissions boundary ARN to use for IAM role | `string` | `null` | no | 221 | | [role\_policies](#input\_role\_policies) | Policies to attach to the IAM role in `{'static_name' = 'policy_arn'}` format | `map(string)` | `{}` | no | 222 | | [set](#input\_set) | Value block with custom values to be merged with the values yaml | `any` | `[]` | no | 223 | | [set\_irsa\_names](#input\_set\_irsa\_names) | Value annotations name where IRSA role ARN created by module will be assigned to the `value` | `list(string)` | `[]` | no | 224 | | [set\_sensitive](#input\_set\_sensitive) | Value block with custom sensitive values to be merged with the values yaml that won't be exposed in the plan's diff | `any` | `[]` | no | 225 | | [skip\_crds](#input\_skip\_crds) | If set, no CRDs will be installed. By default, CRDs are installed if not already present. Defaults to `false` | `bool` | `null` | no | 226 | | [source\_policy\_documents](#input\_source\_policy\_documents) | List of IAM policy documents that are merged together into the exported document. Statements must have unique `sid`s | `list(string)` | `[]` | no | 227 | | [tags](#input\_tags) | A map of tags to add to all resources | `map(string)` | `{}` | no | 228 | | [timeout](#input\_timeout) | Time in seconds to wait for any individual kubernetes operation (like Jobs for hooks). Defaults to `300` seconds | `number` | `null` | no | 229 | | [values](#input\_values) | List of values in raw yaml to pass to helm. Values will be merged, in order, as Helm does with multiple `-f` options | `list(string)` | `null` | no | 230 | | [verify](#input\_verify) | Verify the package before installing it. Helm uses a provenance file to verify the integrity of the chart; this must be hosted alongside the chart. For more information see the Helm Documentation. Defaults to `false` | `bool` | `null` | no | 231 | | [wait](#input\_wait) | Will wait until all resources are in a ready state before marking the release as successful. If set to `true`, it will wait for as long as `timeout`. If set to `null` fallback on `300s` timeout. Defaults to `false` | `bool` | `false` | no | 232 | | [wait\_for\_jobs](#input\_wait\_for\_jobs) | If wait is enabled, will wait until all Jobs have been completed before marking the release as successful. It will wait for as long as `timeout`. Defaults to `false` | `bool` | `null` | no | 233 | 234 | ## Outputs 235 | 236 | | Name | Description | 237 | |------|-------------| 238 | | [app\_version](#output\_app\_version) | The version number of the application being deployed | 239 | | [chart](#output\_chart) | The name of the chart | 240 | | [iam\_policy](#output\_iam\_policy) | The policy document | 241 | | [iam\_policy\_arn](#output\_iam\_policy\_arn) | The ARN assigned by AWS to this policy | 242 | | [iam\_role\_arn](#output\_iam\_role\_arn) | ARN of IAM role | 243 | | [iam\_role\_name](#output\_iam\_role\_name) | Name of IAM role | 244 | | [iam\_role\_path](#output\_iam\_role\_path) | Path of IAM role | 245 | | [iam\_role\_unique\_id](#output\_iam\_role\_unique\_id) | Unique ID of IAM role | 246 | | [name](#output\_name) | Name is the name of the release | 247 | | [namespace](#output\_namespace) | Name of Kubernetes namespace | 248 | | [revision](#output\_revision) | Version is an int32 which represents the version of the release | 249 | | [values](#output\_values) | The compounded values from `values` and `set*` attributes | 250 | | [version](#output\_version) | A SemVer 2 conformant version string of the chart | 251 | 252 | 253 | ## Community 254 | 255 | - [Code of conduct](.github/CODE_OF_CONDUCT.md) 256 | - [Contributing](.github/CONTRIBUTING.md) 257 | - [Security issue notifications](.github/CONTRIBUTING.md#security-issue-notifications) 258 | 259 | ## License 260 | 261 | Apache-2.0 Licensed. See [LICENSE](https://github.com/aws-ia/terraform-aws-eks-blueprints-addon/blob/main/LICENSE). 262 | -------------------------------------------------------------------------------- /main.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | namespace = try(coalesce(var.namespace, "default")) # Need to explicitly set default for use with IRSA 3 | } 4 | 5 | ################################################################################ 6 | # Helm Release 7 | ################################################################################ 8 | 9 | resource "helm_release" "this" { 10 | count = var.create && var.create_release ? 1 : 0 11 | 12 | name = try(coalesce(var.name, var.chart), "") 13 | description = var.description 14 | namespace = local.namespace 15 | create_namespace = var.create_namespace 16 | chart = var.chart 17 | version = var.chart_version # conflicts with reserved keyword 18 | repository = var.repository 19 | values = var.values 20 | 21 | timeout = var.timeout 22 | repository_key_file = var.repository_key_file 23 | repository_cert_file = var.repository_cert_file 24 | repository_ca_file = var.repository_ca_file 25 | repository_username = var.repository_username 26 | repository_password = var.repository_password 27 | devel = var.devel 28 | verify = var.verify 29 | keyring = var.keyring 30 | disable_webhooks = var.disable_webhooks 31 | reuse_values = var.reuse_values 32 | reset_values = var.reset_values 33 | force_update = var.force_update 34 | recreate_pods = var.recreate_pods 35 | cleanup_on_fail = var.cleanup_on_fail 36 | max_history = var.max_history 37 | atomic = var.atomic 38 | skip_crds = var.skip_crds 39 | render_subchart_notes = var.render_subchart_notes 40 | disable_openapi_validation = var.disable_openapi_validation 41 | wait = var.wait 42 | wait_for_jobs = var.wait_for_jobs 43 | dependency_update = var.dependency_update 44 | replace = var.replace 45 | lint = var.lint 46 | 47 | dynamic "postrender" { 48 | for_each = length(var.postrender) > 0 ? [var.postrender] : [] 49 | 50 | content { 51 | binary_path = postrender.value.binary_path 52 | args = try(postrender.value.args, null) 53 | } 54 | } 55 | 56 | dynamic "set" { 57 | for_each = var.set 58 | 59 | content { 60 | name = set.value.name 61 | value = set.value.value 62 | type = try(set.value.type, null) 63 | } 64 | } 65 | 66 | dynamic "set" { 67 | for_each = { for k, v in toset(var.set_irsa_names) : k => v if var.create && var.create_role } 68 | iterator = each 69 | content { 70 | name = each.value 71 | value = aws_iam_role.this[0].arn 72 | } 73 | } 74 | 75 | dynamic "set_sensitive" { 76 | for_each = var.set_sensitive 77 | 78 | content { 79 | name = set_sensitive.value.name 80 | value = set_sensitive.value.value 81 | type = try(set_sensitive.value.type, null) 82 | } 83 | } 84 | } 85 | 86 | ################################################################################ 87 | # IAM Role for Service Account(s) (IRSA) 88 | ################################################################################ 89 | 90 | data "aws_partition" "current" { 91 | count = local.create_role ? 1 : 0 92 | } 93 | data "aws_caller_identity" "current" { 94 | count = local.create_role ? 1 : 0 95 | } 96 | 97 | locals { 98 | create_role = var.create && var.create_role 99 | 100 | account_id = try(data.aws_caller_identity.current[0].account_id, "*") 101 | partition = try(data.aws_partition.current[0].partition, "*") 102 | 103 | role_name = try(coalesce(var.role_name, var.name), "") 104 | role_name_condition = var.role_name_use_prefix ? "${local.role_name}-*" : local.role_name 105 | } 106 | 107 | data "aws_iam_policy_document" "assume" { 108 | count = local.create_role ? 1 : 0 109 | 110 | dynamic "statement" { 111 | # https://aws.amazon.com/blogs/security/announcing-an-update-to-iam-role-trust-policy-behavior/ 112 | for_each = var.allow_self_assume_role ? [1] : [] 113 | 114 | content { 115 | sid = "ExplicitSelfRoleAssumption" 116 | effect = "Allow" 117 | actions = ["sts:AssumeRole"] 118 | 119 | principals { 120 | type = "AWS" 121 | identifiers = ["*"] 122 | } 123 | 124 | condition { 125 | test = "ArnLike" 126 | variable = "aws:PrincipalArn" 127 | values = ["arn:${local.partition}:iam::${local.account_id}:role${var.role_path}${local.role_name_condition}"] 128 | } 129 | } 130 | } 131 | 132 | dynamic "statement" { 133 | for_each = var.oidc_providers 134 | 135 | content { 136 | effect = "Allow" 137 | actions = ["sts:AssumeRoleWithWebIdentity"] 138 | 139 | principals { 140 | type = "Federated" 141 | identifiers = [statement.value.provider_arn] 142 | } 143 | 144 | condition { 145 | test = var.assume_role_condition_test 146 | variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:sub" 147 | values = ["system:serviceaccount:${try(statement.value.namespace, local.namespace)}:${statement.value.service_account}"] 148 | } 149 | 150 | # https://aws.amazon.com/premiumsupport/knowledge-center/eks-troubleshoot-oidc-and-irsa/?nc1=h_ls 151 | condition { 152 | test = var.assume_role_condition_test 153 | variable = "${replace(statement.value.provider_arn, "/^(.*provider/)/", "")}:aud" 154 | values = ["sts.amazonaws.com"] 155 | } 156 | } 157 | } 158 | } 159 | 160 | resource "aws_iam_role" "this" { 161 | count = local.create_role ? 1 : 0 162 | 163 | name = var.role_name_use_prefix ? null : local.role_name 164 | name_prefix = var.role_name_use_prefix ? "${local.role_name}-" : null 165 | path = var.role_path 166 | description = var.role_description 167 | 168 | assume_role_policy = data.aws_iam_policy_document.assume[0].json 169 | max_session_duration = var.max_session_duration 170 | permissions_boundary = var.role_permissions_boundary_arn 171 | force_detach_policies = true 172 | 173 | tags = var.tags 174 | } 175 | 176 | resource "aws_iam_role_policy_attachment" "additional" { 177 | for_each = { for k, v in var.role_policies : k => v if local.create_role } 178 | 179 | role = aws_iam_role.this[0].name 180 | policy_arn = each.value 181 | } 182 | 183 | ################################################################################ 184 | # IAM Policy 185 | ################################################################################ 186 | 187 | locals { 188 | create_policy = local.create_role && var.create_policy 189 | 190 | policy_name = try(coalesce(var.policy_name, local.role_name), "") 191 | perms = concat(var.source_policy_documents, var.override_policy_documents, var.policy_statements) 192 | } 193 | 194 | data "aws_iam_policy_document" "this" { 195 | count = local.create_policy && length(local.perms) > 0 ? 1 : 0 196 | 197 | source_policy_documents = var.source_policy_documents 198 | override_policy_documents = var.override_policy_documents 199 | 200 | dynamic "statement" { 201 | for_each = var.policy_statements 202 | 203 | content { 204 | sid = try(statement.value.sid, null) 205 | actions = try(statement.value.actions, null) 206 | not_actions = try(statement.value.not_actions, null) 207 | effect = try(statement.value.effect, null) 208 | resources = try(statement.value.resources, null) 209 | not_resources = try(statement.value.not_resources, null) 210 | 211 | dynamic "principals" { 212 | for_each = try(statement.value.principals, []) 213 | 214 | content { 215 | type = principals.value.type 216 | identifiers = principals.value.identifiers 217 | } 218 | } 219 | 220 | dynamic "not_principals" { 221 | for_each = try(statement.value.not_principals, []) 222 | 223 | content { 224 | type = not_principals.value.type 225 | identifiers = not_principals.value.identifiers 226 | } 227 | } 228 | 229 | dynamic "condition" { 230 | for_each = try(statement.value.conditions, []) 231 | 232 | content { 233 | test = condition.value.test 234 | values = condition.value.values 235 | variable = condition.value.variable 236 | } 237 | } 238 | } 239 | } 240 | } 241 | 242 | resource "aws_iam_policy" "this" { 243 | count = local.create_policy && length(local.perms) > 0 ? 1 : 0 244 | 245 | name = var.policy_name_use_prefix ? null : local.policy_name 246 | name_prefix = var.policy_name_use_prefix ? "${local.policy_name}-" : null 247 | path = coalesce(var.policy_path, var.role_path) 248 | description = try(coalesce(var.policy_description, var.role_description), null) 249 | policy = data.aws_iam_policy_document.this[0].json 250 | 251 | tags = var.tags 252 | } 253 | 254 | resource "aws_iam_role_policy_attachment" "this" { 255 | count = local.create_policy && length(local.perms) > 0 ? 1 : 0 256 | 257 | role = aws_iam_role.this[0].name 258 | policy_arn = aws_iam_policy.this[0].arn 259 | } 260 | -------------------------------------------------------------------------------- /outputs.tf: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Helm Release 3 | ################################################################################ 4 | 5 | output "chart" { 6 | description = "The name of the chart" 7 | value = try(helm_release.this[0].metadata[0].chart, null) 8 | } 9 | 10 | output "name" { 11 | description = "Name is the name of the release" 12 | value = try(helm_release.this[0].metadata[0].name, null) 13 | } 14 | 15 | output "namespace" { 16 | description = "Name of Kubernetes namespace" 17 | value = try(helm_release.this[0].metadata[0].namespace, null) 18 | } 19 | 20 | output "revision" { 21 | description = "Version is an int32 which represents the version of the release" 22 | value = try(helm_release.this[0].metadata[0].revision, null) 23 | } 24 | 25 | output "version" { 26 | description = "A SemVer 2 conformant version string of the chart" 27 | value = try(helm_release.this[0].metadata[0].version, null) 28 | } 29 | 30 | output "app_version" { 31 | description = "The version number of the application being deployed" 32 | value = try(helm_release.this[0].metadata[0].app_version, null) 33 | } 34 | 35 | output "values" { 36 | description = "The compounded values from `values` and `set*` attributes" 37 | value = try(helm_release.this[0].metadata[0].values, []) 38 | } 39 | 40 | ################################################################################ 41 | # IAM Role for Service Account(s) (IRSA) 42 | ################################################################################ 43 | 44 | output "iam_role_arn" { 45 | description = "ARN of IAM role" 46 | value = try(aws_iam_role.this[0].arn, null) 47 | } 48 | 49 | output "iam_role_name" { 50 | description = "Name of IAM role" 51 | value = try(aws_iam_role.this[0].name, null) 52 | } 53 | 54 | output "iam_role_path" { 55 | description = "Path of IAM role" 56 | value = try(aws_iam_role.this[0].path, null) 57 | } 58 | 59 | output "iam_role_unique_id" { 60 | description = "Unique ID of IAM role" 61 | value = try(aws_iam_role.this[0].unique_id, null) 62 | } 63 | 64 | ################################################################################ 65 | # IAM Policy 66 | ################################################################################ 67 | 68 | output "iam_policy_arn" { 69 | description = "The ARN assigned by AWS to this policy" 70 | value = try(aws_iam_policy.this[0].arn, null) 71 | } 72 | 73 | output "iam_policy" { 74 | description = "The policy document" 75 | value = try(aws_iam_policy.this[0].policy, null) 76 | } 77 | -------------------------------------------------------------------------------- /tests/README.md: -------------------------------------------------------------------------------- 1 | # Amazon EKS Blueprints Addon Tests 2 | 3 | Configuration in this directory provisions: 4 | - An EKS cluster and VPC used to support the example 5 | - An addon (Helm release) for [`metrics-server`](https://github.com/kubernetes-sigs/metrics-server) without an IAM role for service account (IRSA) 6 | - An addon (Helm release) for [`karpenter`](https://github.com/aws/karpenter) with an IAM role for service account (IRSA) 7 | - An IAM role for service account (IRSA) suitable for use by the [AWS VPC-CNI](https://github.com/aws/amazon-vpc-cni-k8s) 8 | 9 | ## Usage 10 | 11 | To run this example you need to execute: 12 | 13 | ```bash 14 | $ terraform init 15 | $ terraform plan 16 | $ terraform apply 17 | ``` 18 | 19 | Note that this example may create resources which will incur monetary charges on your AWS bill. Run `terraform destroy` when you no longer need these resources. 20 | 21 | 22 | ## Requirements 23 | 24 | | Name | Version | 25 | |------|---------| 26 | | [terraform](#requirement\_terraform) | >= 1.0 | 27 | | [aws](#requirement\_aws) | >= 4.47 | 28 | | [helm](#requirement\_helm) | >= 2.9 | 29 | 30 | ## Providers 31 | 32 | | Name | Version | 33 | |------|---------| 34 | | [aws](#provider\_aws) | >= 4.47 | 35 | 36 | ## Modules 37 | 38 | | Name | Source | Version | 39 | |------|--------|---------| 40 | | [disabled](#module\_disabled) | ../ | n/a | 41 | | [eks](#module\_eks) | terraform-aws-modules/eks/aws | ~> 19.16 | 42 | | [helm\_release\_irsa](#module\_helm\_release\_irsa) | ../ | n/a | 43 | | [helm\_release\_only](#module\_helm\_release\_only) | ../ | n/a | 44 | | [irsa\_only](#module\_irsa\_only) | ../ | n/a | 45 | | [vpc](#module\_vpc) | terraform-aws-modules/vpc/aws | ~> 5.0 | 46 | 47 | ## Resources 48 | 49 | | Name | Type | 50 | |------|------| 51 | | [aws_iam_instance_profile.karpenter](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_instance_profile) | resource | 52 | | [aws_iam_policy.karpenter_controller](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/resources/iam_policy) | resource | 53 | | [aws_availability_zones.available](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/availability_zones) | data source | 54 | | [aws_caller_identity.current](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/caller_identity) | data source | 55 | | [aws_iam_policy_document.karpenter_controller](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document) | data source | 56 | 57 | ## Inputs 58 | 59 | No inputs. 60 | 61 | ## Outputs 62 | 63 | | Name | Description | 64 | |------|-------------| 65 | | [helm\_release\_irsa\_app\_version](#output\_helm\_release\_irsa\_app\_version) | The version number of the application being deployed | 66 | | [helm\_release\_irsa\_chart](#output\_helm\_release\_irsa\_chart) | The name of the chart | 67 | | [helm\_release\_irsa\_iam\_role\_arn](#output\_helm\_release\_irsa\_iam\_role\_arn) | ARN of IAM role | 68 | | [helm\_release\_irsa\_iam\_role\_name](#output\_helm\_release\_irsa\_iam\_role\_name) | Name of IAM role | 69 | | [helm\_release\_irsa\_iam\_role\_path](#output\_helm\_release\_irsa\_iam\_role\_path) | Path of IAM role | 70 | | [helm\_release\_irsa\_iam\_role\_unique\_id](#output\_helm\_release\_irsa\_iam\_role\_unique\_id) | Unique ID of IAM role | 71 | | [helm\_release\_irsa\_name](#output\_helm\_release\_irsa\_name) | Name is the name of the release | 72 | | [helm\_release\_irsa\_namespace](#output\_helm\_release\_irsa\_namespace) | Name of Kubernetes namespace | 73 | | [helm\_release\_irsa\_revision](#output\_helm\_release\_irsa\_revision) | Version is an int32 which represents the version of the release | 74 | | [helm\_release\_irsa\_values](#output\_helm\_release\_irsa\_values) | The compounded values from `values` and `set*` attributes | 75 | | [helm\_release\_irsa\_version](#output\_helm\_release\_irsa\_version) | A SemVer 2 conformant version string of the chart | 76 | | [helm\_release\_only\_app\_version](#output\_helm\_release\_only\_app\_version) | The version number of the application being deployed | 77 | | [helm\_release\_only\_chart](#output\_helm\_release\_only\_chart) | The name of the chart | 78 | | [helm\_release\_only\_iam\_role\_arn](#output\_helm\_release\_only\_iam\_role\_arn) | ARN of IAM role | 79 | | [helm\_release\_only\_iam\_role\_name](#output\_helm\_release\_only\_iam\_role\_name) | Name of IAM role | 80 | | [helm\_release\_only\_iam\_role\_path](#output\_helm\_release\_only\_iam\_role\_path) | Path of IAM role | 81 | | [helm\_release\_only\_iam\_role\_unique\_id](#output\_helm\_release\_only\_iam\_role\_unique\_id) | Unique ID of IAM role | 82 | | [helm\_release\_only\_name](#output\_helm\_release\_only\_name) | Name is the name of the release | 83 | | [helm\_release\_only\_namespace](#output\_helm\_release\_only\_namespace) | Name of Kubernetes namespace | 84 | | [helm\_release\_only\_revision](#output\_helm\_release\_only\_revision) | Version is an int32 which represents the version of the release | 85 | | [helm\_release\_only\_values](#output\_helm\_release\_only\_values) | The compounded values from `values` and `set*` attributes | 86 | | [helm\_release\_only\_version](#output\_helm\_release\_only\_version) | A SemVer 2 conformant version string of the chart | 87 | | [irsa\_only\_app\_version](#output\_irsa\_only\_app\_version) | The version number of the application being deployed | 88 | | [irsa\_only\_chart](#output\_irsa\_only\_chart) | The name of the chart | 89 | | [irsa\_only\_iam\_role\_arn](#output\_irsa\_only\_iam\_role\_arn) | ARN of IAM role | 90 | | [irsa\_only\_iam\_role\_name](#output\_irsa\_only\_iam\_role\_name) | Name of IAM role | 91 | | [irsa\_only\_iam\_role\_path](#output\_irsa\_only\_iam\_role\_path) | Path of IAM role | 92 | | [irsa\_only\_iam\_role\_unique\_id](#output\_irsa\_only\_iam\_role\_unique\_id) | Unique ID of IAM role | 93 | | [irsa\_only\_name](#output\_irsa\_only\_name) | Name is the name of the release | 94 | | [irsa\_only\_namespace](#output\_irsa\_only\_namespace) | Name of Kubernetes namespace | 95 | | [irsa\_only\_revision](#output\_irsa\_only\_revision) | Version is an int32 which represents the version of the release | 96 | | [irsa\_only\_values](#output\_irsa\_only\_values) | The compounded values from `values` and `set*` attributes | 97 | | [irsa\_only\_version](#output\_irsa\_only\_version) | A SemVer 2 conformant version string of the chart | 98 | 99 | 100 | Apache-2.0 Licensed. See [LICENSE](https://github.com/aws-ia/terraform-aws-eks-blueprints-addon/blob/main/LICENSE). 101 | -------------------------------------------------------------------------------- /tests/main.tf: -------------------------------------------------------------------------------- 1 | provider "aws" { 2 | region = local.region 3 | } 4 | 5 | provider "helm" { 6 | kubernetes { 7 | host = module.eks.cluster_endpoint 8 | cluster_ca_certificate = base64decode(module.eks.cluster_certificate_authority_data) 9 | 10 | exec { 11 | api_version = "client.authentication.k8s.io/v1beta1" 12 | command = "aws" 13 | # This requires the awscli to be installed locally where Terraform is executed 14 | args = ["eks", "get-token", "--cluster-name", module.eks.cluster_name] 15 | } 16 | } 17 | } 18 | 19 | data "aws_caller_identity" "current" {} 20 | data "aws_availability_zones" "available" {} 21 | 22 | locals { 23 | name = basename(path.cwd) 24 | region = "us-west-2" 25 | account_id = data.aws_caller_identity.current.account_id 26 | 27 | vpc_cidr = "10.0.0.0/16" 28 | azs = slice(data.aws_availability_zones.available.names, 0, 3) 29 | 30 | karpenter_tag_key = "karpenter.sh/discovery/${local.name}" 31 | 32 | tags = { 33 | Example = local.name 34 | GithubRepo = "aws-ia/terraform-aws-eks-blueprints-addon" 35 | } 36 | } 37 | 38 | ################################################################################ 39 | # EKS Blueprints Addon 40 | ################################################################################ 41 | 42 | module "helm_release_only" { 43 | source = "../" 44 | 45 | chart = "metrics-server" 46 | chart_version = "3.8.2" 47 | repository = "https://kubernetes-sigs.github.io/metrics-server/" 48 | description = "Metric server helm Chart deployment configuration" 49 | namespace = "kube-system" 50 | 51 | values = [ 52 | <<-EOT 53 | podDisruptionBudget: 54 | maxUnavailable: 1 55 | metrics: 56 | enabled: true 57 | EOT 58 | ] 59 | 60 | set = [ 61 | { 62 | name = "replicas" 63 | value = 3 64 | } 65 | ] 66 | } 67 | 68 | module "helm_release_irsa" { 69 | source = "../" 70 | 71 | chart = "karpenter" 72 | chart_version = "0.16.2" 73 | repository = "https://charts.karpenter.sh/" 74 | description = "Kubernetes Node Autoscaling: built for flexibility, performance, and simplicity" 75 | namespace = "karpenter" 76 | create_namespace = true 77 | 78 | set = [ 79 | { 80 | name = "clusterName" 81 | value = module.eks.cluster_name 82 | }, 83 | { 84 | name = "clusterEndpoint" 85 | value = module.eks.cluster_endpoint 86 | }, 87 | { 88 | name = "aws.defaultInstanceProfile" 89 | value = aws_iam_instance_profile.karpenter.name 90 | } 91 | ] 92 | 93 | set_irsa_names = ["serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn"] 94 | # # Equivalent to the following but the ARN is only known internally to the module 95 | # set = [{ 96 | # name = "serviceAccount.annotations.eks\\.amazonaws\\.com/role-arn" 97 | # value = iam_role_arn.this[0].arn 98 | # }] 99 | 100 | # IAM role for service account (IRSA) 101 | create_role = true 102 | role_name = "karpenter-controller" 103 | role_policies = { 104 | karpenter = aws_iam_policy.karpenter_controller.arn 105 | } 106 | 107 | oidc_providers = { 108 | this = { 109 | provider_arn = module.eks.oidc_provider_arn 110 | # namespace is inherited from chart 111 | service_account = "karpenter" 112 | } 113 | } 114 | 115 | tags = local.tags 116 | } 117 | 118 | module "irsa_only" { 119 | source = "../" 120 | 121 | # Disable helm release 122 | create_release = false 123 | 124 | # IAM role for service account (IRSA) 125 | create_role = true 126 | role_name = "aws-vpc-cni-ipv4" 127 | role_policies = { 128 | AmazonEKS_CNI_Policy = "arn:aws:iam::aws:policy/AmazonEKS_CNI_Policy" 129 | } 130 | 131 | oidc_providers = { 132 | this = { 133 | provider_arn = module.eks.oidc_provider_arn 134 | namespace = "kube-system" 135 | service_account = "aws-node" 136 | } 137 | } 138 | 139 | tags = local.tags 140 | } 141 | 142 | module "disabled" { 143 | source = "../" 144 | 145 | create = false 146 | } 147 | 148 | ################################################################################ 149 | # Supporting resources 150 | ################################################################################ 151 | 152 | module "eks" { 153 | source = "terraform-aws-modules/eks/aws" 154 | version = "~> 19.16" 155 | 156 | cluster_name = local.name 157 | cluster_version = "1.27" 158 | cluster_endpoint_public_access = true 159 | 160 | vpc_id = module.vpc.vpc_id 161 | subnet_ids = module.vpc.private_subnets 162 | 163 | eks_managed_node_groups = { 164 | initial = { 165 | instance_types = ["m5.large"] 166 | 167 | min_size = 1 168 | max_size = 3 169 | desired_size = 2 170 | } 171 | } 172 | 173 | tags = merge(local.tags, { 174 | # NOTE - if creating multiple security groups with this module, only tag the 175 | # security group that Karpenter should utilize with the following tag 176 | # (i.e. - at most, only one security group should have this tag in your account) 177 | (local.karpenter_tag_key) = local.name 178 | }) 179 | } 180 | 181 | module "vpc" { 182 | source = "terraform-aws-modules/vpc/aws" 183 | version = "~> 5.0" 184 | 185 | name = local.name 186 | cidr = local.vpc_cidr 187 | 188 | azs = local.azs 189 | private_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 4, k)] 190 | public_subnets = [for k, v in local.azs : cidrsubnet(local.vpc_cidr, 8, k + 48)] 191 | 192 | enable_nat_gateway = true 193 | single_nat_gateway = true 194 | 195 | public_subnet_tags = { 196 | "kubernetes.io/role/elb" = 1 197 | } 198 | 199 | private_subnet_tags = { 200 | "kubernetes.io/role/internal-elb" = 1 201 | # Tags subnets for Karpenter auto-discovery 202 | (local.karpenter_tag_key) = local.name 203 | } 204 | 205 | tags = local.tags 206 | } 207 | 208 | resource "aws_iam_instance_profile" "karpenter" { 209 | name = "KarpenterNodeInstanceProfile-${local.name}" 210 | role = module.eks.eks_managed_node_groups["initial"].iam_role_name 211 | 212 | tags = local.tags 213 | } 214 | 215 | data "aws_iam_policy_document" "karpenter_controller" { 216 | statement { 217 | actions = [ 218 | "ec2:CreateLaunchTemplate", 219 | "ec2:CreateFleet", 220 | "ec2:CreateTags", 221 | "ec2:DescribeLaunchTemplates", 222 | "ec2:DescribeImages", 223 | "ec2:DescribeInstances", 224 | "ec2:DescribeSecurityGroups", 225 | "ec2:DescribeSubnets", 226 | "ec2:DescribeInstanceTypes", 227 | "ec2:DescribeInstanceTypeOfferings", 228 | "ec2:DescribeAvailabilityZones", 229 | "ec2:DescribeSpotPriceHistory", 230 | "pricing:GetProducts", 231 | ] 232 | 233 | resources = ["*"] 234 | } 235 | 236 | statement { 237 | actions = [ 238 | "ec2:TerminateInstances", 239 | "ec2:DeleteLaunchTemplate", 240 | ] 241 | 242 | resources = ["*"] 243 | 244 | condition { 245 | test = "StringEquals" 246 | variable = "ec2:ResourceTag/${local.karpenter_tag_key}" 247 | values = [module.eks.cluster_name] 248 | } 249 | } 250 | 251 | statement { 252 | actions = ["ec2:RunInstances"] 253 | resources = [ 254 | "arn:aws:ec2:*:${local.account_id}:launch-template/*", 255 | "arn:aws:ec2:*:${local.account_id}:security-group/*", 256 | ] 257 | 258 | condition { 259 | test = "StringEquals" 260 | variable = "ec2:ResourceTag/${local.karpenter_tag_key}" 261 | values = [module.eks.cluster_name] 262 | } 263 | } 264 | 265 | statement { 266 | actions = ["ec2:RunInstances"] 267 | resources = [ 268 | "arn:aws:ec2:*::image/*", 269 | "arn:aws:ec2:*:${local.account_id}:instance/*", 270 | "arn:aws:ec2:*:${local.account_id}:spot-instances-request/*", 271 | "arn:aws:ec2:*:${local.account_id}:volume/*", 272 | "arn:aws:ec2:*:${local.account_id}:network-interface/*", 273 | "arn:aws:ec2:*:${local.account_id}:subnet/*", 274 | ] 275 | } 276 | 277 | statement { 278 | actions = ["ssm:GetParameter"] 279 | resources = ["arn:aws:ssm:*:*:parameter/aws/service/*"] 280 | } 281 | 282 | statement { 283 | actions = ["iam:PassRole"] 284 | resources = [module.eks.eks_managed_node_groups["initial"].iam_role_arn] 285 | } 286 | } 287 | 288 | resource "aws_iam_policy" "karpenter_controller" { 289 | name_prefix = "Karpenter_Controller_Policy-" 290 | description = "Provides permissions to handle node termination events via the Node Termination Handler" 291 | policy = data.aws_iam_policy_document.karpenter_controller.json 292 | 293 | tags = local.tags 294 | } 295 | -------------------------------------------------------------------------------- /tests/outputs.tf: -------------------------------------------------------------------------------- 1 | ################################################################################ 2 | # Helm Release Only 3 | ################################################################################ 4 | 5 | output "helm_release_only_chart" { 6 | description = "The name of the chart" 7 | value = module.helm_release_only.chart 8 | } 9 | 10 | output "helm_release_only_name" { 11 | description = "Name is the name of the release" 12 | value = module.helm_release_only.name 13 | } 14 | 15 | output "helm_release_only_namespace" { 16 | description = "Name of Kubernetes namespace" 17 | value = module.helm_release_only.namespace 18 | } 19 | 20 | output "helm_release_only_revision" { 21 | description = "Version is an int32 which represents the version of the release" 22 | value = module.helm_release_only.revision 23 | } 24 | 25 | output "helm_release_only_version" { 26 | description = "A SemVer 2 conformant version string of the chart" 27 | value = module.helm_release_only.version 28 | } 29 | 30 | output "helm_release_only_app_version" { 31 | description = "The version number of the application being deployed" 32 | value = module.helm_release_only.app_version 33 | } 34 | 35 | output "helm_release_only_values" { 36 | description = "The compounded values from `values` and `set*` attributes" 37 | value = module.helm_release_only.values 38 | } 39 | 40 | output "helm_release_only_iam_role_arn" { 41 | description = "ARN of IAM role" 42 | value = module.helm_release_only.iam_role_arn 43 | } 44 | 45 | output "helm_release_only_iam_role_name" { 46 | description = "Name of IAM role" 47 | value = module.helm_release_only.iam_role_name 48 | } 49 | 50 | output "helm_release_only_iam_role_path" { 51 | description = "Path of IAM role" 52 | value = module.helm_release_only.iam_role_path 53 | } 54 | 55 | output "helm_release_only_iam_role_unique_id" { 56 | description = "Unique ID of IAM role" 57 | value = module.helm_release_only.iam_role_unique_id 58 | } 59 | 60 | ################################################################################ 61 | # Helm Release & IRSA 62 | ################################################################################ 63 | 64 | output "helm_release_irsa_chart" { 65 | description = "The name of the chart" 66 | value = module.helm_release_irsa.chart 67 | } 68 | 69 | output "helm_release_irsa_name" { 70 | description = "Name is the name of the release" 71 | value = module.helm_release_irsa.name 72 | } 73 | 74 | output "helm_release_irsa_namespace" { 75 | description = "Name of Kubernetes namespace" 76 | value = module.helm_release_irsa.namespace 77 | } 78 | 79 | output "helm_release_irsa_revision" { 80 | description = "Version is an int32 which represents the version of the release" 81 | value = module.helm_release_irsa.revision 82 | } 83 | 84 | output "helm_release_irsa_version" { 85 | description = "A SemVer 2 conformant version string of the chart" 86 | value = module.helm_release_irsa.version 87 | } 88 | 89 | output "helm_release_irsa_app_version" { 90 | description = "The version number of the application being deployed" 91 | value = module.helm_release_irsa.app_version 92 | } 93 | 94 | output "helm_release_irsa_values" { 95 | description = "The compounded values from `values` and `set*` attributes" 96 | value = module.helm_release_irsa.values 97 | } 98 | 99 | output "helm_release_irsa_iam_role_arn" { 100 | description = "ARN of IAM role" 101 | value = module.helm_release_irsa.iam_role_arn 102 | } 103 | 104 | output "helm_release_irsa_iam_role_name" { 105 | description = "Name of IAM role" 106 | value = module.helm_release_irsa.iam_role_name 107 | } 108 | 109 | output "helm_release_irsa_iam_role_path" { 110 | description = "Path of IAM role" 111 | value = module.helm_release_irsa.iam_role_path 112 | } 113 | 114 | output "helm_release_irsa_iam_role_unique_id" { 115 | description = "Unique ID of IAM role" 116 | value = module.helm_release_irsa.iam_role_unique_id 117 | } 118 | 119 | ################################################################################ 120 | # IRSA Only 121 | ################################################################################ 122 | 123 | output "irsa_only_chart" { 124 | description = "The name of the chart" 125 | value = module.irsa_only.chart 126 | } 127 | 128 | output "irsa_only_name" { 129 | description = "Name is the name of the release" 130 | value = module.irsa_only.name 131 | } 132 | 133 | output "irsa_only_namespace" { 134 | description = "Name of Kubernetes namespace" 135 | value = module.irsa_only.namespace 136 | } 137 | 138 | output "irsa_only_revision" { 139 | description = "Version is an int32 which represents the version of the release" 140 | value = module.irsa_only.revision 141 | } 142 | 143 | output "irsa_only_version" { 144 | description = "A SemVer 2 conformant version string of the chart" 145 | value = module.irsa_only.version 146 | } 147 | 148 | output "irsa_only_app_version" { 149 | description = "The version number of the application being deployed" 150 | value = module.irsa_only.app_version 151 | } 152 | 153 | output "irsa_only_values" { 154 | description = "The compounded values from `values` and `set*` attributes" 155 | value = module.irsa_only.values 156 | } 157 | 158 | output "irsa_only_iam_role_arn" { 159 | description = "ARN of IAM role" 160 | value = module.irsa_only.iam_role_arn 161 | } 162 | 163 | output "irsa_only_iam_role_name" { 164 | description = "Name of IAM role" 165 | value = module.irsa_only.iam_role_name 166 | } 167 | 168 | output "irsa_only_iam_role_path" { 169 | description = "Path of IAM role" 170 | value = module.irsa_only.iam_role_path 171 | } 172 | 173 | output "irsa_only_iam_role_unique_id" { 174 | description = "Unique ID of IAM role" 175 | value = module.irsa_only.iam_role_unique_id 176 | } 177 | -------------------------------------------------------------------------------- /tests/variables.tf: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/aws-ia/terraform-aws-eks-blueprints-addon/d4c2dced1838b2b08cb89e71a763236daed481ba/tests/variables.tf -------------------------------------------------------------------------------- /tests/versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 1.0" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 4.47" 8 | } 9 | helm = { 10 | source = "hashicorp/helm" 11 | version = ">= 2.9" 12 | } 13 | } 14 | } 15 | -------------------------------------------------------------------------------- /variables.tf: -------------------------------------------------------------------------------- 1 | variable "create" { 2 | description = "Controls if resources should be created (affects all resources)" 3 | type = bool 4 | default = true 5 | } 6 | 7 | variable "tags" { 8 | description = "A map of tags to add to all resources" 9 | type = map(string) 10 | default = {} 11 | } 12 | 13 | ################################################################################ 14 | # Helm Release 15 | ################################################################################ 16 | 17 | variable "create_release" { 18 | description = "Determines whether the Helm release is created" 19 | type = bool 20 | default = true 21 | } 22 | 23 | variable "name" { 24 | description = "Name of the Helm release" 25 | type = string 26 | default = "" 27 | } 28 | 29 | variable "description" { 30 | description = "Set release description attribute (visible in the history)" 31 | type = string 32 | default = null 33 | } 34 | 35 | variable "namespace" { 36 | description = "The namespace to install the release into. Defaults to `default`" 37 | type = string 38 | default = null 39 | } 40 | 41 | variable "create_namespace" { 42 | description = "Create the namespace if it does not yet exist. Defaults to `false`" 43 | type = bool 44 | default = null 45 | } 46 | 47 | variable "chart" { 48 | description = "Chart name to be installed. The chart name can be local path, a URL to a chart, or the name of the chart if `repository` is specified" 49 | type = string 50 | default = "" 51 | } 52 | 53 | variable "chart_version" { 54 | description = "Specify the exact chart version to install. If this is not specified, the latest version is installed" 55 | type = string 56 | default = null 57 | } 58 | 59 | variable "repository" { 60 | description = "Repository URL where to locate the requested chart" 61 | type = string 62 | default = null 63 | } 64 | 65 | variable "values" { 66 | description = "List of values in raw yaml to pass to helm. Values will be merged, in order, as Helm does with multiple `-f` options" 67 | type = list(string) 68 | default = null 69 | } 70 | 71 | variable "timeout" { 72 | description = "Time in seconds to wait for any individual kubernetes operation (like Jobs for hooks). Defaults to `300` seconds" 73 | type = number 74 | default = null 75 | } 76 | 77 | variable "repository_key_file" { 78 | description = "The repositories cert key file" 79 | type = string 80 | default = null 81 | } 82 | 83 | variable "repository_cert_file" { 84 | description = "The repositories cert file" 85 | type = string 86 | default = null 87 | } 88 | 89 | variable "repository_ca_file" { 90 | description = "The Repositories CA File" 91 | type = string 92 | default = null 93 | } 94 | 95 | variable "repository_username" { 96 | description = "Username for HTTP basic authentication against the repository" 97 | type = string 98 | default = null 99 | } 100 | 101 | variable "repository_password" { 102 | description = "Password for HTTP basic authentication against the repository" 103 | type = string 104 | default = null 105 | } 106 | 107 | variable "devel" { 108 | description = "Use chart development versions, too. Equivalent to version '>0.0.0-0'. If version is set, this is ignored" 109 | type = bool 110 | default = null 111 | } 112 | 113 | variable "verify" { 114 | description = "Verify the package before installing it. Helm uses a provenance file to verify the integrity of the chart; this must be hosted alongside the chart. For more information see the Helm Documentation. Defaults to `false`" 115 | type = bool 116 | default = null 117 | } 118 | 119 | variable "keyring" { 120 | description = "Location of public keys used for verification. Used only if verify is true. Defaults to `/.gnupg/pubring.gpg` in the location set by `home`" 121 | type = string 122 | default = null 123 | } 124 | 125 | variable "disable_webhooks" { 126 | description = "Prevent hooks from running. Defaults to `false`" 127 | type = bool 128 | default = null 129 | } 130 | 131 | variable "reuse_values" { 132 | description = "When upgrading, reuse the last release's values and merge in any overrides. If `reset_values` is specified, this is ignored. Defaults to `false`" 133 | type = bool 134 | default = null 135 | } 136 | 137 | variable "reset_values" { 138 | description = "When upgrading, reset the values to the ones built into the chart. Defaults to `false`" 139 | type = bool 140 | default = null 141 | } 142 | 143 | variable "force_update" { 144 | description = "Force resource update through delete/recreate if needed. Defaults to `false`" 145 | type = bool 146 | default = null 147 | } 148 | 149 | variable "recreate_pods" { 150 | description = "Perform pods restart during upgrade/rollback. Defaults to `false`" 151 | type = bool 152 | default = null 153 | } 154 | 155 | variable "cleanup_on_fail" { 156 | description = "Allow deletion of new resources created in this upgrade when upgrade fails. Defaults to `false`" 157 | type = bool 158 | default = null 159 | } 160 | 161 | variable "max_history" { 162 | description = "Maximum number of release versions stored per release. Defaults to `0` (no limit)" 163 | type = number 164 | default = null 165 | } 166 | 167 | variable "atomic" { 168 | description = "If set, installation process purges chart on fail. The wait flag will be set automatically if atomic is used. Defaults to `false`" 169 | type = bool 170 | default = null 171 | } 172 | 173 | variable "skip_crds" { 174 | description = "If set, no CRDs will be installed. By default, CRDs are installed if not already present. Defaults to `false`" 175 | type = bool 176 | default = null 177 | } 178 | 179 | variable "render_subchart_notes" { 180 | description = "If set, render subchart notes along with the parent. Defaults to `true`" 181 | type = bool 182 | default = null 183 | } 184 | 185 | variable "disable_openapi_validation" { 186 | description = "If set, the installation process will not validate rendered templates against the Kubernetes OpenAPI Schema. Defaults to `false`" 187 | type = bool 188 | default = null 189 | } 190 | 191 | variable "wait" { 192 | description = "Will wait until all resources are in a ready state before marking the release as successful. If set to `true`, it will wait for as long as `timeout`. If set to `null` fallback on `300s` timeout. Defaults to `false`" 193 | type = bool 194 | default = false 195 | } 196 | 197 | variable "wait_for_jobs" { 198 | description = "If wait is enabled, will wait until all Jobs have been completed before marking the release as successful. It will wait for as long as `timeout`. Defaults to `false`" 199 | type = bool 200 | default = null 201 | } 202 | 203 | variable "dependency_update" { 204 | description = "Runs helm dependency update before installing the chart. Defaults to `false`" 205 | type = bool 206 | default = null 207 | } 208 | 209 | variable "replace" { 210 | description = "Re-use the given name, only if that name is a deleted release which remains in the history. This is unsafe in production. Defaults to `false`" 211 | type = bool 212 | default = null 213 | } 214 | 215 | variable "lint" { 216 | description = "Run the helm chart linter during the plan. Defaults to `false`" 217 | type = bool 218 | default = null 219 | } 220 | 221 | variable "postrender" { 222 | description = "Configure a command to run after helm renders the manifest which can alter the manifest contents" 223 | type = any 224 | default = {} 225 | } 226 | 227 | variable "set" { 228 | description = "Value block with custom values to be merged with the values yaml" 229 | type = any 230 | default = [] 231 | } 232 | 233 | variable "set_sensitive" { 234 | description = "Value block with custom sensitive values to be merged with the values yaml that won't be exposed in the plan's diff" 235 | type = any 236 | default = [] 237 | } 238 | 239 | variable "set_irsa_names" { 240 | description = "Value annotations name where IRSA role ARN created by module will be assigned to the `value`" 241 | type = list(string) 242 | default = [] 243 | } 244 | 245 | ################################################################################ 246 | # IAM Role for Service Account(s) (IRSA) 247 | ################################################################################ 248 | 249 | variable "create_role" { 250 | description = "Determines whether to create an IAM role" 251 | type = bool 252 | default = false 253 | } 254 | 255 | variable "role_name" { 256 | description = "Name of IAM role" 257 | type = string 258 | default = null 259 | } 260 | 261 | variable "role_name_use_prefix" { 262 | description = "Determines whether the IAM role name (`role_name`) is used as a prefix" 263 | type = bool 264 | default = true 265 | } 266 | 267 | variable "role_path" { 268 | description = "Path of IAM role" 269 | type = string 270 | default = "/" 271 | } 272 | 273 | variable "role_permissions_boundary_arn" { 274 | description = "Permissions boundary ARN to use for IAM role" 275 | type = string 276 | default = null 277 | } 278 | 279 | variable "role_description" { 280 | description = "IAM Role description" 281 | type = string 282 | default = null 283 | } 284 | 285 | variable "role_policies" { 286 | description = "Policies to attach to the IAM role in `{'static_name' = 'policy_arn'}` format" 287 | type = map(string) 288 | default = {} 289 | } 290 | 291 | variable "oidc_providers" { 292 | description = "Map of OIDC providers where each provider map should contain the `provider_arn`, and `service_accounts`" 293 | type = any 294 | default = {} 295 | } 296 | 297 | variable "max_session_duration" { 298 | description = "Maximum CLI/API session duration in seconds between 3600 and 43200" 299 | type = number 300 | default = null 301 | } 302 | 303 | variable "assume_role_condition_test" { 304 | description = "Name of the [IAM condition operator](https://docs.aws.amazon.com/IAM/latest/UserGuide/reference_policies_elements_condition_operators.html) to evaluate when assuming the role" 305 | type = string 306 | default = "StringEquals" 307 | } 308 | 309 | variable "allow_self_assume_role" { 310 | description = "Determines whether to allow the role to be [assume itself](https://aws.amazon.com/blogs/security/announcing-an-update-to-iam-role-trust-policy-behavior/)" 311 | type = bool 312 | default = false 313 | } 314 | 315 | ################################################################################ 316 | # IAM Policy 317 | ################################################################################ 318 | 319 | variable "create_policy" { 320 | description = "Whether to create an IAM policy that is attached to the IAM role created" 321 | type = bool 322 | default = true 323 | } 324 | 325 | variable "source_policy_documents" { 326 | description = "List of IAM policy documents that are merged together into the exported document. Statements must have unique `sid`s" 327 | type = list(string) 328 | default = [] 329 | } 330 | 331 | variable "override_policy_documents" { 332 | description = "List of IAM policy documents that are merged together into the exported document. In merging, statements with non-blank `sid`s will override statements with the same `sid`" 333 | type = list(string) 334 | default = [] 335 | } 336 | 337 | variable "policy_statements" { 338 | description = "List of IAM policy [statements](https://registry.terraform.io/providers/hashicorp/aws/latest/docs/data-sources/iam_policy_document#statement)" 339 | type = any 340 | default = [] 341 | } 342 | 343 | variable "policy_name" { 344 | description = "Name of IAM policy" 345 | type = string 346 | default = null 347 | } 348 | 349 | variable "policy_name_use_prefix" { 350 | description = "Determines whether the IAM policy name (`policy_name`) is used as a prefix" 351 | type = bool 352 | default = true 353 | } 354 | 355 | variable "policy_path" { 356 | description = "Path of IAM policy" 357 | type = string 358 | default = null 359 | } 360 | 361 | variable "policy_description" { 362 | description = "IAM policy description" 363 | type = string 364 | default = null 365 | } 366 | -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 1.0" 3 | 4 | required_providers { 5 | aws = { 6 | source = "hashicorp/aws" 7 | version = ">= 4.47" 8 | } 9 | helm = { 10 | source = "hashicorp/helm" 11 | version = ">= 2.9" 12 | } 13 | } 14 | } 15 | --------------------------------------------------------------------------------