├── .github ├── ISSUE_TEMPLATE │ ├── bug_report_form.yml │ ├── config.yml │ └── feature_request_form.yml ├── pull_request_template.md └── workflows │ ├── docs.yml │ ├── lint.yml │ └── scan.yml ├── CODE_OF_CONDUCT.md ├── CONTRIBUTING.md ├── LICENSE ├── README.md ├── _data.tf ├── _outputs.tf ├── _variables.tf ├── examples ├── bitbucket.md └── github.md ├── iam-role.tf ├── locals.tf └── versions.tf /.github/ISSUE_TEMPLATE/bug_report_form.yml: -------------------------------------------------------------------------------- 1 | name: Bug Report 2 | description: File a bug report 3 | labels: ["bug"] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thanks for taking the time to fill out this bug report! 9 | - type: input 10 | id: contact 11 | attributes: 12 | label: Contact Details (optional) 13 | description: How can we get in touch with you if we need more info? 14 | placeholder: ex. email@example.com 15 | validations: 16 | required: false 17 | - type: textarea 18 | id: what-happened 19 | attributes: 20 | label: Description. What happened? 21 | description: Also tell us, what did you expect to happen? 22 | placeholder: Tell us what you see! 23 | value: "A bug happened!" 24 | validations: 25 | required: true 26 | - type: textarea 27 | id: steps-to-reproduce 28 | attributes: 29 | label: Steps to reproduce 30 | description: Describe the steps to reproduce. 31 | placeholder: 1. Step 1 ... 32 | 2. Step 2 ... 33 | 3. Step 3 ... 34 | validations: 35 | required: true 36 | - type: textarea 37 | id: expected-behavior 38 | attributes: 39 | label: Expected behavior 40 | description: Describe the expected behavior. 41 | placeholder: The expected behavior is ... 42 | validations: 43 | required: false 44 | - type: textarea 45 | id: actual-behavior 46 | attributes: 47 | label: Actual behavior 48 | description: Describe the actual behavior. 49 | placeholder: The actual behavior is ... 50 | validations: 51 | required: true 52 | - type: dropdown 53 | id: occurrence-frequency 54 | attributes: 55 | label: Occurrence 56 | description: How often this bug occurs? 57 | options: 58 | - Frequently 59 | - Sometimes 60 | - Rarely 61 | validations: 62 | required: true 63 | - type: textarea 64 | id: logs 65 | attributes: 66 | label: Relevant log output 67 | description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. 68 | render: shell 69 | - type: checkboxes 70 | id: terms 71 | attributes: 72 | label: Code of Conduct 73 | description: By submitting this issue, you agree to follow our [Code of Conduct](../blob/main/CODE_OF_CONDUCT.md) 74 | options: 75 | - label: I agree to follow this project's Code of Conduct 76 | required: true -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/config.yml: -------------------------------------------------------------------------------- 1 | blank_issues_enabled: false 2 | contact_links: 3 | - name: DNX One Documentation 4 | url: https://docs.dnx.one 5 | about: At DNX we help your business build better solutions by upgrading how delivery is done, leaving behind manual processes and embracing an automated, cloud-native way of working. 6 | - name: About us 7 | url: https://dnx.solutions/about-us/ 8 | about: Informations about DNX as a company. -------------------------------------------------------------------------------- /.github/ISSUE_TEMPLATE/feature_request_form.yml: -------------------------------------------------------------------------------- 1 | name: Feature Request 2 | description: Suggest an idea for this project 3 | labels: ["feature-request"] 4 | body: 5 | - type: markdown 6 | attributes: 7 | value: | 8 | Thanks for taking the time to fill out this feature request! 9 | - type: input 10 | id: contact 11 | attributes: 12 | label: Contact Details (optional) 13 | description: How can we get in touch with you if we need more info? 14 | placeholder: ex. email@example.com 15 | validations: 16 | required: false 17 | - type: textarea 18 | id: summary 19 | attributes: 20 | label: Summary 21 | description: Describe the requested feature. 22 | validations: 23 | required: true 24 | - type: textarea 25 | id: motivation 26 | attributes: 27 | label: Motivation 28 | description: Describe the motivation behind this feature request. 29 | validations: 30 | required: true 31 | - type: textarea 32 | id: alternatives 33 | attributes: 34 | label: Alternatives 35 | description: Describe the alternatives you've considered. 36 | validations: 37 | required: false 38 | - type: textarea 39 | id: additional-information 40 | attributes: 41 | label: Additional Context 42 | - type: checkboxes 43 | id: terms 44 | attributes: 45 | label: Code of Conduct 46 | description: By submitting this issue, you agree to follow our Code of Conduct](../blob/main/CODE_OF_CONDUCT.md) 47 | options: 48 | - label: I agree to follow this project's Code of Conduct 49 | required: true -------------------------------------------------------------------------------- /.github/pull_request_template.md: -------------------------------------------------------------------------------- 1 | 2 | Describe the big picture of your changes here to communicate to the maintainers why we should accept this pull request. If it fixes a bug or resolves a feature request, be sure to link to that issue. 3 | 4 | ## Types of changes 5 | 6 | What types of changes does your code introduce to ? 7 | _Put an `x` in the boxes that apply_ 8 | 9 | - [ ] Bugfix (non-breaking change which fixes an issue) 10 | - [ ] New feature (non-breaking change which adds functionality) 11 | - [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) 12 | - [ ] Documentation Update (if none of the other choices apply) 13 | 14 | ## Checklist 15 | 16 | _Put an `x` in the boxes that apply. You can also fill these out after creating the PR. If you're unsure about any of them, don't hesitate to ask. We're here to help! This is simply a reminder of what we are going to look for before merging your code._ 17 | 18 | - [ ] I have read the CONTRIBUTING.md doc. 19 | - [ ] I have added necessary documentation (if appropriate). 20 | - [ ] Any dependent changes have been merged and published in downstream modules. 21 | 22 | ## Further comments 23 | 24 | If this is a relatively large or complex change, kick off the discussion by explaining why you chose the solution you did and what alternatives you considered, etc... -------------------------------------------------------------------------------- /.github/workflows/docs.yml: -------------------------------------------------------------------------------- 1 | name: Generate terraform docs 2 | 3 | on: 4 | push: 5 | branches: 6 | - main 7 | 8 | permissions: read-all 9 | 10 | jobs: 11 | docs: 12 | runs-on: ubuntu-latest 13 | steps: 14 | - uses: actions/checkout@v2 15 | with: 16 | ref: main 17 | 18 | - name: Render terraform docs inside the README.md and push changes back to pushed branch 19 | uses: DNXLabs/terraform-docs@v1.0.0 20 | with: 21 | tf_docs_working_dir: . 22 | tf_docs_output_file: README.md 23 | tf_docs_output_method: inject 24 | tf_docs_git_push: 'true' 25 | tf_docs_git_commit_message: 'terraform-docs: automated update action' -------------------------------------------------------------------------------- /.github/workflows/lint.yml: -------------------------------------------------------------------------------- 1 | name: Lint 2 | 3 | on: [push] 4 | 5 | permissions: read-all 6 | 7 | jobs: 8 | tflint: 9 | name: Lint 10 | runs-on: ubuntu-latest 11 | steps: 12 | - uses: actions/checkout@master 13 | - name: TFLint 14 | uses: docker://wata727/tflint 15 | 16 | fmt: 17 | name: Code Format 18 | runs-on: ubuntu-latest 19 | container: 20 | image: hashicorp/terraform:latest 21 | steps: 22 | - uses: actions/checkout@master 23 | - run: terraform fmt --recursive -check=true 24 | 25 | validate: 26 | name: Validate 27 | runs-on: ubuntu-latest 28 | container: 29 | image: hashicorp/terraform:latest 30 | steps: 31 | - uses: actions/checkout@master 32 | - name: Validate Code 33 | env: 34 | AWS_REGION: 'us-east-1' 35 | TF_WARN_OUTPUT_ERRORS: 1 36 | TF_VAR_vpc_id: 'vpc-123456' 37 | TF_VAR_subnets: '["subnet-12345a"]' 38 | TF_VAR_workers_ami_id: 'ami-123456' 39 | TF_VAR_cluster_name: 'test_cluster' 40 | run: | 41 | terraform init 42 | terraform validate 43 | - name: Validate Examples 44 | run: | 45 | for example in $(find examples -maxdepth 1 -mindepth 1 -type d); do 46 | cd $example 47 | terraform init 48 | terraform validate 49 | cd - 50 | done 51 | 52 | minimum: 53 | name: Minimum version check 54 | runs-on: ubuntu-latest 55 | container: 56 | image: hashicorp/terraform:0.13.0 57 | steps: 58 | - uses: actions/checkout@master 59 | - name: Validate Code 60 | env: 61 | AWS_REGION: 'us-east-1' 62 | TF_WARN_OUTPUT_ERRORS: 1 63 | run: | 64 | sed -i -e 's/>=/=/' -e 's/ \(\d\+\.\d\+\)"/ \1.0"/' versions.tf 65 | terraform init 66 | terraform validate -var "region=${AWS_REGION}" -var "vpc_id=vpc-123456" -var "subnets=[\"subnet-12345a\"]" -var "workers_ami_id=ami-123456" -var "cluster_ingress_cidrs=[]" -var "cluster_name=test_cluster" -------------------------------------------------------------------------------- /.github/workflows/scan.yml: -------------------------------------------------------------------------------- 1 | name: Scan 2 | 3 | on: [push] 4 | 5 | permissions: read-all 6 | 7 | jobs: 8 | scan: 9 | runs-on: ubuntu-latest 10 | steps: 11 | - name: Checkout repo 12 | uses: actions/checkout@v3 13 | - name: Run Checkov action 14 | id: checkov 15 | uses: bridgecrewio/checkov-action@v12 16 | with: 17 | directory: . 18 | framework: terraform -------------------------------------------------------------------------------- /CODE_OF_CONDUCT.md: -------------------------------------------------------------------------------- 1 | ## Code of Conduct 2 | 3 | ### Our Pledge 4 | 5 | In the interest of fostering an open and welcoming environment, we as 6 | contributors and maintainers pledge to make participation in our project and 7 | our community a harassment-free experience for everyone, regardless of age, body 8 | size, disability, ethnicity, gender identity and expression, level of experience, 9 | nationality, personal appearance, race, religion, or sexual identity and 10 | orientation. 11 | 12 | ### Our Standards 13 | 14 | Examples of behavior that contributes to creating a positive environment 15 | include: 16 | 17 | * Using welcoming and inclusive language 18 | * Being respectful of differing viewpoints and experiences 19 | * Gracefully accepting constructive criticism 20 | * Focusing on what is best for the community 21 | * Showing empathy towards other community members 22 | 23 | Examples of unacceptable behavior by participants include: 24 | 25 | * The use of sexualized language or imagery and unwelcome sexual attention or 26 | advances 27 | * Trolling, insulting/derogatory comments, and personal or political attacks 28 | * Public or private harassment 29 | * Publishing others' private information, such as a physical or electronic 30 | address, without explicit permission 31 | * Other conduct which could reasonably be considered inappropriate in a 32 | professional setting 33 | 34 | ### Our Responsibilities 35 | 36 | Project maintainers are responsible for clarifying the standards of acceptable 37 | behavior and are expected to take appropriate and fair corrective action in 38 | response to any instances of unacceptable behavior. 39 | 40 | Project maintainers have the right and responsibility to remove, edit, or 41 | reject comments, commits, code, wiki edits, issues, and other contributions 42 | that are not aligned to this Code of Conduct, or to ban temporarily or 43 | permanently any contributor for other behaviors that they deem inappropriate, 44 | threatening, offensive, or harmful. 45 | 46 | ### Scope 47 | 48 | This Code of Conduct applies both within project spaces and in public spaces 49 | when an individual is representing the project or its community. Examples of 50 | representing a project or community include using an official project e-mail 51 | address, posting via an official social media account or acting as an appointed 52 | representative at an online or offline event. Representation of a project may be 53 | further defined and clarified by project maintainers. 54 | 55 | ### Enforcement 56 | 57 | Instances of abusive, harassing, or otherwise, unacceptable behavior may be 58 | reported by contacting the project team at contact@dnx.solutions. All 59 | complaints will be reviewed and investigated and will result in a response that 60 | is deemed necessary and appropriate to the circumstances. The project team is 61 | obligated to maintain confidentiality with regard to the reporter of an incident. 62 | Further details of specific enforcement policies may be posted separately. 63 | 64 | Project maintainers who do not follow or enforce the Code of Conduct in good 65 | faith may face temporary or permanent repercussions as determined by other 66 | members of the project's leadership. -------------------------------------------------------------------------------- /CONTRIBUTING.md: -------------------------------------------------------------------------------- 1 | # Contributing 2 | 3 | When contributing to this repository, please first discuss the change you wish to make via issue, 4 | email, or any other method with the owners of this repository before making a change. 5 | 6 | Please note we have a code of conduct, please follow it in all your interactions over the project. 7 | 8 | ## Reporting Bugs 9 | 10 | This section guides you through submitting a bug report for DNX. Following these guidelines helps maintainers and the community understand your report, reproduce the behavior, and find related reports. 11 | 12 | Before creating bug reports, please check this list as you might find out that you don't need to create one. When you are creating a bug report, please [include as many details as possible](#how-do-i-submit-a-good-bug-report). Fill out [the required template, the information it asks for helps us resolve issues faster. 13 | 14 | 15 | #### How Do I Submit A (Good) Bug Report? 16 | 17 | Bugs are tracked as [GitHub issues](https://guides.github.com/features/issues/). Create an issue on the repository and provide the following information by filling in the template. 18 | 19 | Explain the problem and include additional details to help maintainers reproduce the problem: 20 | 21 | * **Use a clear and descriptive title** for the issue to identify the problem. 22 | * **Describe the exact steps which reproduce the problem** in as many details as possible. For example, start by explaining how you started the module, e.g. which command exactly you used in the terminal. 23 | * **Provide specific examples to demonstrate the steps**. Include links to files or GitHub projects, or copy/pasteable snippets, which you use in those examples. If you're providing snippets in the issue, use [Markdown code blocks](https://docs.github.com/pt/github/writing-on-github/working-with-advanced-formatting/creating-and-highlighting-code-blocks). 24 | * **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior. 25 | * **If the problem wasn't triggered by a specific action**, describe what you were doing before the problem happened and share more information using the guidelines below. 26 | 27 | Provide more context by answering these questions: 28 | 29 | * **Did the problem start happening recently** (e.g. after updating to a new version of Terraform) or was this always a problem? 30 | * If the problem started happening recently, **can you reproduce the problem in an older version of Terraform?** What's the most recent version in which the problem doesn't happen? You can download older versions of Terraform from [the releases page](https://github.com/hashicorp/terraform/releases). 31 | * **Can you reliably reproduce the issue?** If not, provide details about how often the problem happens and under which conditions it normally happens. 32 | * If the problem is related to working with files (e.g. opening and editing files), **does the problem happen for all files and projects or only some?** Does the problem happen only when working with local or remote files (e.g. on network drives), with files of a specific type (e.g. only JavaScript or Python files), with large files or files with very long lines, or with files in a specific encoding? Is there anything else special about the files you are using? 33 | ### Suggesting Enhancements 34 | 35 | This section guides you through submitting an enhancement suggestion for DNX modules, including completely new features and minor improvements to existing functionality. Following these guidelines helps maintainers and the community understand your suggestion and find related suggestions. 36 | 37 | Before creating enhancement suggestions, please check issues as you might find out that you don't need to create one. When you are creating an enhancement suggestion, please include as many details as possible. Fill in the template, including the steps that you imagine you would take if the feature you're requesting existed. 38 | 39 | #### How Do I Submit A (Good) Enhancement Suggestion? 40 | 41 | Enhancement suggestions are tracked as [GitHub issues](https://guides.github.com/features/issues/). Create an issue on that repository and provide the following information: 42 | 43 | * **Use a clear and descriptive title** for the issue to identify the suggestion. 44 | * **Provide a step-by-step description of the suggested enhancement** in as many details as possible. 45 | * **Provide specific examples to demonstrate the steps**. Include copy/pasteable snippets which you use in those examples, as [Markdown code blocks](https://help.github.com/articles/markdown-basics/#multiple-lines). 46 | * **Describe the current behavior** and **explain which behavior you expected to see instead** and why. 47 | * **Include screenshots and animated GIFs** which help you demonstrate the steps or point out the part of code which the suggestion is related. You can use [this tool](https://www.cockos.com/licecap/) to record GIFs on macOS and Windows, and [this tool](https://github.com/colinkeenan/silentcast) or [this tool](https://gitlab.gnome.org/Archive/byzanz) on Linux. 48 | * **Explain why this enhancement would be useful** to most Terraform users and isn't something that can or should be implemented as a community package. 49 | * **Specify which version of Terraform you're using.** You can get the exact version by running `terraform -v` in your terminal. 50 | * **Specify the name and version of the OS you're using.** 51 | 52 | 53 | ## Pull Request Process 54 | 55 | The process described here has several goals: 56 | 57 | - Fix problems that are important to users. 58 | 59 | 1. Update the README.md with details of changes to the interface, this includes new environment variables, exposed ports, useful file locations, and container parameters. 60 | 2. Increase the version numbers in any examples files and the README.md to the new version that this 61 | Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). 62 | 3. You may merge the Pull Request in once you have the sign-off of two other developers, or if you do not have permission to do that, you may request the second reviewer to merge it for you. 63 | 4. Follow all instructions in [the template](./.github/pull_request_template.md). 64 | 5. Follow the [styleguides](https://docs.dnx.one/docs/style-guide/terraform-style-guide.html). 65 | 6. After you submit your pull request, verify that all [status checks](https://help.github.com/articles/about-status-checks/) are passing.
What if the status checks are failing?If a status check is failing, and you believe that the failure is unrelated to your change, please leave a comment on the pull request explaining why you believe the failure is unrelated. A maintainer will re-run the status check for you. If we conclude that the failure was a false positive, then we will open an issue to track that problem with our status check suite.
66 | 67 | While the prerequisites above must be satisfied prior to have your pull request reviewed, the reviewer(s) may ask you to complete additional design work, tests, or other changes before your pull request can be ultimately accepted. 68 | 69 | ### Your First Code Contribution 70 | 71 | Unsure where to begin contributing to DNX? You can start by looking through these `beginner` and `help-wanted` issues: 72 | 73 | * `beginner` - issues that should only require a few lines of code, and a test or two. 74 | * `help-wanted` - issues which should be a bit more involved than `beginner` issues. 75 | 76 | Both issue lists are sorted by the total number of comments. While not perfect, the number of comments is a reasonable proxy for the impact a given change will have. -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | Apache License 2 | Version 2.0, January 2004 3 | http://www.apache.org/licenses/ 4 | 5 | TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION 6 | 7 | 1. Definitions. 8 | 9 | "License" shall mean the terms and conditions for use, reproduction, 10 | and distribution as defined by Sections 1 through 9 of this document. 11 | 12 | "Licensor" shall mean the copyright owner or entity authorized by 13 | the copyright owner that is granting the License. 14 | 15 | "Legal Entity" shall mean the union of the acting entity and all 16 | other entities that control, are controlled by, or are under common 17 | control with that entity. For the purposes of this definition, 18 | "control" means (i) the power, direct or indirect, to cause the 19 | direction or management of such entity, whether by contract or 20 | otherwise, or (ii) ownership of fifty percent (50%) or more of the 21 | outstanding shares, or (iii) beneficial ownership of such entity. 22 | 23 | "You" (or "Your") shall mean an individual or Legal Entity 24 | exercising permissions granted by this License. 25 | 26 | "Source" form shall mean the preferred form for making modifications, 27 | including but not limited to software source code, documentation 28 | source, and configuration files. 29 | 30 | "Object" form shall mean any form resulting from mechanical 31 | transformation or translation of a Source form, including but 32 | not limited to compiled object code, generated documentation, 33 | and conversions to other media types. 34 | 35 | "Work" shall mean the work of authorship, whether in Source or 36 | Object form, made available under the License, as indicated by a 37 | copyright notice that is included in or attached to the work 38 | (an example is provided in the Appendix below). 39 | 40 | "Derivative Works" shall mean any work, whether in Source or Object 41 | form, that is based on (or derived from) the Work and for which the 42 | editorial revisions, annotations, elaborations, or other modifications 43 | represent, as a whole, an original work of authorship. For the purposes 44 | of this License, Derivative Works shall not include works that remain 45 | separable from, or merely link (or bind by name) to the interfaces of, 46 | the Work and Derivative Works thereof. 47 | 48 | "Contribution" shall mean any work of authorship, including 49 | the original version of the Work and any modifications or additions 50 | to that Work or Derivative Works thereof, that is intentionally 51 | submitted to Licensor for inclusion in the Work by the copyright owner 52 | or by an individual or Legal Entity authorized to submit on behalf of 53 | the copyright owner. For the purposes of this definition, "submitted" 54 | means any form of electronic, verbal, or written communication sent 55 | to the Licensor or its representatives, including but not limited to 56 | communication on electronic mailing lists, source code control systems, 57 | and issue tracking systems that are managed by, or on behalf of, the 58 | Licensor for the purpose of discussing and improving the Work, but 59 | excluding communication that is conspicuously marked or otherwise 60 | designated in writing by the copyright owner as "Not a Contribution." 61 | 62 | "Contributor" shall mean Licensor and any individual or Legal Entity 63 | on behalf of whom a Contribution has been received by Licensor and 64 | subsequently incorporated within the Work. 65 | 66 | 2. Grant of Copyright License. Subject to the terms and conditions of 67 | this License, each Contributor hereby grants to You a perpetual, 68 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 69 | copyright license to reproduce, prepare Derivative Works of, 70 | publicly display, publicly perform, sublicense, and distribute the 71 | Work and such Derivative Works in Source or Object form. 72 | 73 | 3. Grant of Patent License. Subject to the terms and conditions of 74 | this License, each Contributor hereby grants to You a perpetual, 75 | worldwide, non-exclusive, no-charge, royalty-free, irrevocable 76 | (except as stated in this section) patent license to make, have made, 77 | use, offer to sell, sell, import, and otherwise transfer the Work, 78 | where such license applies only to those patent claims licensable 79 | by such Contributor that are necessarily infringed by their 80 | Contribution(s) alone or by combination of their Contribution(s) 81 | with the Work to which such Contribution(s) was submitted. If You 82 | institute patent litigation against any entity (including a 83 | cross-claim or counterclaim in a lawsuit) alleging that the Work 84 | or a Contribution incorporated within the Work constitutes direct 85 | or contributory patent infringement, then any patent licenses 86 | granted to You under this License for that Work shall terminate 87 | as of the date such litigation is filed. 88 | 89 | 4. Redistribution. You may reproduce and distribute copies of the 90 | Work or Derivative Works thereof in any medium, with or without 91 | modifications, and in Source or Object form, provided that You 92 | meet the following conditions: 93 | 94 | (a) You must give any other recipients of the Work or 95 | Derivative Works a copy of this License; and 96 | 97 | (b) You must cause any modified files to carry prominent notices 98 | stating that You changed the files; and 99 | 100 | (c) You must retain, in the Source form of any Derivative Works 101 | that You distribute, all copyright, patent, trademark, and 102 | attribution notices from the Source form of the Work, 103 | excluding those notices that do not pertain to any part of 104 | the Derivative Works; and 105 | 106 | (d) If the Work includes a "NOTICE" text file as part of its 107 | distribution, then any Derivative Works that You distribute must 108 | include a readable copy of the attribution notices contained 109 | within such NOTICE file, excluding those notices that do not 110 | pertain to any part of the Derivative Works, in at least one 111 | of the following places: within a NOTICE text file distributed 112 | as part of the Derivative Works; within the Source form or 113 | documentation, if provided along with the Derivative Works; or, 114 | within a display generated by the Derivative Works, if and 115 | wherever such third-party notices normally appear. The contents 116 | of the NOTICE file are for informational purposes only and 117 | do not modify the License. You may add Your own attribution 118 | notices within Derivative Works that You distribute, alongside 119 | or as an addendum to the NOTICE text from the Work, provided 120 | that such additional attribution notices cannot be construed 121 | as modifying the License. 122 | 123 | You may add Your own copyright statement to Your modifications and 124 | may provide additional or different license terms and conditions 125 | for use, reproduction, or distribution of Your modifications, or 126 | for any such Derivative Works as a whole, provided Your use, 127 | reproduction, and distribution of the Work otherwise complies with 128 | the conditions stated in this License. 129 | 130 | 5. Submission of Contributions. Unless You explicitly state otherwise, 131 | any Contribution intentionally submitted for inclusion in the Work 132 | by You to the Licensor shall be under the terms and conditions of 133 | this License, without any additional terms or conditions. 134 | Notwithstanding the above, nothing herein shall supersede or modify 135 | the terms of any separate license agreement you may have executed 136 | with Licensor regarding such Contributions. 137 | 138 | 6. Trademarks. This License does not grant permission to use the trade 139 | names, trademarks, service marks, or product names of the Licensor, 140 | except as required for reasonable and customary use in describing the 141 | origin of the Work and reproducing the content of the NOTICE file. 142 | 143 | 7. Disclaimer of Warranty. Unless required by applicable law or 144 | agreed to in writing, Licensor provides the Work (and each 145 | Contributor provides its Contributions) on an "AS IS" BASIS, 146 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or 147 | implied, including, without limitation, any warranties or conditions 148 | of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A 149 | PARTICULAR PURPOSE. You are solely responsible for determining the 150 | appropriateness of using or redistributing the Work and assume any 151 | risks associated with Your exercise of permissions under this License. 152 | 153 | 8. Limitation of Liability. In no event and under no legal theory, 154 | whether in tort (including negligence), contract, or otherwise, 155 | unless required by applicable law (such as deliberate and grossly 156 | negligent acts) or agreed to in writing, shall any Contributor be 157 | liable to You for damages, including any direct, indirect, special, 158 | incidental, or consequential damages of any character arising as a 159 | result of this License or out of the use or inability to use the 160 | Work (including but not limited to damages for loss of goodwill, 161 | work stoppage, computer failure or malfunction, or any and all 162 | other commercial damages or losses), even if such Contributor 163 | has been advised of the possibility of such damages. 164 | 165 | 9. Accepting Warranty or Additional Liability. While redistributing 166 | the Work or Derivative Works thereof, You may choose to offer, 167 | and charge a fee for, acceptance of support, warranty, indemnity, 168 | or other liability obligations and/or rights consistent with this 169 | License. However, in accepting such obligations, You may act only 170 | on Your own behalf and on Your sole responsibility, not on behalf 171 | of any other Contributor, and only if You agree to indemnify, 172 | defend, and hold each Contributor harmless for any liability 173 | incurred by, or claims asserted against, such Contributor by reason 174 | of your accepting any such warranty or additional liability. 175 | 176 | END OF TERMS AND CONDITIONS 177 | 178 | APPENDIX: How to apply the Apache License to your work. 179 | 180 | To apply the Apache License to your work, attach the following 181 | boilerplate notice, with the fields enclosed by brackets "[]" 182 | replaced with your own identifying information. (Don't include 183 | the brackets!) The text should be enclosed in the appropriate 184 | comment syntax for the file format. We also recommend that a 185 | file or class name and description of purpose be included on the 186 | same "printed page" as the copyright notice for easier 187 | identification within third-party archives. 188 | 189 | Copyright [yyyy] [name of copyright owner] 190 | 191 | Licensed under the Apache License, Version 2.0 (the "License"); 192 | you may not use this file except in compliance with the License. 193 | You may obtain a copy of the License at 194 | 195 | http://www.apache.org/licenses/LICENSE-2.0 196 | 197 | Unless required by applicable law or agreed to in writing, software 198 | distributed under the License is distributed on an "AS IS" BASIS, 199 | WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 200 | See the License for the specific language governing permissions and 201 | limitations under the License. 202 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # terraform-aws-vcs-oidc 2 | 3 | [![Lint Status](https://github.com/DNXLabs/terraform-aws-vcs-oidc/workflows/Lint/badge.svg)](https://github.com/DNXLabs/terraform-aws-vcs-oidc/actions) 4 | [![LICENSE](https://img.shields.io/github/license/DNXLabs/terraform-aws-vcs-oidc)](https://github.com/DNXLabs/terraform-aws-vcs-oidc/blob/main/LICENSE) 5 | 6 | This module sets up IAM Roles and Identity Provider for various VCS(Version Control Systems) providers. 7 | 8 | Supported providers: 9 | - Bitbucket 10 | - GitHub 11 | 12 | The following resources will be created: 13 | - IAM Role. 14 | - IAM Policy attachment. 15 | - IAM Identity Provider Web Identity. 16 | 17 | ## Usage 18 | 19 | - [Bitbucket](examples/bitbucket.md) 20 | - [GitHub](examples/github.md) 21 | 22 | 23 | 24 | 25 | ## Requirements 26 | 27 | | Name | Version | 28 | |------|---------| 29 | | terraform | >= 0.13.0 | 30 | 31 | ## Providers 32 | 33 | | Name | Version | 34 | |------|---------| 35 | | aws | n/a | 36 | | tls | n/a | 37 | 38 | ## Inputs 39 | 40 | | Name | Description | Type | Default | Required | 41 | |------|-------------|------|---------|:--------:| 42 | | audiences | Also known as client ID, audience is a value that identifies the application that is registered with an OpenID Connect provider. | `list(string)` | n/a | yes | 43 | | identity\_provider\_url | Specify the secure OpenID Connect URL for authentication requests. | `string` | n/a | yes | 44 | | oidc\_thumbprint | Thumbprint of OIDC host. See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html | `string` | `""` | no | 45 | | roles | List of roles to create. | `list(any)` | `[]` | no | 46 | 47 | ## Outputs 48 | 49 | | Name | Description | 50 | |------|-------------| 51 | | identity\_provider\_arn | n/a | 52 | | roles | n/a | 53 | 54 | 55 | 56 | ## Authors 57 | 58 | Module managed by [DNX Solutions](https://github.com/DNXLabs). 59 | 60 | ## License 61 | 62 | Apache 2 Licensed. See [LICENSE](https://github.com/DNXLabs/terraform-aws-vcs-oidc/blob/main/LICENSE) for full details. 63 | -------------------------------------------------------------------------------- /_data.tf: -------------------------------------------------------------------------------- 1 | data "aws_caller_identity" "current" {} 2 | 3 | data "tls_certificate" "thumprint" { 4 | url = var.identity_provider_url 5 | } -------------------------------------------------------------------------------- /_outputs.tf: -------------------------------------------------------------------------------- 1 | output "roles" { 2 | value = { for role_name, role_values in element(aws_iam_role.default.*, 0) : role_name => role_values.arn } 3 | } 4 | 5 | output "identity_provider_arn" { 6 | value = aws_iam_openid_connect_provider.default.arn 7 | } -------------------------------------------------------------------------------- /_variables.tf: -------------------------------------------------------------------------------- 1 | variable "identity_provider_url" { 2 | type = string 3 | description = "Specify the secure OpenID Connect URL for authentication requests." 4 | } 5 | 6 | variable "audiences" { 7 | type = list(string) 8 | description = "Also known as client ID, audience is a value that identifies the application that is registered with an OpenID Connect provider." 9 | } 10 | 11 | variable "roles" { 12 | type = list(any) 13 | default = [] 14 | description = "List of roles to create." 15 | } 16 | 17 | variable "oidc_thumbprint" { 18 | type = string 19 | default = "" 20 | description = "Thumbprint of OIDC host. See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html" 21 | } -------------------------------------------------------------------------------- /examples/bitbucket.md: -------------------------------------------------------------------------------- 1 | # Bitbucket 2 | 3 | Use OpenID Connect (OIDC) to allow your pipelines to access your resource server, such as AWS, GCP, or Vault. Below is all the information required to setup an OIDC identity provider on your resource server. [Learn more](https://support.atlassian.com/bitbucket-cloud/docs/integrate-pipelines-with-resource-servers-using-oidc/) 4 | 5 | In this step, you are going to configure your build to the assume the role created in the previous step. You need to enable your BitbucketCI step to create a unique OIDC token that can be used to assume a role and request a temporary credential. This token is exposed as an environment variable `BITBUCKET_STEP_OIDC_TOKEN`. 6 | 7 | https://support.atlassian.com/bitbucket-cloud/docs/deploy-on-aws-using-bitbucket-pipelines-openid-connect 8 | 9 | To find information about indentity provider URL and Audience go to `https://bitbucket.org///admin/addon/admin/pipelines/openid-connect` 10 | 11 | #### Terraform setup 12 | 13 | ```bash 14 | module "bitbucket_oidc" { 15 | source = "git::https://github.com/DNXLabs/terraform-aws-vcs-oidc.git" 16 | 17 | identity_provider_url = "https://api.bitbucket.org/2.0/workspaces/{WORKSPACE}/pipelines-config/identity/oidc" 18 | audiences = [ 19 | "ari:cloud:bitbucket::workspace/{WORKSPACE-UUID}" 20 | ] 21 | 22 | roles = [ 23 | { 24 | name = "CIDeployBitbucket" 25 | assume_roles = [ 26 | "arn:aws:iam::*:role/InfraDeployAccess" # Optional 27 | ] 28 | assume_policies = [ 29 | "arn:aws:iam::aws:policy/AdministratorAccess" # Optional 30 | ] 31 | conditions = [ 32 | { 33 | test = "ForAnyValue:StringLike" 34 | variable = "api.bitbucket.org/2.0/workspaces/{WORKSPACE}/pipelines-config/identity/oidc:sub" 35 | # {REPOSITORY_UUID}*:{ENVIRONMENT_UUID}:* or {REPOSITORY_UUID}:* 36 | # Max of ~30 conditions. 37 | values = "*:*" 38 | }, 39 | { # Limit only assumes requests coming from Bitbucket Pipelines IP to assume the role. 40 | test = "IpAddress" 41 | variable = "aws:SourceIp" 42 | values = [ 43 | "34.199.54.113/32", 44 | "34.232.25.90/32", 45 | "34.232.119.183/32", 46 | "34.236.25.177/32", 47 | "35.171.175.212/32", 48 | "52.54.90.98/32", 49 | "52.202.195.162/32", 50 | "52.203.14.55/32", 51 | "52.204.96.37/32", 52 | "34.218.156.209/32", 53 | "34.218.168.212/32", 54 | "52.41.219.63/32", 55 | "35.155.178.254/32", 56 | "35.160.177.10/32", 57 | "34.216.18.129/32" 58 | ] 59 | } 60 | ] 61 | } 62 | ] 63 | } 64 | ``` 65 | 66 | #### Example of bitbucket-pipelines.yml file 67 | 68 | ```yml 69 | image: amazon/aws-cli 70 | 71 | pipelines: 72 | default: 73 | - step: 74 | oidc: true 75 | script: 76 | - export AWS_REGION=us-west-2 77 | - export AWS_ROLE_ARN=arn:aws:iam:::role/ 78 | - export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token 79 | - echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token 80 | - aws sts get-caller-identity 81 | ``` 82 | 83 | > The above code is an example of bitbucket-pipelines.yml file that assumes the role to request temporary credentials that can be used to access AWS resources. -------------------------------------------------------------------------------- /examples/github.md: -------------------------------------------------------------------------------- 1 | # GitHub 2 | 3 | GitHub Actions has the functionality that can vendor OpenID Connect credentials to jobs running on the platform. This is very exciting for AWS account administrators as it means that CI/CD jobs no longer need any long-term secrets to be stored in GitHub. But enough of that, here’s how it works: 4 | 5 | First, an AWS IAM OIDC identity provider and an AWS IAM role that GitHub Actions can assume. You can do that by deploying this terraform module template to your account. 6 | 7 | #### Terraform setup 8 | 9 | ```bash 10 | module "github_oidc" { 11 | source = "git::https://github.com/DNXLabs/terraform-aws-vcs-oidc.git" 12 | 13 | identity_provider_url = "https://token.actions.githubusercontent.com" 14 | audiences = [ 15 | "https://github.com//" 16 | ] 17 | 18 | roles = [ 19 | { 20 | name = "InfraDeployGithub" 21 | assume_roles = [ 22 | "arn:aws:iam::*:role/InfraDeployAccess" # Optional 23 | ] 24 | assume_policies = [ 25 | "arn:aws:iam::aws:policy/AdministratorAccess" # Optional 26 | ] 27 | conditions = [ 28 | { 29 | test = "ForAnyValue:StringLike" 30 | variable = "vstoken.actions.githubusercontent.com:sub" 31 | values = "repo:/:*" # Max of ~30 conditions. 32 | } 33 | ] 34 | } 35 | ] 36 | } 37 | ``` 38 | 39 | Next, the GitHub workflow definition. Put this in a repo: 40 | 41 | #### Example of workflow yml file 42 | 43 | Parameters to change: 44 | - `Account id` inside `AWS_ROLE_ARN` variable. 45 | - `Role name` inside `AWS_ROLE_ARN` variable. 46 | 47 | ```yml 48 | name: OIDC 49 | on: 50 | push: 51 | branches: 52 | - master 53 | jobs: 54 | deploy: 55 | name: OIDC 56 | runs-on: ubuntu-latest 57 | permissions: 58 | id-token: write 59 | contents: read 60 | steps: 61 | - run: sleep 5 62 | - name: Checkout 63 | uses: actions/checkout@v2 64 | - name: Configure AWS 65 | run: | 66 | export AWS_ROLE_ARN=arn:aws:iam:::role/ 67 | export AWS_WEB_IDENTITY_TOKEN_FILE=/tmp/awscreds 68 | export AWS_DEFAULT_REGION=us-west-2 69 | 70 | echo AWS_WEB_IDENTITY_TOKEN_FILE=$AWS_WEB_IDENTITY_TOKEN_FILE >> $GITHUB_ENV 71 | echo AWS_ROLE_ARN=$AWS_ROLE_ARN >> $GITHUB_ENV 72 | echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION >> $GITHUB_ENV 73 | 74 | curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r '.value' > $AWS_WEB_IDENTITY_TOKEN_FILE 75 | - name: get-caller-identity 76 | run: | 77 | aws sts get-caller-identity 78 | ``` 79 | 80 | You now have a GitHub Actions workflow that assumes your role. It works because the AWS SDKs (and AWS CLI) support using the `AWS_WEB_IDENTITY_TOKEN_FILE` and `AWS_ROLE_ARN` environment variables since AWS EKS needed this. 81 | 82 | ### Some potential trust policies 83 | 84 | Maybe you want an IAM role that can be assumed by any branch in any repo in your GitHub org, e.g. with relatively few permissions needed for PRs. You can do this: 85 | 86 | ``` 87 | conditions = [ 88 | { 89 | test = "ForAnyValue:StringLike" 90 | variable = "vstoken.actions.githubusercontent.com:sub" 91 | values = "repo:/*" 92 | ] 93 | ``` 94 | 95 | Maybe you want an IAM role scoped only to workflows on the main branches, because this will be doing sensitive deployments. In that case, you can do: 96 | 97 | ``` 98 | conditions = [ 99 | { 100 | test = "ForAnyValue:StringLike" 101 | variable = "vstoken.actions.githubusercontent.com:sub" 102 | values = "repo:/*:ref:refs/heads/main" 103 | } 104 | ] 105 | ``` 106 | 107 | Take a look at [glassechidna/ghaoidc](https://github.com/glassechidna/ghaoidc) in case you want to implement JWT claims as role session tags to your action. -------------------------------------------------------------------------------- /iam-role.tf: -------------------------------------------------------------------------------- 1 | resource "aws_iam_role" "default" { 2 | for_each = { for role in var.roles : role.name => role } 3 | name = each.value.name 4 | assume_role_policy = data.aws_iam_policy_document.assume_role_saml[each.key].json 5 | } 6 | 7 | resource "aws_iam_role_policy_attachment" "default" { 8 | for_each = { for role in local.assume_policies_flatten : role.index => role } 9 | role = each.value.role_name 10 | policy_arn = data.aws_iam_policy.default[each.key].arn 11 | 12 | depends_on = [aws_iam_role.default] 13 | } 14 | 15 | data "aws_iam_policy" "default" { 16 | for_each = { for role in local.assume_policies_flatten : role.index => role } 17 | arn = each.value.assume_policy 18 | } 19 | 20 | data "aws_iam_policy_document" "assume_role_saml" { 21 | for_each = { for role in var.roles : role.name => role } 22 | 23 | statement { 24 | principals { 25 | type = "Federated" 26 | identifiers = [ 27 | "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${replace(var.identity_provider_url, "https://", "")}" 28 | ] 29 | } 30 | actions = ["sts:AssumeRoleWithWebIdentity"] 31 | 32 | dynamic "condition" { 33 | for_each = each.value.conditions 34 | content { 35 | test = condition.value.test 36 | variable = condition.value.variable 37 | values = condition.value.values 38 | } 39 | } 40 | } 41 | } 42 | 43 | resource "aws_iam_role_policy" "assume_role" { 44 | for_each = { for role in local.assume_roles_flatten : role.index => role } 45 | name_prefix = "${each.value.name}-${element(split("/", each.value.assume_role), 1)}" 46 | role = each.value.name 47 | 48 | policy = jsonencode({ 49 | Version = "2012-10-17" 50 | Statement = [ 51 | { 52 | Action = [ 53 | "sts:AssumeRole", 54 | ] 55 | Effect = "Allow" 56 | Resource = each.value.assume_role 57 | }, 58 | ] 59 | }) 60 | 61 | depends_on = [aws_iam_role.default] 62 | } 63 | 64 | resource "aws_iam_openid_connect_provider" "default" { 65 | url = var.identity_provider_url 66 | 67 | client_id_list = var.audiences 68 | 69 | thumbprint_list = compact([ 70 | var.oidc_thumbprint != "" ? var.oidc_thumbprint : "", 71 | data.tls_certificate.thumprint.certificates.0.sha1_fingerprint 72 | ]) 73 | } -------------------------------------------------------------------------------- /locals.tf: -------------------------------------------------------------------------------- 1 | locals { 2 | assume_roles_flatten = flatten([ 3 | for role_key, role in var.roles : [ 4 | for assume_role in role.assume_roles : { 5 | index = format("%s-%s", role.name, element(split("/", assume_role), 1)) 6 | name = role.name 7 | assume_role = assume_role 8 | conditions = role.conditions 9 | } 10 | ] 11 | ]) 12 | assume_policies_flatten = flatten([ 13 | for role_key, role in var.roles : [ 14 | for assume_policy in role.assume_policies : { 15 | index = format("%s-%s", role.name, element(split("/", assume_policy), 1)) 16 | role_name = role.name 17 | assume_policy = assume_policy 18 | } 19 | ] 20 | ]) 21 | } -------------------------------------------------------------------------------- /versions.tf: -------------------------------------------------------------------------------- 1 | terraform { 2 | required_version = ">= 0.13.0" 3 | } --------------------------------------------------------------------------------