From 9200cbbdef4ce1ae00500ff0c35690757af31b9d Mon Sep 17 00:00:00 2001 From: Arthur Diniz Date: Tue, 5 Oct 2021 16:31:55 -0300 Subject: [PATCH] Initial commit Signed-off-by: Arthur Diniz --- .github/ISSUE_TEMPLATE/bug_report_form.yml | 76 +++++++ .github/ISSUE_TEMPLATE/config.yml | 8 + .../ISSUE_TEMPLATE/feature_request_form.yml | 49 +++++ .github/pull_request_template.md | 24 +++ .github/workflows/docs.yml | 23 ++ .github/workflows/lint.yml | 64 ++++++ CODE_OF_CONDUCT.md | 66 ++++++ CONTRIBUTING.md | 76 +++++++ LICENSE | 201 ++++++++++++++++++ README.md | 34 +++ _data.tf | 5 + _outputs.tf | 7 + _variables.tf | 21 ++ examples/bitbucket.md | 83 ++++++++ examples/github.md | 107 ++++++++++ iam-role.tf | 73 +++++++ locals.tf | 21 ++ versions.tf | 3 + 18 files changed, 941 insertions(+) create mode 100644 .github/ISSUE_TEMPLATE/bug_report_form.yml create mode 100644 .github/ISSUE_TEMPLATE/config.yml create mode 100644 .github/ISSUE_TEMPLATE/feature_request_form.yml create mode 100644 .github/pull_request_template.md create mode 100644 .github/workflows/docs.yml create mode 100644 .github/workflows/lint.yml create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 _data.tf create mode 100644 _outputs.tf create mode 100644 _variables.tf create mode 100644 examples/bitbucket.md create mode 100644 examples/github.md create mode 100644 iam-role.tf create mode 100644 locals.tf create mode 100644 versions.tf diff --git a/.github/ISSUE_TEMPLATE/bug_report_form.yml b/.github/ISSUE_TEMPLATE/bug_report_form.yml new file mode 100644 index 0000000..438e70c --- /dev/null +++ b/.github/ISSUE_TEMPLATE/bug_report_form.yml @@ -0,0 +1,76 @@ +name: Bug Report +description: File a bug report +labels: ["bug"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this bug report! + - type: input + id: contact + attributes: + label: Contact Details (optional) + description: How can we get in touch with you if we need more info? + placeholder: ex. email@example.com + validations: + required: false + - type: textarea + id: what-happened + attributes: + label: Description. What happened? + description: Also tell us, what did you expect to happen? + placeholder: Tell us what you see! + value: "A bug happened!" + validations: + required: true + - type: textarea + id: steps-to-reproduce + attributes: + label: Steps to reproduce + description: Describe the steps to reproduce. + placeholder: 1. Step 1 ... + 2. Step 2 ... + 3. Step 3 ... + validations: + required: true + - type: textarea + id: expected-behavior + attributes: + label: Expected behavior + description: Describe the expected behavior. + placeholder: The expected behavior is ... + validations: + required: false + - type: textarea + id: actual-behavior + attributes: + label: Actual behavior + description: Describe the actual behavior. + placeholder: The actual behavior is ... + validations: + required: true + - type: dropdown + id: occurrence-frequency + attributes: + label: Occurrence + description: How often this bug occurs? + options: + - Frequently + - Sometimes + - Rarely + validations: + required: true + - type: textarea + id: logs + attributes: + label: Relevant log output + description: Please copy and paste any relevant log output. This will be automatically formatted into code, so no need for backticks. + render: shell + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our [Code of Conduct](../blob/main/CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/config.yml b/.github/ISSUE_TEMPLATE/config.yml new file mode 100644 index 0000000..9451ca3 --- /dev/null +++ b/.github/ISSUE_TEMPLATE/config.yml @@ -0,0 +1,8 @@ +blank_issues_enabled: false +contact_links: + - name: DNX One Documentation + url: https://docs.dnx.one + 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. + - name: About us + url: https://dnx.solutions/about-us/ + about: Informations about DNX as a company. \ No newline at end of file diff --git a/.github/ISSUE_TEMPLATE/feature_request_form.yml b/.github/ISSUE_TEMPLATE/feature_request_form.yml new file mode 100644 index 0000000..75d99ad --- /dev/null +++ b/.github/ISSUE_TEMPLATE/feature_request_form.yml @@ -0,0 +1,49 @@ +name: Feature Request +description: Suggest an idea for this project +labels: ["feature-request"] +body: + - type: markdown + attributes: + value: | + Thanks for taking the time to fill out this feature request! + - type: input + id: contact + attributes: + label: Contact Details (optional) + description: How can we get in touch with you if we need more info? + placeholder: ex. email@example.com + validations: + required: false + - type: textarea + id: summary + attributes: + label: Summary + description: Describe the requested feature. + validations: + required: true + - type: textarea + id: motivation + attributes: + label: Motivation + description: Describe the motivation behind this feature request. + validations: + required: true + - type: textarea + id: alternatives + attributes: + label: Alternatives + description: Describe the alternatives you've considered. + validations: + required: false + - type: textarea + id: additional-information + attributes: + label: Additional Context + - type: checkboxes + id: terms + attributes: + label: Code of Conduct + description: By submitting this issue, you agree to follow our Code of Conduct](../blob/main/CODE_OF_CONDUCT.md) + options: + - label: I agree to follow this project's Code of Conduct + required: true \ No newline at end of file diff --git a/.github/pull_request_template.md b/.github/pull_request_template.md new file mode 100644 index 0000000..a268438 --- /dev/null +++ b/.github/pull_request_template.md @@ -0,0 +1,24 @@ + +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. + +## Types of changes + +What types of changes does your code introduce to ? +_Put an `x` in the boxes that apply_ + +- [ ] Bugfix (non-breaking change which fixes an issue) +- [ ] New feature (non-breaking change which adds functionality) +- [ ] Breaking change (fix or feature that would cause existing functionality to not work as expected) +- [ ] Documentation Update (if none of the other choices apply) + +## Checklist + +_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._ + +- [ ] I have read the CONTRIBUTING.md doc. +- [ ] I have added necessary documentation (if appropriate). +- [ ] Any dependent changes have been merged and published in downstream modules. + +## Further comments + +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... \ No newline at end of file diff --git a/.github/workflows/docs.yml b/.github/workflows/docs.yml new file mode 100644 index 0000000..1a4cd54 --- /dev/null +++ b/.github/workflows/docs.yml @@ -0,0 +1,23 @@ +name: Generate terraform docs + +on: + push: + branches: + - main + +jobs: + docs: + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v2 + with: + ref: main + + - name: Render terraform docs inside the README.md and push changes back to pushed branch + uses: DNXLabs/terraform-docs@v1.0.0 + with: + tf_docs_working_dir: . + tf_docs_output_file: README.md + tf_docs_output_method: inject + tf_docs_git_push: 'true' + tf_docs_git_commit_message: 'terraform-docs: automated update action' \ No newline at end of file diff --git a/.github/workflows/lint.yml b/.github/workflows/lint.yml new file mode 100644 index 0000000..2658549 --- /dev/null +++ b/.github/workflows/lint.yml @@ -0,0 +1,64 @@ +name: Lint + +on: [push] + +jobs: + tflint: + name: Lint + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@master + - name: TFLint + uses: docker://wata727/tflint + + fmt: + name: Code Format + runs-on: ubuntu-latest + container: + image: hashicorp/terraform:latest + steps: + - uses: actions/checkout@master + - run: terraform fmt --recursive -check=true + + validate: + name: Validate + runs-on: ubuntu-latest + container: + image: hashicorp/terraform:latest + steps: + - uses: actions/checkout@master + - name: Validate Code + env: + AWS_REGION: 'us-east-1' + TF_WARN_OUTPUT_ERRORS: 1 + TF_VAR_vpc_id: 'vpc-123456' + TF_VAR_subnets: '["subnet-12345a"]' + TF_VAR_workers_ami_id: 'ami-123456' + TF_VAR_cluster_name: 'test_cluster' + run: | + terraform init + terraform validate + - name: Validate Examples + run: | + for example in $(find examples -maxdepth 1 -mindepth 1 -type d); do + cd $example + terraform init + terraform validate + cd - + done + + minimum: + name: Minimum version check + runs-on: ubuntu-latest + container: + image: hashicorp/terraform:0.13.0 + steps: + - uses: actions/checkout@master + - name: Validate Code + env: + AWS_REGION: 'us-east-1' + TF_WARN_OUTPUT_ERRORS: 1 + run: | + sed -i -e 's/>=/=/' -e 's/ \(\d\+\.\d\+\)"/ \1.0"/' versions.tf + terraform init + 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" \ No newline at end of file diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..d8d15f6 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,66 @@ +## Code of Conduct + +### Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to make participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, gender identity and expression, level of experience, +nationality, personal appearance, race, religion, or sexual identity and +orientation. + +### Our Standards + +Examples of behavior that contributes to creating a positive environment +include: + +* Using welcoming and inclusive language +* Being respectful of differing viewpoints and experiences +* Gracefully accepting constructive criticism +* Focusing on what is best for the community +* Showing empathy towards other community members + +Examples of unacceptable behavior by participants include: + +* The use of sexualized language or imagery and unwelcome sexual attention or +advances +* Trolling, insulting/derogatory comments, and personal or political attacks +* Public or private harassment +* Publishing others' private information, such as a physical or electronic + address, without explicit permission +* Other conduct which could reasonably be considered inappropriate in a + professional setting + +### Our Responsibilities + +Project maintainers are responsible for clarifying the standards of acceptable +behavior and are expected to take appropriate and fair corrective action in +response to any instances of unacceptable behavior. + +Project maintainers have the right and responsibility to remove, edit, or +reject comments, commits, code, wiki edits, issues, and other contributions +that are not aligned to this Code of Conduct, or to ban temporarily or +permanently any contributor for other behaviors that they deem inappropriate, +threatening, offensive, or harmful. + +### Scope + +This Code of Conduct applies both within project spaces and in public spaces +when an individual is representing the project or its community. Examples of +representing a project or community include using an official project e-mail +address, posting via an official social media account or acting as an appointed +representative at an online or offline event. Representation of a project may be +further defined and clarified by project maintainers. + +### Enforcement + +Instances of abusive, harassing, or otherwise, unacceptable behavior may be +reported by contacting the project team at contact@dnx.solutions. All +complaints will be reviewed and investigated and will result in a response that +is deemed necessary and appropriate to the circumstances. The project team is +obligated to maintain confidentiality with regard to the reporter of an incident. +Further details of specific enforcement policies may be posted separately. + +Project maintainers who do not follow or enforce the Code of Conduct in good +faith may face temporary or permanent repercussions as determined by other +members of the project's leadership. \ No newline at end of file diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..059a1e4 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,76 @@ +# Contributing + +When contributing to this repository, please first discuss the change you wish to make via issue, +email, or any other method with the owners of this repository before making a change. + +Please note we have a code of conduct, please follow it in all your interactions over the project. + +## Reporting Bugs + +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. + +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. + + +#### How Do I Submit A (Good) Bug Report? + +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. + +Explain the problem and include additional details to help maintainers reproduce the problem: + +* **Use a clear and descriptive title** for the issue to identify the problem. +* **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. +* **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). +* **Describe the behavior you observed after following the steps** and point out what exactly is the problem with that behavior. +* **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. + +Provide more context by answering these questions: + +* **Did the problem start happening recently** (e.g. after updating to a new version of Terraform) or was this always a problem? +* 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). +* **Can you reliably reproduce the issue?** If not, provide details about how often the problem happens and under which conditions it normally happens. +* 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? +### Suggesting Enhancements + +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. + +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. + +#### How Do I Submit A (Good) Enhancement Suggestion? + +Enhancement suggestions are tracked as [GitHub issues](https://guides.github.com/features/issues/). Create an issue on that repository and provide the following information: + +* **Use a clear and descriptive title** for the issue to identify the suggestion. +* **Provide a step-by-step description of the suggested enhancement** in as many details as possible. +* **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). +* **Describe the current behavior** and **explain which behavior you expected to see instead** and why. +* **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. +* **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. +* **Specify which version of Terraform you're using.** You can get the exact version by running `terraform -v` in your terminal. +* **Specify the name and version of the OS you're using.** + + +## Pull Request Process + +The process described here has several goals: + +- Fix problems that are important to users. + +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. +2. Increase the version numbers in any examples files and the README.md to the new version that this + Pull Request would represent. The versioning scheme we use is [SemVer](http://semver.org/). +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. +4. Follow all instructions in [the template](./.github/pull_request_template.md). +5. Follow the [styleguides](https://docs.dnx.one/docs/style-guide/terraform-style-guide.html). +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.
+ +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. + +### Your First Code Contribution + +Unsure where to begin contributing to DNX? You can start by looking through these `beginner` and `help-wanted` issues: + +* `beginner` - issues that should only require a few lines of code, and a test or two. +* `help-wanted` - issues which should be a bit more involved than `beginner` issues. + +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. \ No newline at end of file diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..261eeb9 --- /dev/null +++ b/LICENSE @@ -0,0 +1,201 @@ + Apache License + Version 2.0, January 2004 + http://www.apache.org/licenses/ + + TERMS AND CONDITIONS FOR USE, REPRODUCTION, AND DISTRIBUTION + + 1. Definitions. + + "License" shall mean the terms and conditions for use, reproduction, + and distribution as defined by Sections 1 through 9 of this document. + + "Licensor" shall mean the copyright owner or entity authorized by + the copyright owner that is granting the License. + + "Legal Entity" shall mean the union of the acting entity and all + other entities that control, are controlled by, or are under common + control with that entity. For the purposes of this definition, + "control" means (i) the power, direct or indirect, to cause the + direction or management of such entity, whether by contract or + otherwise, or (ii) ownership of fifty percent (50%) or more of the + outstanding shares, or (iii) beneficial ownership of such entity. + + "You" (or "Your") shall mean an individual or Legal Entity + exercising permissions granted by this License. + + "Source" form shall mean the preferred form for making modifications, + including but not limited to software source code, documentation + source, and configuration files. + + "Object" form shall mean any form resulting from mechanical + transformation or translation of a Source form, including but + not limited to compiled object code, generated documentation, + and conversions to other media types. + + "Work" shall mean the work of authorship, whether in Source or + Object form, made available under the License, as indicated by a + copyright notice that is included in or attached to the work + (an example is provided in the Appendix below). + + "Derivative Works" shall mean any work, whether in Source or Object + form, that is based on (or derived from) the Work and for which the + editorial revisions, annotations, elaborations, or other modifications + represent, as a whole, an original work of authorship. For the purposes + of this License, Derivative Works shall not include works that remain + separable from, or merely link (or bind by name) to the interfaces of, + the Work and Derivative Works thereof. + + "Contribution" shall mean any work of authorship, including + the original version of the Work and any modifications or additions + to that Work or Derivative Works thereof, that is intentionally + submitted to Licensor for inclusion in the Work by the copyright owner + or by an individual or Legal Entity authorized to submit on behalf of + the copyright owner. For the purposes of this definition, "submitted" + means any form of electronic, verbal, or written communication sent + to the Licensor or its representatives, including but not limited to + communication on electronic mailing lists, source code control systems, + and issue tracking systems that are managed by, or on behalf of, the + Licensor for the purpose of discussing and improving the Work, but + excluding communication that is conspicuously marked or otherwise + designated in writing by the copyright owner as "Not a Contribution." + + "Contributor" shall mean Licensor and any individual or Legal Entity + on behalf of whom a Contribution has been received by Licensor and + subsequently incorporated within the Work. + + 2. Grant of Copyright License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + copyright license to reproduce, prepare Derivative Works of, + publicly display, publicly perform, sublicense, and distribute the + Work and such Derivative Works in Source or Object form. + + 3. Grant of Patent License. Subject to the terms and conditions of + this License, each Contributor hereby grants to You a perpetual, + worldwide, non-exclusive, no-charge, royalty-free, irrevocable + (except as stated in this section) patent license to make, have made, + use, offer to sell, sell, import, and otherwise transfer the Work, + where such license applies only to those patent claims licensable + by such Contributor that are necessarily infringed by their + Contribution(s) alone or by combination of their Contribution(s) + with the Work to which such Contribution(s) was submitted. If You + institute patent litigation against any entity (including a + cross-claim or counterclaim in a lawsuit) alleging that the Work + or a Contribution incorporated within the Work constitutes direct + or contributory patent infringement, then any patent licenses + granted to You under this License for that Work shall terminate + as of the date such litigation is filed. + + 4. Redistribution. You may reproduce and distribute copies of the + Work or Derivative Works thereof in any medium, with or without + modifications, and in Source or Object form, provided that You + meet the following conditions: + + (a) You must give any other recipients of the Work or + Derivative Works a copy of this License; and + + (b) You must cause any modified files to carry prominent notices + stating that You changed the files; and + + (c) You must retain, in the Source form of any Derivative Works + that You distribute, all copyright, patent, trademark, and + attribution notices from the Source form of the Work, + excluding those notices that do not pertain to any part of + the Derivative Works; and + + (d) If the Work includes a "NOTICE" text file as part of its + distribution, then any Derivative Works that You distribute must + include a readable copy of the attribution notices contained + within such NOTICE file, excluding those notices that do not + pertain to any part of the Derivative Works, in at least one + of the following places: within a NOTICE text file distributed + as part of the Derivative Works; within the Source form or + documentation, if provided along with the Derivative Works; or, + within a display generated by the Derivative Works, if and + wherever such third-party notices normally appear. The contents + of the NOTICE file are for informational purposes only and + do not modify the License. You may add Your own attribution + notices within Derivative Works that You distribute, alongside + or as an addendum to the NOTICE text from the Work, provided + that such additional attribution notices cannot be construed + as modifying the License. + + You may add Your own copyright statement to Your modifications and + may provide additional or different license terms and conditions + for use, reproduction, or distribution of Your modifications, or + for any such Derivative Works as a whole, provided Your use, + reproduction, and distribution of the Work otherwise complies with + the conditions stated in this License. + + 5. Submission of Contributions. Unless You explicitly state otherwise, + any Contribution intentionally submitted for inclusion in the Work + by You to the Licensor shall be under the terms and conditions of + this License, without any additional terms or conditions. + Notwithstanding the above, nothing herein shall supersede or modify + the terms of any separate license agreement you may have executed + with Licensor regarding such Contributions. + + 6. Trademarks. This License does not grant permission to use the trade + names, trademarks, service marks, or product names of the Licensor, + except as required for reasonable and customary use in describing the + origin of the Work and reproducing the content of the NOTICE file. + + 7. Disclaimer of Warranty. Unless required by applicable law or + agreed to in writing, Licensor provides the Work (and each + Contributor provides its Contributions) on an "AS IS" BASIS, + WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or + implied, including, without limitation, any warranties or conditions + of TITLE, NON-INFRINGEMENT, MERCHANTABILITY, or FITNESS FOR A + PARTICULAR PURPOSE. You are solely responsible for determining the + appropriateness of using or redistributing the Work and assume any + risks associated with Your exercise of permissions under this License. + + 8. Limitation of Liability. In no event and under no legal theory, + whether in tort (including negligence), contract, or otherwise, + unless required by applicable law (such as deliberate and grossly + negligent acts) or agreed to in writing, shall any Contributor be + liable to You for damages, including any direct, indirect, special, + incidental, or consequential damages of any character arising as a + result of this License or out of the use or inability to use the + Work (including but not limited to damages for loss of goodwill, + work stoppage, computer failure or malfunction, or any and all + other commercial damages or losses), even if such Contributor + has been advised of the possibility of such damages. + + 9. Accepting Warranty or Additional Liability. While redistributing + the Work or Derivative Works thereof, You may choose to offer, + and charge a fee for, acceptance of support, warranty, indemnity, + or other liability obligations and/or rights consistent with this + License. However, in accepting such obligations, You may act only + on Your own behalf and on Your sole responsibility, not on behalf + of any other Contributor, and only if You agree to indemnify, + defend, and hold each Contributor harmless for any liability + incurred by, or claims asserted against, such Contributor by reason + of your accepting any such warranty or additional liability. + + END OF TERMS AND CONDITIONS + + APPENDIX: How to apply the Apache License to your work. + + To apply the Apache License to your work, attach the following + boilerplate notice, with the fields enclosed by brackets "[]" + replaced with your own identifying information. (Don't include + the brackets!) The text should be enclosed in the appropriate + comment syntax for the file format. We also recommend that a + file or class name and description of purpose be included on the + same "printed page" as the copyright notice for easier + identification within third-party archives. + + Copyright [yyyy] [name of copyright owner] + + Licensed under the Apache License, Version 2.0 (the "License"); + you may not use this file except in compliance with the License. + You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, software + distributed under the License 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. diff --git a/README.md b/README.md new file mode 100644 index 0000000..fbceaae --- /dev/null +++ b/README.md @@ -0,0 +1,34 @@ +# terraform-aws-vcs-oidc + +[![Lint Status](https://github.com/DNXLabs/terraform-aws-vcs-oidc/workflows/Lint/badge.svg)](https://github.com/DNXLabs/terraform-aws-vcs-oidc/actions) +[![LICENSE](https://img.shields.io/github/license/DNXLabs/terraform-aws-vcs-oidc)](https://github.com/DNXLabs/terraform-aws-vcs-oidc/blob/main/LICENSE) + +This module sets up IAM Roles and Identity Provider for various VCS(Version Control Systems) providers. + +Supported providers: + - Bitbucket + - GitHub + +The following resources will be created: + - IAM Role. + - IAM Policy attachment. + - IAM Identity Provider Web Identity. + +## Usage + +- [Bitbucket](examples/bitbucket.md) +- [GitHub](examples/github.md) + + + + + + + +## Authors + +Module managed by [DNX Solutions](https://github.com/DNXLabs). + +## License + +Apache 2 Licensed. See [LICENSE](https://github.com/DNXLabs/terraform-aws-vcs-oidc/blob/main/LICENSE) for full details. diff --git a/_data.tf b/_data.tf new file mode 100644 index 0000000..fbdebc0 --- /dev/null +++ b/_data.tf @@ -0,0 +1,5 @@ +data "aws_caller_identity" "current" {} + +data "tls_certificate" "thumprint" { + url = var.identity_provider_url +} \ No newline at end of file diff --git a/_outputs.tf b/_outputs.tf new file mode 100644 index 0000000..dd6a139 --- /dev/null +++ b/_outputs.tf @@ -0,0 +1,7 @@ +output "roles" { + value = { for role_name, role_values in element(aws_iam_role.default.*, 0) : role_name => role_values.arn } +} + +output "identity_provider_arn" { + value = aws_iam_openid_connect_provider.default.arn +} \ No newline at end of file diff --git a/_variables.tf b/_variables.tf new file mode 100644 index 0000000..64b30a2 --- /dev/null +++ b/_variables.tf @@ -0,0 +1,21 @@ +variable "identity_provider_url" { + type = string + description = "Specify the secure OpenID Connect URL for authentication requests." +} + +variable "audiences" { + type = list(string) + description = "Also known as client ID, audience is a value that identifies the application that is registered with an OpenID Connect provider." +} + +variable "roles" { + type = list(any) + default = [] + description = "List of roles to create." +} + +variable "oidc_thumbprint" { + type = string + default = "" + description = "Thumbprint of OIDC host. See https://docs.aws.amazon.com/IAM/latest/UserGuide/id_roles_providers_create_oidc_verify-thumbprint.html" +} \ No newline at end of file diff --git a/examples/bitbucket.md b/examples/bitbucket.md new file mode 100644 index 0000000..d142c3c --- /dev/null +++ b/examples/bitbucket.md @@ -0,0 +1,83 @@ +# Bitbucket + +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/) + +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`. + +https://support.atlassian.com/bitbucket-cloud/docs/deploy-on-aws-using-bitbucket-pipelines-openid-connect + +To find information about indentity provider URL and Audience go to `https://bitbucket.org///admin/addon/admin/pipelines/openid-connect` + +#### Terraform setup + +```bash +module "bitbucket_oidc" { + source = "git::https://github.com/DNXLabs/terraform-aws-vcs-oidc.git" + + identity_provider_url = "https://api.bitbucket.org/2.0/workspaces/{WORKSPACE}/pipelines-config/identity/oidc" + audiences = [ + "ari:cloud:bitbucket::workspace/{WORKSPACE-UUID}" + ] + + roles = [ + { + name = "CIDeployBitbucket" + assume_roles = [ + "arn:aws:iam::*:role/InfraDeployAccess" # Optional + ] + assume_policies = [ + "arn:aws:iam::aws:policy/AdministratorAccess" # Optional + ] + conditions = [ + { + test = "ForAnyValue:StringLike" + variable = "api.bitbucket.org/2.0/workspaces/{WORKSPACE}/pipelines-config/identity/oidc:sub" + # {REPOSITORY_UUID}*:{ENVIRONMENT_UUID}:* or {REPOSITORY_UUID}:* + # Max of ~30 conditions. + values = "*:*" + }, + { # Limit only assumes requests coming from Bitbucket Pipelines IP to assume the role. + test = "IpAddress" + variable = "aws:SourceIp" + values = [ + "34.199.54.113/32", + "34.232.25.90/32", + "34.232.119.183/32", + "34.236.25.177/32", + "35.171.175.212/32", + "52.54.90.98/32", + "52.202.195.162/32", + "52.203.14.55/32", + "52.204.96.37/32", + "34.218.156.209/32", + "34.218.168.212/32", + "52.41.219.63/32", + "35.155.178.254/32", + "35.160.177.10/32", + "34.216.18.129/32" + ] + } + ] + } + ] +} +``` + +#### Example of bitbucket-pipelines.yml file + +```yml +image: amazon/aws-cli + +pipelines: + default: + - step: + oidc: true + script: + - export AWS_REGION=us-west-2 + - export AWS_ROLE_ARN=arn:aws:iam:::role/ + - export AWS_WEB_IDENTITY_TOKEN_FILE=$(pwd)/web-identity-token + - echo $BITBUCKET_STEP_OIDC_TOKEN > $(pwd)/web-identity-token + - aws sts get-caller-identity +``` + +> 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. \ No newline at end of file diff --git a/examples/github.md b/examples/github.md new file mode 100644 index 0000000..0d836a8 --- /dev/null +++ b/examples/github.md @@ -0,0 +1,107 @@ +# GitHub + +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: + +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. + +#### Terraform setup + +```bash +module "github_oidc" { + source = "git::https://github.com/DNXLabs/terraform-aws-vcs-oidc.git" + + identity_provider_url = "https://vstoken.actions.githubusercontent.com" + audiences = [ + "https://github.com//" + ] + + roles = [ + { + name = "InfraDeployGithub" + assume_roles = [ + "arn:aws:iam::*:role/InfraDeployAccess" # Optional + ] + assume_policies = [ + "arn:aws:iam::aws:policy/AdministratorAccess" # Optional + ] + conditions = [ + { + test = "ForAnyValue:StringLike" + variable = "vstoken.actions.githubusercontent.com:sub" + values = "repo:/:*" # Max of ~30 conditions. + } + ] + } + ] +} +``` + +Next, the GitHub workflow definition. Put this in a repo: + +#### Example of workflow yml file + +Parameters to change: +- `Account id` inside `AWS_ROLE_ARN` variable. +- `Role name` inside `AWS_ROLE_ARN` variable. + +```yml +name: OIDC +on: + push: + branches: + - master +jobs: + deploy: + name: OIDC + runs-on: ubuntu-latest + permissions: + id-token: write + contents: read + steps: + - run: sleep 5 + - name: Checkout + uses: actions/checkout@v2 + - name: Configure AWS + run: | + export AWS_ROLE_ARN=arn:aws:iam:::role/ + export AWS_WEB_IDENTITY_TOKEN_FILE=/tmp/awscreds + export AWS_DEFAULT_REGION=us-west-2 + + echo AWS_WEB_IDENTITY_TOKEN_FILE=$AWS_WEB_IDENTITY_TOKEN_FILE >> $GITHUB_ENV + echo AWS_ROLE_ARN=$AWS_ROLE_ARN >> $GITHUB_ENV + echo AWS_DEFAULT_REGION=$AWS_DEFAULT_REGION >> $GITHUB_ENV + + curl -H "Authorization: bearer $ACTIONS_ID_TOKEN_REQUEST_TOKEN" "$ACTIONS_ID_TOKEN_REQUEST_URL" | jq -r '.value' > $AWS_WEB_IDENTITY_TOKEN_FILE + - name: get-caller-identity + run: | + aws sts get-caller-identity +``` + +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. + +### Some potential trust policies + +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: + +``` +conditions = [ + { + test = "ForAnyValue:StringLike" + variable = "vstoken.actions.githubusercontent.com:sub" + values = "repo:/*" +] +``` + +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: + +``` +conditions = [ + { + test = "ForAnyValue:StringLike" + variable = "vstoken.actions.githubusercontent.com:sub" + values = "repo:/*:ref:refs/heads/main" + } +] +``` + +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. \ No newline at end of file diff --git a/iam-role.tf b/iam-role.tf new file mode 100644 index 0000000..029e690 --- /dev/null +++ b/iam-role.tf @@ -0,0 +1,73 @@ +resource "aws_iam_role" "default" { + for_each = { for role in var.roles : role.name => role } + name = each.value.name + assume_role_policy = data.aws_iam_policy_document.assume_role_saml[each.key].json +} + +resource "aws_iam_role_policy_attachment" "default" { + for_each = { for role in local.assume_policies_flatten : role.index => role } + role = each.value.role_name + policy_arn = data.aws_iam_policy.default[each.key].arn + + depends_on = [aws_iam_role.default] +} + +data "aws_iam_policy" "default" { + for_each = { for role in local.assume_policies_flatten : role.index => role } + arn = each.value.assume_policy +} + +data "aws_iam_policy_document" "assume_role_saml" { + for_each = { for role in var.roles : role.name => role } + + statement { + principals { + type = "Federated" + identifiers = [ + "arn:aws:iam::${data.aws_caller_identity.current.account_id}:oidc-provider/${replace(var.identity_provider_url, "https://", "")}" + ] + } + actions = ["sts:AssumeRoleWithWebIdentity"] + + dynamic "condition" { + for_each = each.value.conditions + content { + test = condition.value.test + variable = condition.value.variable + values = condition.value.values + } + } + } +} + +resource "aws_iam_role_policy" "assume_role" { + for_each = { for role in local.assume_roles_flatten : role.index => role } + name_prefix = "${each.value.name}-${element(split("/", each.value.assume_role), 1)}" + role = each.value.name + + policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = [ + "sts:AssumeRole", + ] + Effect = "Allow" + Resource = each.value.assume_role + }, + ] + }) + + depends_on = [aws_iam_role.default] +} + +resource "aws_iam_openid_connect_provider" "default" { + url = var.identity_provider_url + + client_id_list = var.audiences + + thumbprint_list = compact([ + var.oidc_thumbprint != "" ? var.oidc_thumbprint : "", + data.tls_certificate.thumprint.certificates.0.sha1_fingerprint + ]) +} \ No newline at end of file diff --git a/locals.tf b/locals.tf new file mode 100644 index 0000000..0bc74ce --- /dev/null +++ b/locals.tf @@ -0,0 +1,21 @@ +locals { + assume_roles_flatten = flatten([ + for role_key, role in var.roles : [ + for assume_role in role.assume_roles : { + index = format("%s-%s", role.name, element(split("/", assume_role), 1)) + name = role.name + assume_role = assume_role + conditions = role.conditions + } + ] + ]) + assume_policies_flatten = flatten([ + for role_key, role in var.roles : [ + for assume_policy in role.assume_policies : { + index = format("%s-%s", role.name, element(split("/", assume_policy), 1)) + role_name = role.name + assume_policy = assume_policy + } + ] + ]) +} \ No newline at end of file diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..d8e6461 --- /dev/null +++ b/versions.tf @@ -0,0 +1,3 @@ +terraform { + required_version = ">= 0.13.0" +} \ No newline at end of file