From c9d5b5494f0010635565ab7cf8a8d88d162477fa Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Adri=C3=A1n=20Mart=C3=ADn=20Garc=C3=ADa?= Date: Sun, 18 Feb 2024 09:40:02 +0100 Subject: [PATCH] feat: Initial repository --- .editorconfig | 30 ++++ .github/workflows/lock.yml | 21 +++ .github/workflows/pr-tittle.yml | 52 +++++++ .github/workflows/pre-commit.yml | 83 +++++++++++ .github/workflows/release.yml | 37 +++++ .github/workflows/stale-actions.yaml | 32 +++++ .gitignore | 29 ++++ .pre-commit-config.yaml | 30 ++++ .releaserc.json | 45 ++++++ LICENSE | 176 +++++++++++++++++++++++ README.md | 100 ++++++++++++- examples/nexus-routing-rule/README.md | 30 ++++ examples/nexus-routing-rule/main.tf | 14 ++ examples/nexus-routing-rule/outputs.tf | 7 + examples/nexus-routing-rule/variables.tf | 3 + examples/nexus-routing-rule/versions.tf | 12 ++ main.tf | 14 ++ modules/nexus-routing-rule/README.md | 37 +++++ modules/nexus-routing-rule/main.tf | 9 ++ modules/nexus-routing-rule/outputs.tf | 7 + modules/nexus-routing-rule/variables.tf | 24 ++++ modules/nexus-routing-rule/versions.tf | 12 ++ outputs.tf | 7 + variables.tf | 13 ++ versions.tf | 12 ++ 25 files changed, 835 insertions(+), 1 deletion(-) create mode 100644 .editorconfig create mode 100644 .github/workflows/lock.yml create mode 100644 .github/workflows/pr-tittle.yml create mode 100644 .github/workflows/pre-commit.yml create mode 100644 .github/workflows/release.yml create mode 100644 .github/workflows/stale-actions.yaml create mode 100644 .gitignore create mode 100644 .pre-commit-config.yaml create mode 100644 .releaserc.json create mode 100644 LICENSE create mode 100644 examples/nexus-routing-rule/README.md create mode 100644 examples/nexus-routing-rule/main.tf create mode 100644 examples/nexus-routing-rule/outputs.tf create mode 100644 examples/nexus-routing-rule/variables.tf create mode 100644 examples/nexus-routing-rule/versions.tf create mode 100644 main.tf create mode 100644 modules/nexus-routing-rule/README.md create mode 100644 modules/nexus-routing-rule/main.tf create mode 100644 modules/nexus-routing-rule/outputs.tf create mode 100644 modules/nexus-routing-rule/variables.tf create mode 100644 modules/nexus-routing-rule/versions.tf create mode 100644 outputs.tf create mode 100644 variables.tf create mode 100644 versions.tf diff --git a/.editorconfig b/.editorconfig new file mode 100644 index 0000000..88cb251 --- /dev/null +++ b/.editorconfig @@ -0,0 +1,30 @@ +# EditorConfig is awesome: http://EditorConfig.org +# Uses editorconfig to maintain consistent coding styles + +# top-most EditorConfig file +root = true + +# Unix-style newlines with a newline ending every file +[*] +charset = utf-8 +end_of_line = lf +indent_size = 2 +indent_style = space +insert_final_newline = true +max_line_length = 80 +trim_trailing_whitespace = true + +[*.{tf,tfvars}] +indent_size = 2 +indent_style = space + +[*.md] +max_line_length = 0 +trim_trailing_whitespace = false + +[Makefile] +tab_width = 2 +indent_style = tab + +[COMMIT_EDITMSG] +max_line_length = 0 diff --git a/.github/workflows/lock.yml b/.github/workflows/lock.yml new file mode 100644 index 0000000..12953b9 --- /dev/null +++ b/.github/workflows/lock.yml @@ -0,0 +1,21 @@ +name: 'Lock Threads' + +on: + schedule: + - cron: '50 1 * * *' + +jobs: + lock: + runs-on: ubuntu-latest + steps: + - uses: dessant/lock-threads@v4 + with: + github-token: ${{ secrets.GH_TOKEN }} + issue-comment: > + I'm going to lock this issue because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues. + If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. + issue-inactive-days: '30' + pr-comment: > + I'm going to lock this pull request because it has been closed for _30 days_ ⏳. This helps our maintainers find and focus on the active issues. + If you have found a problem that seems related to this change, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further. + pr-inactive-days: '30' diff --git a/.github/workflows/pr-tittle.yml b/.github/workflows/pr-tittle.yml new file mode 100644 index 0000000..4abbbce --- /dev/null +++ b/.github/workflows/pr-tittle.yml @@ -0,0 +1,52 @@ +name: 'Validate PR title' + +on: + pull_request_target: + types: + - opened + - edited + - synchronize + +jobs: + main: + name: Validate PR title + runs-on: ubuntu-latest + steps: + # Please look up the latest version from + # https://github.com/amannn/action-semantic-pull-request/releases + - uses: amannn/action-semantic-pull-request@v5.0.2 + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} + with: + # Configure which types are allowed. + # Default: https://github.com/commitizen/conventional-commit-types + types: | + fix + feat + docs + ci + chore + # Configure that a scope must always be provided. + requireScope: false + # Configure additional validation for the subject based on a regex. + # This example ensures the subject starts with an uppercase character. + subjectPattern: ^[A-Z].+$ + # If `subjectPattern` is configured, you can use this property to override + # the default error message that is shown when the pattern doesn't match. + # The variables `subject` and `title` can be used within the message. + subjectPatternError: | + The subject "{subject}" found in the pull request title "{title}" + didn't match the configured pattern. Please ensure that the subject + starts with an uppercase character. + # For work-in-progress PRs you can typically use draft pull requests + # from Github. However, private repositories on the free plan don't have + # this option and therefore this action allows you to opt-in to using the + # special "[WIP]" prefix to indicate this state. This will avoid the + # validation of the PR title and the pull request checks remain pending. + # Note that a second check will be reported if this is enabled. + wip: true + # When using "Squash and merge" on a PR with only one commit, GitHub + # will suggest using that commit message instead of the PR title for the + # merge commit, and it's easy to commit this by mistake. Enable this option + # to also validate the commit message for one commit PRs. + validateSingleCommit: false diff --git a/.github/workflows/pre-commit.yml b/.github/workflows/pre-commit.yml new file mode 100644 index 0000000..17d8244 --- /dev/null +++ b/.github/workflows/pre-commit.yml @@ -0,0 +1,83 @@ +name: Pre-Commit + +on: + pull_request: + branches: + - main + - master + +env: + TERRAFORM_DOCS_VERSION: v0.16.0 + TFLINT_VERSION: v0.44.1 + +jobs: + collectInputs: + name: Collect workflow inputs + runs-on: ubuntu-latest + outputs: + directories: ${{ steps.dirs.outputs.directories }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Get root directories + id: dirs + uses: clowdhaus/terraform-composite-actions/directories@v1.8.3 + + preCommitMinVersions: + name: Min TF pre-commit + needs: collectInputs + runs-on: ubuntu-latest + strategy: + matrix: + directory: ${{ fromJson(needs.collectInputs.outputs.directories) }} + steps: + - name: Checkout + uses: actions/checkout@v4 + + - name: Terraform min/max versions + id: minMax + uses: clowdhaus/terraform-min-max@v1.2.7 + with: + directory: ${{ matrix.directory }} + + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} + # Run only validate pre-commit check on min version supported + if: ${{ matrix.directory != '.' }} + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3 + with: + terraform-version: ${{ steps.minMax.outputs.minVersion }} + tflint-version: ${{ env.TFLINT_VERSION }} + args: 'terraform_validate --color=always --show-diff-on-failure --files ${{ matrix.directory }}/*' + + - name: Pre-commit Terraform ${{ steps.minMax.outputs.minVersion }} + # Run only validate pre-commit check on min version supported + if: ${{ matrix.directory == '.' }} + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3 + with: + terraform-version: ${{ steps.minMax.outputs.minVersion }} + tflint-version: ${{ env.TFLINT_VERSION }} + args: 'terraform_validate --color=always --show-diff-on-failure --files $(ls *.tf)' + + preCommitMaxVersion: + name: Max TF pre-commit + runs-on: ubuntu-latest + needs: collectInputs + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + ref: ${{ github.event.pull_request.head.ref }} + repository: ${{github.event.pull_request.head.repo.full_name}} + + - name: Terraform min/max versions + id: minMax + uses: clowdhaus/terraform-min-max@v1.2.7 + + - name: Pre-commit Terraform ${{ steps.minMax.outputs.maxVersion }} + uses: clowdhaus/terraform-composite-actions/pre-commit@v1.8.3 + with: + terraform-version: ${{ steps.minMax.outputs.maxVersion }} + tflint-version: ${{ env.TFLINT_VERSION }} + terraform-docs-version: ${{ env.TERRAFORM_DOCS_VERSION }} + install-hcledit: true diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml new file mode 100644 index 0000000..e93709b --- /dev/null +++ b/.github/workflows/release.yml @@ -0,0 +1,37 @@ +name: Release + +on: + workflow_dispatch: + push: + branches: + - main + - master + paths: + - '**/*.tpl' + - '**/*.py' + - '**/*.tf' + - '.github/workflows/release.yml' + +jobs: + release: + name: Release + runs-on: ubuntu-latest + # Skip running release workflow on forks + if: github.repository_owner == 'terraform-nexus-modules' + steps: + - name: Checkout + uses: actions/checkout@v4 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Release + uses: cycjimmy/semantic-release-action@v3 + with: + semantic_version: 18.0.0 + extra_plugins: | + @semantic-release/changelog@6.0.0 + @semantic-release/git@10.0.0 + conventional-changelog-conventionalcommits@4.6.3 + env: + GITHUB_TOKEN: ${{ secrets.GH_TOKEN }} diff --git a/.github/workflows/stale-actions.yaml b/.github/workflows/stale-actions.yaml new file mode 100644 index 0000000..5d1e246 --- /dev/null +++ b/.github/workflows/stale-actions.yaml @@ -0,0 +1,32 @@ +name: 'Mark or close stale issues and PRs' +on: + schedule: + - cron: '0 0 * * *' + +jobs: + stale: + runs-on: ubuntu-latest + steps: + - uses: actions/stale@v6 + with: + repo-token: ${{ secrets.GH_TOKEN }} + # Staling issues and PR's + days-before-stale: 30 + stale-issue-label: stale + stale-pr-label: stale + stale-issue-message: | + This issue has been automatically marked as stale because it has been open 30 days + with no activity. Remove stale label or comment or this issue will be closed in 10 days + stale-pr-message: | + This PR has been automatically marked as stale because it has been open 30 days + with no activity. Remove stale label or comment or this PR will be closed in 10 days + # Not stale if have this labels or part of milestone + exempt-issue-labels: bug,wip,on-hold + exempt-pr-labels: bug,wip,on-hold + exempt-all-milestones: true + # Close issue operations + # Label will be automatically removed if the issues are no longer closed nor locked. + days-before-close: 10 + delete-branch: true + close-issue-message: This issue was automatically closed because of stale in 10 days + close-pr-message: This PR was automatically closed because of stale in 10 days diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..397af32 --- /dev/null +++ b/.gitignore @@ -0,0 +1,29 @@ +# Local .terraform directories +**/.terraform/* + +# Terraform lockfile +.terraform.lock.hcl + +# .tfstate files +*.tfstate +*.tfstate.* + +# Crash log files +crash.log + +# Exclude all .tfvars files, which are likely to contain sentitive data, such as +# password, private keys, and other secrets. These should not be part of version +# control as they are data points which are potentially sensitive and subject +# to change depending on the environment. +*.tfvars + +# Ignore override files as they are usually used to override resources locally and so +# are not checked in +override.tf +override.tf.json +*_override.tf +*_override.tf.json + +# Ignore CLI configuration files +.terraformrc +terraform.rc diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..06eef70 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,30 @@ +repos: + - repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.85.0 + hooks: + - id: terraform_fmt + - id: terraform_wrapper_module_for_each + - id: terraform_validate + - id: terraform_docs + args: + - '--args=--lockfile=false' + - id: terraform_tflint + args: + - '--args=--only=terraform_deprecated_interpolation' + - '--args=--only=terraform_deprecated_index' + - '--args=--only=terraform_unused_declarations' + - '--args=--only=terraform_comment_syntax' + - '--args=--only=terraform_documented_outputs' + - '--args=--only=terraform_documented_variables' + - '--args=--only=terraform_typed_variables' + - '--args=--only=terraform_module_pinned_source' + - '--args=--only=terraform_naming_convention' + - '--args=--only=terraform_required_version' + - '--args=--only=terraform_required_providers' + - '--args=--only=terraform_standard_module_structure' + - '--args=--only=terraform_workspace_remote' + - repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.5.0 + hooks: + - id: check-merge-conflict + - id: end-of-file-fixer diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..280dc43 --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,45 @@ +{ + "branches": [ + "main", + "master" + ], + "ci": false, + "plugins": [ + [ + "@semantic-release/commit-analyzer", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/release-notes-generator", + { + "preset": "conventionalcommits" + } + ], + [ + "@semantic-release/github", + { + "successComment": "This ${issue.pull_request ? 'PR is included' : 'issue has been resolved'} in version ${nextRelease.version} :tada:", + "labels": false, + "releasedLabels": false + } + ], + [ + "@semantic-release/changelog", + { + "changelogFile": "CHANGELOG.md", + "changelogTitle": "# Changelog\n\nAll notable changes to this project will be documented in this file." + } + ], + [ + "@semantic-release/git", + { + "assets": [ + "CHANGELOG.md" + ], + "message": "chore(release): version ${nextRelease.version} [skip ci]\n\n${nextRelease.notes}" + } + ] + ] +} diff --git a/LICENSE b/LICENSE new file mode 100644 index 0000000..d9a10c0 --- /dev/null +++ b/LICENSE @@ -0,0 +1,176 @@ + 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 diff --git a/README.md b/README.md index a9c407d..f6d2a39 100644 --- a/README.md +++ b/README.md @@ -1 +1,99 @@ -# terraform-nexus-routing \ No newline at end of file +# Nexus Routing + +This module allows you to create **Nexus Routing as a global resource** and **individual Nexus Routing resources.** For individual examples, see the usage snippets and [examples](https://github.com/terraform-nexus-modules/terraform-nexus-routing/tree/main/examples). + +## Provider +You need use a [Nexus provider](https://registry.terraform.io/providers/datadrivers/nexus/latest/docs). +```hcl +provider "nexus" { + insecure = true + password = "admin123" + url = "https://127.0.0.1:8080" + username = "admin" +} +``` + +## Root module usage + +`nexus-routing`: + +```hcl +module "nexus_routing" { + source = "terraform-nexus-modules/routing/nexus" + version = "1.0.0" + + nexus_routing_rule = [ + { + name = "stop-leaks" + description = "Prevent requests of internal names" + mode = "BLOCK" + matchers = [ + "^/com/example/.*", + "^/org/example/.*", + ] + }, + ] +} +``` + +## Individual module usage + +`nexus-routing-rule`: + +```hcl +module "nexus_routing_rule" { + source = "terraform-nexus-modules/routing/nexus//modules/nexus-routing-rule" + version = "1.0.0" + + name = "stop-leaks" + description = "Prevent requests of internal names" + mode = "BLOCK" + matchers = [ + "^/com/example/.*", + "^/org/example/.*", + ] +} +``` + +## Terraform Docs + +### Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3.0 | +| [nexus](#requirement\_nexus) | >= 2.0.0 | + +### Providers + +No providers. + +### Modules + +| Name | Source | Version | +|------|--------|---------| +| [nexus\_routing\_rule](#module\_nexus\_routing\_rule) | ./modules/nexus-routing-rule | n/a | + +### Resources + +No resources. + +### Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [nexus\_routing\_rule](#input\_nexus\_routing\_rule) | Routing Rule. |
list(object({
name = string
matchers = set(string)
description = optional(string)
mode = optional(string)
}))
| `[]` | no | + +### Outputs + +| Name | Description | +|------|-------------| +| [routing\_rule\_name](#output\_routing\_rule\_name) | The name of the routing rule. | + +## Authors + +Module is maintained by [DevOps IA](https://github.com/devops-ia) with help from [these awesome contributors](https://github.com/terraform-nexus-modules/terraform-nexus-routing/graphs/contributors). + +## License + +Apache 2 Licensed. See [LICENSE](https://github.com/terraform-nexus-modules/terraform-nexus-routing/blob/main/LICENSE) for full details. diff --git a/examples/nexus-routing-rule/README.md b/examples/nexus-routing-rule/README.md new file mode 100644 index 0000000..634cec3 --- /dev/null +++ b/examples/nexus-routing-rule/README.md @@ -0,0 +1,30 @@ +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3.0 | +| [nexus](#requirement\_nexus) | >= 2.0.0 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [nexus\_routing\_rule](#module\_nexus\_routing\_rule) | ../../modules/nexus-routing-rule | n/a | + +## Resources + +No resources. + +## Inputs + +No inputs. + +## Outputs + +| Name | Description | +|------|-------------| +| [name](#output\_name) | The name of the resource. | diff --git a/examples/nexus-routing-rule/main.tf b/examples/nexus-routing-rule/main.tf new file mode 100644 index 0000000..ad5e756 --- /dev/null +++ b/examples/nexus-routing-rule/main.tf @@ -0,0 +1,14 @@ +################################################################################ +# Routing Rule +################################################################################ +module "nexus_routing_rule" { + source = "../../modules/nexus-routing-rule" + + name = "stop-leaks" + description = "Prevent requests of internal names" + mode = "BLOCK" + matchers = [ + "^/com/example/.*", + "^/org/example/.*", + ] +} diff --git a/examples/nexus-routing-rule/outputs.tf b/examples/nexus-routing-rule/outputs.tf new file mode 100644 index 0000000..8bb2a3b --- /dev/null +++ b/examples/nexus-routing-rule/outputs.tf @@ -0,0 +1,7 @@ +################################################################################ +# Routing Rule +################################################################################ +output "name" { + description = "The name of the resource." + value = module.nexus_routing_rule.name +} diff --git a/examples/nexus-routing-rule/variables.tf b/examples/nexus-routing-rule/variables.tf new file mode 100644 index 0000000..38ca643 --- /dev/null +++ b/examples/nexus-routing-rule/variables.tf @@ -0,0 +1,3 @@ +################################################################################ +# Routing Rule +################################################################################ diff --git a/examples/nexus-routing-rule/versions.tf b/examples/nexus-routing-rule/versions.tf new file mode 100644 index 0000000..aa6f060 --- /dev/null +++ b/examples/nexus-routing-rule/versions.tf @@ -0,0 +1,12 @@ +################################################################################ +# Routing Rule +################################################################################ +terraform { + required_version = ">= 1.3.0" + required_providers { + nexus = { + source = "datadrivers/nexus" + version = ">= 2.0.0" + } + } +} diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..043744b --- /dev/null +++ b/main.tf @@ -0,0 +1,14 @@ +################################################################################ +# Routing Rule +################################################################################ +module "nexus_routing_rule" { + source = "./modules/nexus-routing-rule" + + for_each = { for r in var.nexus_routing_rule : r.name => r } + + name = each.value.name + matchers = each.value.matchers + + description = each.value.description + mode = each.value.mode +} diff --git a/modules/nexus-routing-rule/README.md b/modules/nexus-routing-rule/README.md new file mode 100644 index 0000000..34523db --- /dev/null +++ b/modules/nexus-routing-rule/README.md @@ -0,0 +1,37 @@ +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3.0 | +| [nexus](#requirement\_nexus) | >= 2.0.0 | + +## Providers + +| Name | Version | +|------|---------| +| [nexus](#provider\_nexus) | >= 2.0.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [nexus_routing_rule.main](https://registry.terraform.io/providers/datadrivers/nexus/latest/docs/resources/routing_rule) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [description](#input\_description) | The description of the routing rule | `string` | `""` | no | +| [matchers](#input\_matchers) | Matchers is a list of regular expressions used to identify request paths that are allowed or blocked (depending on above mode) | `set(string)` | n/a | yes | +| [mode](#input\_mode) | The mode describe how to hande with mathing requests | `string` | `"BLOCK"` | no | +| [name](#input\_name) | The name of the routing rule | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [name](#output\_name) | The name of the resource. | diff --git a/modules/nexus-routing-rule/main.tf b/modules/nexus-routing-rule/main.tf new file mode 100644 index 0000000..fab0164 --- /dev/null +++ b/modules/nexus-routing-rule/main.tf @@ -0,0 +1,9 @@ +################################################################################ +# Routing Rule +################################################################################ +resource "nexus_routing_rule" "main" { + name = var.name + description = var.description + mode = var.mode + matchers = var.matchers +} diff --git a/modules/nexus-routing-rule/outputs.tf b/modules/nexus-routing-rule/outputs.tf new file mode 100644 index 0000000..0d67592 --- /dev/null +++ b/modules/nexus-routing-rule/outputs.tf @@ -0,0 +1,7 @@ +################################################################################ +# Routing Rule +################################################################################ +output "name" { + description = "The name of the resource." + value = nexus_routing_rule.main.name +} diff --git a/modules/nexus-routing-rule/variables.tf b/modules/nexus-routing-rule/variables.tf new file mode 100644 index 0000000..fc3944e --- /dev/null +++ b/modules/nexus-routing-rule/variables.tf @@ -0,0 +1,24 @@ +################################################################################ +# Routing Rule +################################################################################ +variable "name" { + description = "The name of the routing rule" + type = string +} + +variable "matchers" { + description = "Matchers is a list of regular expressions used to identify request paths that are allowed or blocked (depending on above mode)" + type = set(string) +} + +variable "description" { + description = "The description of the routing rule" + type = string + default = "" +} + +variable "mode" { + description = "The mode describe how to hande with mathing requests" + type = string + default = "BLOCK" +} diff --git a/modules/nexus-routing-rule/versions.tf b/modules/nexus-routing-rule/versions.tf new file mode 100644 index 0000000..aa6f060 --- /dev/null +++ b/modules/nexus-routing-rule/versions.tf @@ -0,0 +1,12 @@ +################################################################################ +# Routing Rule +################################################################################ +terraform { + required_version = ">= 1.3.0" + required_providers { + nexus = { + source = "datadrivers/nexus" + version = ">= 2.0.0" + } + } +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..7446175 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,7 @@ +################################################################################ +# Routing Rule +################################################################################ +output "routing_rule_name" { + description = "The name of the routing rule." + value = [for r in module.nexus_routing_rule : r.name] +} diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..7adc3e3 --- /dev/null +++ b/variables.tf @@ -0,0 +1,13 @@ +################################################################################ +# Routing Rule +################################################################################ +variable "nexus_routing_rule" { + description = "Routing Rule." + type = list(object({ + name = string + matchers = set(string) + description = optional(string) + mode = optional(string) + })) + default = [] +} diff --git a/versions.tf b/versions.tf new file mode 100644 index 0000000..58742ea --- /dev/null +++ b/versions.tf @@ -0,0 +1,12 @@ +################################################################################ +# Nexus Routing +################################################################################ +terraform { + required_version = ">= 1.3.0" + required_providers { + nexus = { + source = "datadrivers/nexus" + version = ">= 2.0.0" + } + } +}