From 5636b2aacd7e2315d4dc09c58cd44556a91abd30 Mon Sep 17 00:00:00 2001 From: Chris Privitere <23177737+cprivitere@users.noreply.github.com> Date: Mon, 15 May 2023 16:55:30 -0500 Subject: [PATCH] Initial commit --- .github/workflows/documentation.yaml | 53 +++++++ .github/workflows/pre-commit.yaml | 72 ++++++++++ .github/workflows/release.yaml | 28 ++++ .gitignore | 52 +++++++ .mdl_style.rb | 7 + .mdlrc | 1 + .pre-commit-config.yaml | 87 ++++++++++++ .releaserc.json | 44 ++++++ .tflint.hcl | 5 + CHANGELOG.md | 0 CODEOWNERS | 3 + CODE_OF_CONDUCT.md | 76 ++++++++++ CONTRIBUTING.md | 30 ++++ LICENSE | 201 +++++++++++++++++++++++++++ README.md | 120 ++++++++++++++++ docs/template-doc.md | 1 + examples/simple/README.md | 47 +++++++ examples/simple/main.tf | 12 ++ examples/simple/outputs.tf | 24 ++++ examples/simple/variables.tf | 21 +++ files/static-file.txt | 1 + helpers/helper-script.sh | 1 + main.tf | 50 +++++++ modules/inline-module/README.md | 49 +++++++ modules/inline-module/main.tf | 37 +++++ modules/inline-module/outputs.tf | 17 +++ modules/inline-module/variables.tf | 14 ++ outputs.tf | 24 ++++ renovate.json | 6 + scripts/template-script.sh | 1 + templates/template-file.tftpl | 1 + variables.tf | 21 +++ 32 files changed, 1106 insertions(+) create mode 100644 .github/workflows/documentation.yaml create mode 100644 .github/workflows/pre-commit.yaml create mode 100644 .github/workflows/release.yaml create mode 100644 .gitignore create mode 100644 .mdl_style.rb create mode 100644 .mdlrc create mode 100644 .pre-commit-config.yaml create mode 100644 .releaserc.json create mode 100644 .tflint.hcl create mode 100644 CHANGELOG.md create mode 100644 CODEOWNERS create mode 100644 CODE_OF_CONDUCT.md create mode 100644 CONTRIBUTING.md create mode 100644 LICENSE create mode 100644 README.md create mode 100644 docs/template-doc.md create mode 100644 examples/simple/README.md create mode 100644 examples/simple/main.tf create mode 100644 examples/simple/outputs.tf create mode 100644 examples/simple/variables.tf create mode 100644 files/static-file.txt create mode 100644 helpers/helper-script.sh create mode 100644 main.tf create mode 100644 modules/inline-module/README.md create mode 100644 modules/inline-module/main.tf create mode 100644 modules/inline-module/outputs.tf create mode 100644 modules/inline-module/variables.tf create mode 100644 outputs.tf create mode 100644 renovate.json create mode 100644 scripts/template-script.sh create mode 100644 templates/template-file.tftpl create mode 100644 variables.tf diff --git a/.github/workflows/documentation.yaml b/.github/workflows/documentation.yaml new file mode 100644 index 0000000..80e082c --- /dev/null +++ b/.github/workflows/documentation.yaml @@ -0,0 +1,53 @@ +name: generate-terraform-docs +# This workflow will generate terraform docs into README.md in the root, examples, and modules folders. +# Source: https://github.com/equinix-labs/terraform-equinix-kubernetes-addons/blob/main/.github/workflows/documentation.yaml + +on: + push: + branches: + - main + paths: + - '**/*.tpl' + - '**/*.tf' + +jobs: + tf-docs: + name: TF docs + runs-on: ubuntu-latest + steps: + - uses: actions/checkout@v3 + id: actions-checkout + with: + ref: main + + - name: Render terraform docs inside the main and the modules README.md files and push changes back to PR branch + id: terraform-docs + uses: terraform-docs/gh-actions@v1.0.0 + with: + find-dir: . + args: --sort-by required + indention: 2 + git-push: "false" + + # terraform-docs/gh-actions@v1.0.0 modifies .git files with owner root:root, and the following steps fail with + # insufficient permission for adding an object to repository database .git/objects + # since the expected user is runner:docker. See https://github.com/terraform-docs/gh-actions/issues/90 + - name: Fix .git owner + run: sudo chown runner:docker -R .git + + - name: Create Pull Request + if: steps.terraform-docs.outputs.num_changed != '0' + uses: peter-evans/create-pull-request@v4 + with: + commit-message: 'generate-terraform-docs: automated action' + committer: GitHub + author: ${{ github.actor }} <${{ github.actor }}@users.noreply.github.com> + title: 'generate-terraform-docs: automated action' + body: | + Update terraform docs + branch-suffix: timestamp + base: main + signoff: true + delete-branch: true + + # TODO(ocobleseqx): https://github.com/peter-evans/enable-pull-request-automerge diff --git a/.github/workflows/pre-commit.yaml b/.github/workflows/pre-commit.yaml new file mode 100644 index 0000000..6bb6bf8 --- /dev/null +++ b/.github/workflows/pre-commit.yaml @@ -0,0 +1,72 @@ +name: 'run-pre-commit-hooks' +# This workflow runs the pre-commit hooks defined in .pre-commit-config.yaml + +on: + pull_request: + branches: [main] + +concurrency: + group: ${{ github.workflow }}-${{ github.ref }} + cancel-in-progress: true + +jobs: + pre-commit: + runs-on: ${{ matrix.os }} + env: + TF_VERSION: ${{ matrix.tf }} + TFLINT_VERSION: ${{ matrix.tflint }} + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} + strategy: + matrix: + os: [ubuntu-latest] + tf: [1.3.0] + tflint: [v0.44.1] + permissions: + pull-requests: write + id-token: write + contents: read + steps: + - name: Checkout from Github + uses: actions/checkout@v3 + + - name: Install Python3 + uses: actions/setup-python@v4 + + - name: Install tflint + uses: terraform-linters/setup-tflint@v3 + with: + tflint_version: ${{ env.TFLINT_VERSION }} + + - name: Cache tflint plugin dir + uses: actions/cache@v3 + with: + path: ~/.tflint.d/plugins + key: ${{ matrix.os }}-tflint-${{ hashFiles('.tflint.hcl') }} + + - name: Install Terraform + uses: hashicorp/setup-terraform@v2 + with: + terraform_version: ${{ env.TF_VERSION }} + + - name: Config Terraform plugin cache + run: | + echo 'plugin_cache_dir="$HOME/.terraform.d/plugin-cache"' >~/.terraformrc + mkdir --parents ~/.terraform.d/plugin-cache + + - name: Cache Terraform + uses: actions/cache@v3 + with: + path: | + ~/.terraform.d/plugin-cache + key: ${{ runner.os }}-terraform-${{ hashFiles('**/.terraform.lock.hcl') }} + restore-keys: | + ${{ runner.os }}-terraform- + + - name: Install tfsec + uses: jaxxstorm/action-install-gh-release@v1.5.0 + with: + repo: aquasecurity/tfsec + platform: linux + arch: x86-64 + + - uses: pre-commit/action@v3.0.0 diff --git a/.github/workflows/release.yaml b/.github/workflows/release.yaml new file mode 100644 index 0000000..e3ea883 --- /dev/null +++ b/.github/workflows/release.yaml @@ -0,0 +1,28 @@ +name: generate-release +# This workflow will generate changelog and release notes. +# Source: https://github.com/terraform-aws-modules/terraform-aws-vpc/blob/master/.github/workflows/release.yml + +on: + workflow_dispatch: + +jobs: + release: + name: Release + runs-on: ubuntu-latest + steps: + - name: Checkout + uses: actions/checkout@v3 + with: + persist-credentials: false + fetch-depth: 0 + + - name: Release + uses: cycjimmy/semantic-release-action@v3 + with: + semantic_version: 19.0.5 + extra_plugins: | + @semantic-release/changelog@6.0.0 + @semantic-release/git@10.0.0 + conventional-changelog-conventionalcommits@4.6.3 + env: + GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..432bd68 --- /dev/null +++ b/.gitignore @@ -0,0 +1,52 @@ +# OSX leaves these everywhere on SMB shares +._* + +# OSX trash +**/.DS_Store +*.pyc* + +# Emacs save files +*~ +\#*\# +.\#* + +# Vim-related files +[._]*.s[a-w][a-z] +[._]s[a-w][a-z] +*.un~ +Session.vim +.netrwhist + +# Local .terraform directories +**/.terraform/* +**/*/.terraform/* +.terraform* + +# .tfstate files +*.tfstate +*.tfstate.* + +.terraform.lock.hcl + +# Crash log files +crash.log + +# Ignore any .tfvars files that are generated automatically for each Terraform run. Most +# .tfvars files are managed as part of configuration and so should be included in +# version control. +# +# example.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 + +# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan +# example: *tfplan* +**/terraform.tfvars +util/keys + +*-kubeconfig diff --git a/.mdl_style.rb b/.mdl_style.rb new file mode 100644 index 0000000..3896394 --- /dev/null +++ b/.mdl_style.rb @@ -0,0 +1,7 @@ +all + +exclude_rule 'MD013' +rule 'MD029', style: ['ordered'] +exclude_rule 'MD033' +exclude_rule 'MD041' +exclude_rule 'MD047' diff --git a/.mdlrc b/.mdlrc new file mode 100644 index 0000000..1f82ca2 --- /dev/null +++ b/.mdlrc @@ -0,0 +1 @@ +style '.mdl_style.rb' diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml new file mode 100644 index 0000000..d37af30 --- /dev/null +++ b/.pre-commit-config.yaml @@ -0,0 +1,87 @@ +--- +fail_fast: false +repos: + +- repo: https://github.com/antonbabenko/pre-commit-terraform + rev: v1.77.1 + hooks: + - id: terraform_fmt + args: + - "--args=-recursive" + - id: terraform_validate + exclude: "^[^/]+$" + - id: terraform_tflint + args: + - "--args=--config=__GIT_WORKING_DIR__/.tflint.hcl" + - id: terraform_tfsec + args: + - "--args=--soft-fail" + +- repo: https://github.com/pre-commit/pre-commit-hooks + rev: v4.4.0 + hooks: + # Git style + - id: check-added-large-files + - id: check-merge-conflict + - id: check-vcs-permalinks + - id: forbid-new-submodules + - id: no-commit-to-branch + args: ['--branch', 'master'] + + # Common errors + - id: end-of-file-fixer + - id: trailing-whitespace + args: + - "--markdown-linebreak-ext=md" + exclude: CHANGELOG.md + - id: check-yaml + args: + - "--allow-multiple-documents" + exclude: | + (?x)^( + examples/| + \.*?.yaml$" + )$ + - id: check-json + - id: check-symlinks + - id: check-executables-have-shebangs + + # Cross platform + - id: check-case-conflict + - id: mixed-line-ending + args: + - "--fix=lf" + + # Security + - id: detect-private-key + +# Shell Script Formatter and Markdown Linter +- repo: https://github.com/jumanjihouse/pre-commit-hooks + rev: 3.0.0 + hooks: + - id: shfmt + exclude: | + (?x)^( + helpers/helper-script.sh| + scripts/template-script.sh + )$ + - id: shellcheck + args: + - "--severity=warning" + - "--source-path=SCRIPTDIR scripts/* helpers/*" + - "--shell=bash" + exclude: | + (?x)^( + helpers/helper-script.sh| + scripts/template-script.sh + )$ + - id: markdownlint + exclude: "CHANGELOG.md" + +# JSON5 and Yaml Prettyfier +- repo: https://github.com/pre-commit/mirrors-prettier + rev: v3.0.0-alpha.4 + hooks: + - id: prettier + types: [json5, yaml] + exclude: "^examples/" diff --git a/.releaserc.json b/.releaserc.json new file mode 100644 index 0000000..4e8212e --- /dev/null +++ b/.releaserc.json @@ -0,0 +1,44 @@ +{ + "branches": [ + "main" + ], + "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/.tflint.hcl b/.tflint.hcl new file mode 100644 index 0000000..7b2d40e --- /dev/null +++ b/.tflint.hcl @@ -0,0 +1,5 @@ +plugin "terraform" { + enabled = true + version = "0.2.2" + source = "github.com/terraform-linters/tflint-ruleset-terraform" +} diff --git a/CHANGELOG.md b/CHANGELOG.md new file mode 100644 index 0000000..e69de29 diff --git a/CODEOWNERS b/CODEOWNERS new file mode 100644 index 0000000..024e229 --- /dev/null +++ b/CODEOWNERS @@ -0,0 +1,3 @@ +# TEMPLATE: add your username after terraform +# TEMPLATE: * equinix-labs/terraform myusername +* @equinix-labs/terraform diff --git a/CODE_OF_CONDUCT.md b/CODE_OF_CONDUCT.md new file mode 100644 index 0000000..28b7243 --- /dev/null +++ b/CODE_OF_CONDUCT.md @@ -0,0 +1,76 @@ +# Contributor Covenant Code of Conduct + +## Our Pledge + +In the interest of fostering an open and welcoming environment, we as +contributors and maintainers pledge to making participation in our project and +our community a harassment-free experience for everyone, regardless of age, body +size, disability, ethnicity, sex characteristics, gender identity and expression, +level of experience, education, socio-economic status, 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 devrel [at] packet [dot] com. 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. + +## Attribution + +This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4, +available at + +[homepage]: https://www.contributor-covenant.org + +For answers to common questions about this code of conduct, see + diff --git a/CONTRIBUTING.md b/CONTRIBUTING.md new file mode 100644 index 0000000..e4e0f87 --- /dev/null +++ b/CONTRIBUTING.md @@ -0,0 +1,30 @@ +# Contributing + +This document provides guidelines for contributing to the module. + +Contributors to this project must abide by the [Contributor Covenant Code of Conduct](CODE_OF_CONDUCT.md). + +## File structure + +The project has the following folders and files: + +- /: root folder. +- /docs: Examples for using this module. +- /examples: Examples for using this module. +- /files: Static files referenced but not executed by Terraform. +- /helpers: Helper scripts NOT called by Terraform. +- /modules: Inline local modules called by this module. +- /scripts: Scripts for specific tasks on module. +- /templates: Template files used to be execute by data sources. +- /main.tf: Main file for this module, contains all the resources to operate the module. +- /variables.tf: All the variables necessary for run the module. +- /output.tf: The outputs generate from the module. +- /README.md: Main repo README document. +- /CHANGELOG.md: Module release changelog file. +- /CODEOWNERS: Module contributing developers. +- /CODE_OF_CONDUCT.md: Code of Conduct file. +- /CONTRIBUTING.md: This file. + +## Issues and Change Requests + +Please submit change requests and / or features via [Issues](https://github.com/equinix-labs/equinix-labs/issues). 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..e700a23 --- /dev/null +++ b/README.md @@ -0,0 +1,120 @@ +# terraform-equinix-template + + + +[![Experimental](https://img.shields.io/badge/Stability-Experimental-red.svg)](https://github.com/equinix-labs/standards#about-uniform-standards) +[![run-pre-commit-hooks](https://github.com/equinix-labs/terraform-equinix-template/actions/workflows/pre-commit.yaml/badge.svg)](https://github.com/equinix-labs/terraform-equinix-template/actions/workflows/pre-commit.yaml) +[![generate-terraform-docs](https://github.com/equinix-labs/terraform-equinix-template/actions/workflows/documentation.yaml/badge.svg)](https://github.com/equinix-labs/terraform-equinix-template/actions/workflows/documentation.yaml) + +`terraform-equinix-template` is a minimal Terraform module that utilizes [Terraform providers for Equinix](https://registry.terraform.io/namespaces/equinix) to provision digital infrastructure and demonstrate higher level integrations. + + + +## Usage + +This project is experimental and supported by the user community. Equinix does not provide support for this project. + +Install Terraform using the [tfenv](https://github.com/tfutils/tfenv) utility. + +This project may be forked, cloned, or downloaded and modified as needed as the base in your integrations and deployments. + +This project may also be used as a [Terraform module](https://learn.hashicorp.com/collections/terraform/modules). + +To use this module in a new project, create a file such as: + +```hcl +# main.tf +terraform { + required_providers { + equinix = { + source = "equinix/equinix" + } +} + +module "example" { + source = "github.com/equinix-labs/template" + # TEMPLATE: replace "template" with the name of the repo after the terraform-equinix- prefix. + + # Published modules can be sourced as: + # source = "equinix-labs/template/equinix" + # See https://www.terraform.io/docs/registry/modules/publish.html for details. + + # version = "0.1.0" + + # TEMPLATE: insert required variables here +} +``` + +Install [pre-commit](https://pre-commit.com/#install) with its prerequesites: [python](https://docs.python.org/3/using/index.html) and [pip](https://pip.pypa.io/en/stable/installation/). + +Configure pre-commit: `pre-commit install`. + +Install required packages: [tflint](https://github.com/terraform-linters/tflint), [tfsec](https://aquasecurity.github.io/tfsec/v1.0.11/getting-started/installation/), [shfmt](https://github.com/mvdan/sh), [shellcheck](https://github.com/koalaman/shellcheck), and [markdownlint](https://github.com/markdownlint/markdownlint). + +Run `terraform init -upgrade` and `terraform apply`. + +## Module Documentation + +The main README.md, the modules README.md and the examples README.md are populated by [terraform-docs worflow job](.github/workflows/documentation.yaml). The following sections are appended between the terraform-docs delimeters: Requiremenents, Providers, Modules, Resources, Inputs, and Outputs. + +## Module Release and Changelog Generation + +The module git release and [changelog](CHANGELOG.md) are generated by the [release workflow job](.github/workflows/release.yaml). The release worflow follows the [conventional commits convention](https://www.conventionalcommits.org/). To submit a commit, please follow the [commit message format guidelines](https://www.conventionalcommits.org/en/v1.0.0/#specification). This job is set to run manually by default. + +Example commit message: `fix: disabled log generation for system services` + +For more examples, please see [conventional commit message examples](https://www.conventionalcommits.org/en/v1.0.0/#examples). + +## Examples + +To view examples for how you can leverage this module, please see the [examples](examples/) directory. + + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3 | +| [equinix](#requirement\_equinix) | >= 1.8.0 | + +## Providers + +| Name | Version | +|------|---------| +| [equinix](#provider\_equinix) | >= 1.8.1 | + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [inline-module](#module\_inline-module) | ./modules/inline-module | n/a | + +## Resources + +| Name | Type | +|------|------| +| [equinix_metal_device.example](https://registry.terraform.io/providers/equinix/equinix/latest/docs/resources/metal_device) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [example\_auth\_token](#input\_example\_auth\_token) | The example auth token value defines what will be included in the example resource in main.tf. This example is descriptive. | `string` | n/a | yes | +| [example\_project\_id](#input\_example\_project\_id) | The example project id value defines what will be included in the example resource in main.tf. This example is descriptive. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [example\_device\_hostname](#output\_example\_device\_hostname) | The example output. In practice, output value reference implicit resource attributes declared in main.tf | +| [example\_gateway\_id](#output\_example\_gateway\_id) | The example output. In practice, output value reference implicit resource attributes declared in main.tf | + +## Contributing + +If you would like to contribute to this module, see [CONTRIBUTING](CONTRIBUTING.md) page. + +## License + +Apache License, Version 2.0. See [LICENSE](LICENSE). + diff --git a/docs/template-doc.md b/docs/template-doc.md new file mode 100644 index 0000000..4378ae5 --- /dev/null +++ b/docs/template-doc.md @@ -0,0 +1 @@ +# template-doc diff --git a/examples/simple/README.md b/examples/simple/README.md new file mode 100644 index 0000000..6a41ec3 --- /dev/null +++ b/examples/simple/README.md @@ -0,0 +1,47 @@ +# Simple Example + +This example demonstrates usage of the Equinix Template module. + +## Usage + +```bash +terraform init +terraform apply +``` + + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3 | + +## Providers + +No providers. + +## Modules + +| Name | Source | Version | +|------|--------|---------| +| [example](#module\_example) | ../../ | n/a | + +## Resources + +No resources. + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [example\_metal\_auth\_token](#input\_example\_metal\_auth\_token) | The example auth token value defines what will be included in the example resource in main.tf. This example is descriptive. | `string` | n/a | yes | +| [example\_metal\_project\_id](#input\_example\_metal\_project\_id) | The example project id value defines what will be included in the example resource in main.tf. This example is descriptive. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [example\_device\_hostname](#output\_example\_device\_hostname) | The example output. In practice, output value reference implicit resource attributes declared in main.tf | +| [example\_gateway\_id](#output\_example\_gateway\_id) | The example output. In practice, output value reference implicit resource attributes declared in main.tf | + diff --git a/examples/simple/main.tf b/examples/simple/main.tf new file mode 100644 index 0000000..43c115c --- /dev/null +++ b/examples/simple/main.tf @@ -0,0 +1,12 @@ +terraform { + required_version = ">= 1.3" +} + +module "example" { + # TEMPLATE: Replace this path with the Git repo path or Terraform Registry path + source = "../../" + + # Define any required variables + metal_project_id = var.example_metal_project_id + metal_auth_token = var.example_metal_auth_token +} diff --git a/examples/simple/outputs.tf b/examples/simple/outputs.tf new file mode 100644 index 0000000..50d8eb0 --- /dev/null +++ b/examples/simple/outputs.tf @@ -0,0 +1,24 @@ +# TEMPLATE: Consider the attributes users of this module will need to take advantage of this module +# TEMPLATE: in a new module that depends on this module (addresses, credentials, filenames). +# TEMPLATE: All outputs must have a description. Do not include descriptions or help text in the +# TEMPLATE: value, use the description field. +# TEMPLATE: +# TEMPLATE: Declare all outputs in this file, sprawling declarations are difficult to identify. +# TEMPLATE: +# TEMPLATE: https://www.terraform.io/docs/language/values/outputs.html +# TEMPLATE: https://www.terraform.io/docs/language/expressions/types.html +# TEMPLATE: + +# TEMPLATE: Replace sample output described below with your own. +output "example_device_hostname" { + description = "The example output. In practice, output value reference implicit resource attributes declared in main.tf" + sensitive = false + value = module.example.device_hostname +} + +# TEMPLATE: Replace sample output described below with your own. +output "example_gateway_id" { + description = "The example output. In practice, output value reference implicit resource attributes declared in main.tf" + sensitive = false + value = module.example.gateway_id +} diff --git a/examples/simple/variables.tf b/examples/simple/variables.tf new file mode 100644 index 0000000..878ff3d --- /dev/null +++ b/examples/simple/variables.tf @@ -0,0 +1,21 @@ +# TEMPLATE: All variables must have a description and should declare their type. +# TEMPLATE: Set defaults whenever possible but do not set defaults for required properties. +# TEMPLATE: Declare all variables in this file, sprawling declarations are difficult to identify. +# TEMPLATE: +# TEMPLATE: https://www.terraform.io/docs/language/values/variables.html +# TEMPLATE: https://www.terraform.io/docs/language/expressions/types.html +# TEMPLATE: + +# TEMPLATE: Replace sample variable described below with your own. +variable "example_metal_project_id" { + type = string + description = "The example project id value defines what will be included in the example resource in main.tf. This example is descriptive." + sensitive = false +} + +# TEMPLATE: Replace sample variable described below with your own. +variable "example_metal_auth_token" { + type = string + description = "The example auth token value defines what will be included in the example resource in main.tf. This example is descriptive." + sensitive = true +} diff --git a/files/static-file.txt b/files/static-file.txt new file mode 100644 index 0000000..69ac7b4 --- /dev/null +++ b/files/static-file.txt @@ -0,0 +1 @@ +# TEMPLATE: Place your static files referenced but not executed by Terraform under this folder diff --git a/helpers/helper-script.sh b/helpers/helper-script.sh new file mode 100644 index 0000000..8bb98bb --- /dev/null +++ b/helpers/helper-script.sh @@ -0,0 +1 @@ +# TEMPLATE: Place your bespoke script NOT called by Terraform here. diff --git a/main.tf b/main.tf new file mode 100644 index 0000000..5eb376a --- /dev/null +++ b/main.tf @@ -0,0 +1,50 @@ +# TEMPLATE: Before using "provider" blocks, consider https://www.terraform.io/docs/language/modules/develop/providers.html#implicit-provider-inheritance +# TEMPLATE: +# TEMPLATE: All ".tf" files are parsed at once. There is no benefit to numerically prefixed filenames. Keep all resource definitions in "main.tf". +# TEMPLATE: +# TEMPLATE: When main.tf becomes unwieldy, consider submodules (https://www.terraform.io/docs/language/modules/develop/structure.html) +# TEMPLATE: and dependency inversion (https://www.terraform.io/docs/language/modules/develop/composition.html). +# TEMPLATE: + +# TEMPLATE: Replace sample provider described below with your own. +terraform { + required_version = ">= 1.3" + + provider_meta "equinix" { + # TEMPLATE: Replace the module name with your own. + module_name = "template" + } + + required_providers { + equinix = { + source = "equinix/equinix" + version = ">= 1.8.0" + } + } +} + +# TEMPLATE: Replace sample provider described below with your own. +provider "equinix" { + auth_token = var.metal_auth_token +} + +# TEMPLATE: Replace sample resource described below with your own. +resource "equinix_metal_device" "example_device" { + hostname = "example-device" + plan = "c3.small.x86" + metro = "sv" + operating_system = "ubuntu_20_04" + billing_cycle = "hourly" + project_id = var.metal_project_id +} + +# TEMPLATE: Run `terraform get` to install local module +# TEMPLATE: Run `terraform init` to initialize backends and install plugins +# TEMPLATE: Replace sample in-line local module described below with your own. +# TEMPLATE +module "inline_module" { + source = "./modules/inline-module" + + # Define any required variables + inline_module_project_id = var.metal_project_id +} diff --git a/modules/inline-module/README.md b/modules/inline-module/README.md new file mode 100644 index 0000000..52db438 --- /dev/null +++ b/modules/inline-module/README.md @@ -0,0 +1,49 @@ +# In-line Module + +This example demonstrates usage of an in-line module. + +## Usage + +```bash +terraform init +terraform apply +``` + + + +## Requirements + +| Name | Version | +|------|---------| +| [terraform](#requirement\_terraform) | >= 1.3 | +| [equinix](#requirement\_equinix) | >= 1.8.0 | + +## Providers + +| Name | Version | +|------|---------| +| [equinix](#provider\_equinix) | >= 1.8.0 | + +## Modules + +No modules. + +## Resources + +| Name | Type | +|------|------| +| [equinix_metal_gateway.inline_module_gateway](https://registry.terraform.io/providers/equinix/equinix/latest/docs/resources/metal_gateway) | resource | +| [equinix_metal_vlan.inline_module_vlan](https://registry.terraform.io/providers/equinix/equinix/latest/docs/resources/metal_vlan) | resource | + +## Inputs + +| Name | Description | Type | Default | Required | +|------|-------------|------|---------|:--------:| +| [inline\_module\_project\_id](#input\_inline\_module\_project\_id) | The example project id value defines what will be included in the example resource in main.tf. This example is descriptive. | `string` | n/a | yes | + +## Outputs + +| Name | Description | +|------|-------------| +| [metal\_gateway\_id](#output\_metal\_gateway\_id) | The example output. In practice, output value reference implicit resource attributes declared in main.tf | + diff --git a/modules/inline-module/main.tf b/modules/inline-module/main.tf new file mode 100644 index 0000000..65dcb41 --- /dev/null +++ b/modules/inline-module/main.tf @@ -0,0 +1,37 @@ +# TEMPLATE: Before using "provider" blocks, consider https://www.terraform.io/docs/language/modules/develop/providers.html#implicit-provider-inheritance +# TEMPLATE: +# TEMPLATE: All ".tf" files are parsed at once. There is no benefit to numerically prefixed filenames. Keep all resource definitions in "main.tf". +# TEMPLATE: +# TEMPLATE: When main.tf becomes unwieldy, consider submodules (https://www.terraform.io/docs/language/modules/develop/structure.html) +# TEMPLATE: and dependency inversion (https://www.terraform.io/docs/language/modules/develop/composition.html). + +# TEMPLATE: Replace sample provider described below with your own. +terraform { + required_version = ">= 1.3" + + provider_meta "equinix" { + # TEMPLATE: Replace the module name with your own. + module_name = "inline-module" + } + + required_providers { + equinix = { + source = "equinix/equinix" + version = ">= 1.8.0" + } + } +} + +# TEMPLATE: Replace sample resource described below with your own. +resource "equinix_metal_vlan" "inline_module_vlan" { + description = "VLAN in SV" + metro = "sv" + project_id = var.inline_module_project_id +} + +# TEMPLATE: Replace sample resource described below with your own. +resource "equinix_metal_gateway" "inline_module_gateway" { + project_id = var.inline_module_project_id + vlan_id = equinix_metal_vlan.inline_module_vlan.id + private_ipv4_subnet_size = 8 +} diff --git a/modules/inline-module/outputs.tf b/modules/inline-module/outputs.tf new file mode 100644 index 0000000..58deb9d --- /dev/null +++ b/modules/inline-module/outputs.tf @@ -0,0 +1,17 @@ +# TEMPLATE: Consider the attributes users of this module will need to take advantage of this module +# TEMPLATE: in a new module that depends on this module (addresses, credentials, filenames). +# TEMPLATE: All outputs must have a description. Do not include descriptions or help text in the +# TEMPLATE: value, use the description field. +# TEMPLATE: +# TEMPLATE: Declare all outputs in this file, sprawling declarations are difficult to identify. +# TEMPLATE: +# TEMPLATE: https://www.terraform.io/docs/language/values/outputs.html +# TEMPLATE: https://www.terraform.io/docs/language/expressions/types.html +# + +# TEMPLATE: Replace sample output described below with your own. +output "metal_gateway_id" { + description = "The example output. In practice, output value reference implicit resource attributes declared in main.tf" + sensitive = false + value = equinix_metal_gateway.inline_module_gateway.id +} diff --git a/modules/inline-module/variables.tf b/modules/inline-module/variables.tf new file mode 100644 index 0000000..770ebc4 --- /dev/null +++ b/modules/inline-module/variables.tf @@ -0,0 +1,14 @@ +# TEMPLATE: All variables must have a description and should declare their type. +# TEMPLATE: Set defaults whenever possible but do not set defaults for required properties. +# TEMPLATE: Declare all variables in this file, sprawling declarations are difficult to identify. +# TEMPLATE: +# TEMPLATE: https://www.terraform.io/docs/language/values/variables.html +# TEMPLATE: https://www.terraform.io/docs/language/expressions/types.html +# + +# TEMPLATE: Replace sample variable described below with your own. +variable "inline_module_project_id" { + type = string + description = "The example project id value defines what will be included in the example resource in main.tf. This example is descriptive." + sensitive = false +} diff --git a/outputs.tf b/outputs.tf new file mode 100644 index 0000000..4bdfbc6 --- /dev/null +++ b/outputs.tf @@ -0,0 +1,24 @@ +# TEMPLATE: Consider the attributes users of this module will need to take advantage of this module +# TEMPLATE: in a new module that depends on this module (addresses, credentials, filenames). +# TEMPLATE: All outputs must have a description. Do not include descriptions or help text in the +# TEMPLATE: value, use the description field. +# TEMPLATE: +# TEMPLATE: Declare all outputs in this file, sprawling declarations are difficult to identify. +# TEMPLATE: +# TEMPLATE: https://www.terraform.io/docs/language/values/outputs.html +# TEMPLATE: https://www.terraform.io/docs/language/expressions/types.html +# TEMPLATE: + +# TEMPLATE: Replace sample output described below with your own. +output "device_hostname" { + description = "The example output. In practice, output value reference implicit resource attributes declared in main.tf" + sensitive = false + value = equinix_metal_device.example_device.hostname +} + +# TEMPLATE: Replace sample output described below with your own. +output "gateway_id" { + description = "The example output. In practice, output value reference implicit resource attributes declared in main.tf" + sensitive = false + value = module.inline_module.metal_gateway_id +} diff --git a/renovate.json b/renovate.json new file mode 100644 index 0000000..39a2b6e --- /dev/null +++ b/renovate.json @@ -0,0 +1,6 @@ +{ + "$schema": "https://docs.renovatebot.com/renovate-schema.json", + "extends": [ + "config:base" + ] +} diff --git a/scripts/template-script.sh b/scripts/template-script.sh new file mode 100644 index 0000000..ac9101c --- /dev/null +++ b/scripts/template-script.sh @@ -0,0 +1 @@ +# TEMPLATE: Place your beskope script called by Terraform here. diff --git a/templates/template-file.tftpl b/templates/template-file.tftpl new file mode 100644 index 0000000..b87e591 --- /dev/null +++ b/templates/template-file.tftpl @@ -0,0 +1 @@ +# TEMPLATE: Place your template here. This will be called by the templatefile function. For more info: https://developer.hashicorp.com/terraform/language/functions/templatefile diff --git a/variables.tf b/variables.tf new file mode 100644 index 0000000..5334a3c --- /dev/null +++ b/variables.tf @@ -0,0 +1,21 @@ +# TEMPLATE: All variables must have a description and should declare their type. +# TEMPLATE: Set defaults whenever possible but do not set defaults for required properties. +# TEMPLATE: Declare all variables in this file, sprawling declarations are difficult to identify. +# TEMPLATE: +# TEMPLATE: https://www.terraform.io/docs/language/values/variables.html +# TEMPLATE: https://www.terraform.io/docs/language/expressions/types.html +# TEMPLATE: + +# TEMPLATE: Replace sample variable described below with your own. +variable "metal_project_id" { + type = string + description = "The example project id value defines what will be included in the example resource in main.tf. This example is descriptive." + sensitive = false +} + +# TEMPLATE: Replace sample variable described below with your own. +variable "metal_auth_token" { + type = string + description = "The example auth token value defines what will be included in the example resource in main.tf. This example is descriptive." + sensitive = true +}