mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-13 07:02:35 +00:00
Initial commit
This commit is contained in:
commit
cd5e05ffbf
23 changed files with 26743 additions and 0 deletions
37
.github/workflows/continuous-integration.yml
vendored
Normal file
37
.github/workflows/continuous-integration.yml
vendored
Normal file
|
|
@ -0,0 +1,37 @@
|
||||||
|
name: 'Continuous Integration'
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
test:
|
||||||
|
name: Test
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Node.js 12.x
|
||||||
|
uses: actions/setup-node@v1
|
||||||
|
with:
|
||||||
|
node-version: '12.x'
|
||||||
|
|
||||||
|
- name: Install
|
||||||
|
run: npm clean-install
|
||||||
|
|
||||||
|
- name: Verify
|
||||||
|
if: runner.os == 'Linux'
|
||||||
|
run: |
|
||||||
|
npm run build
|
||||||
|
# Fail if "npm run build" generated new changes in dist
|
||||||
|
git update-index --refresh dist/* && git diff-index --quiet HEAD dist
|
||||||
|
|
||||||
|
- name: Test
|
||||||
|
run: npm test
|
||||||
5
.github/workflows/data/local/main.tf
vendored
Normal file
5
.github/workflows/data/local/main.tf
vendored
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
resource "null_resource" "null" {
|
||||||
|
triggers = {
|
||||||
|
value = "${timestamp()}"
|
||||||
|
}
|
||||||
|
}
|
||||||
261
.github/workflows/setup-terraform.yml
vendored
Normal file
261
.github/workflows/setup-terraform.yml
vendored
Normal file
|
|
@ -0,0 +1,261 @@
|
||||||
|
name: 'Setup Terraform'
|
||||||
|
|
||||||
|
on:
|
||||||
|
push:
|
||||||
|
branches:
|
||||||
|
- master
|
||||||
|
pull_request:
|
||||||
|
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
shell: bash
|
||||||
|
|
||||||
|
jobs:
|
||||||
|
terraform-versions:
|
||||||
|
name: 'Terraform Versions'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
terraform-versions: [0.11.14, 0.12.24]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform - ${{ matrix['terraform-versions'] }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
terraform_version: ${{ matrix['terraform-versions'] }}
|
||||||
|
|
||||||
|
- name: Validate Teraform Version - ${{ matrix['terraform-versions'] }}
|
||||||
|
run: terraform version | grep ${{ matrix['terraform-versions']}}
|
||||||
|
|
||||||
|
terraform-versions-no-wrapper:
|
||||||
|
name: 'Terraform Versions No Wrapper'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
terraform-versions: [0.11.14, 0.12.24]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform (no wrapper) - ${{ matrix['terraform-versions'] }}
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
terraform_version: ${{ matrix['terraform-versions'] }}
|
||||||
|
terraform_wrapper: false
|
||||||
|
|
||||||
|
- name: Validate Teraform Version (no wrapper) - ${{ matrix['terraform-versions'] }}
|
||||||
|
run: terraform version | grep ${{ matrix['terraform-versions']}}
|
||||||
|
|
||||||
|
terraform-credentials-cloud:
|
||||||
|
name: 'Terraform Cloud Credentials'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
env:
|
||||||
|
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
||||||
|
|
||||||
|
- name: Validate Terraform Credentials (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
run: |
|
||||||
|
cat ${APPDATA}/terraform.rc | grep 'credentials "app.terraform.io"'
|
||||||
|
cat ${APPDATA}/terraform.rc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||||
|
|
||||||
|
- name: Validate Teraform Credentials (Linux & macOS)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
run: |
|
||||||
|
cat ${HOME}/.terraformrc | grep 'credentials "app.terraform.io"'
|
||||||
|
cat ${HOME}/.terraformrc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||||
|
|
||||||
|
terraform-credentials-enterprise:
|
||||||
|
name: 'Terraform Enterprise Credentials'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
env:
|
||||||
|
TF_CLOUD_API_TOKEN: 'XXXXXXXXXXXXXX.atlasv1.XXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXXX'
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
cli_config_credentials_hostname: 'terraform.example.com'
|
||||||
|
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
||||||
|
|
||||||
|
- name: Validate Terraform Credentials (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
run: |
|
||||||
|
cat ${APPDATA}/terraform.rc | grep 'credentials "terraform.example.com"'
|
||||||
|
cat ${APPDATA}/terraform.rc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||||
|
|
||||||
|
- name: Validate Teraform Credentials (Linux & macOS)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
run: |
|
||||||
|
cat ${HOME}/.terraformrc | grep 'credentials "terraform.example.com"'
|
||||||
|
cat ${HOME}/.terraformrc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
||||||
|
|
||||||
|
terraform-credentials-none:
|
||||||
|
name: 'Terraform No Credentials'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform
|
||||||
|
uses: ./
|
||||||
|
|
||||||
|
- name: Validate Terraform Credentials (Windows)
|
||||||
|
if: runner.os == 'Windows'
|
||||||
|
run: |
|
||||||
|
[[ -f ${APPDATA}/terraform.rc ]] || exit 0
|
||||||
|
|
||||||
|
- name: Validate Teraform Credentials (Linux & macOS)
|
||||||
|
if: runner.os != 'Windows'
|
||||||
|
run: |
|
||||||
|
[[ -f ${HOME}/.terraformrc ]] || exit 0
|
||||||
|
|
||||||
|
terraform-arguments:
|
||||||
|
name: 'Terraform Arguments'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform
|
||||||
|
uses: ./
|
||||||
|
|
||||||
|
- name: Check No Arguments
|
||||||
|
run: terraform || exit 0
|
||||||
|
|
||||||
|
- name: Check Single Argument
|
||||||
|
run: terraform help || exit 0
|
||||||
|
|
||||||
|
- name: Check Single Argument Hyphen
|
||||||
|
run: terraform -help
|
||||||
|
|
||||||
|
- name: Check Single Argument Double Hyphen
|
||||||
|
run: terraform --help
|
||||||
|
|
||||||
|
- name: Check Single Argument Subcommand
|
||||||
|
run: terraform fmt -check
|
||||||
|
|
||||||
|
- name: Check Multiple Arguments Subcommand
|
||||||
|
run: terraform fmt -check -list=true -no-color
|
||||||
|
|
||||||
|
terraform-arguments-no-wrapper:
|
||||||
|
name: 'Terraform Arguments No Wrapper'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
terraform_wrapper: false
|
||||||
|
|
||||||
|
- name: Check No Arguments
|
||||||
|
run: terraform || exit 0
|
||||||
|
|
||||||
|
- name: Check Single Argument
|
||||||
|
run: terraform help || exit 0
|
||||||
|
|
||||||
|
- name: Check Single Argument Hyphen
|
||||||
|
run: terraform -help
|
||||||
|
|
||||||
|
- name: Check Single Argument Double Hyphen
|
||||||
|
run: terraform --help
|
||||||
|
|
||||||
|
- name: Check Single Argument Subcommand
|
||||||
|
run: terraform fmt -check
|
||||||
|
|
||||||
|
- name: Check Multiple Arguments Subcommand
|
||||||
|
run: terraform fmt -check -list=true -no-color
|
||||||
|
|
||||||
|
terraform-run-local:
|
||||||
|
name: 'Terraform Run Local'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./.github/workflows/data/local
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform
|
||||||
|
uses: ./
|
||||||
|
|
||||||
|
- name: Terraform Init
|
||||||
|
shell: bash
|
||||||
|
run: terraform init
|
||||||
|
|
||||||
|
- name: Terraform Format
|
||||||
|
shell: bash
|
||||||
|
run: terraform fmt -check
|
||||||
|
|
||||||
|
- name: Terraform Plan
|
||||||
|
id: plan
|
||||||
|
shell: bash
|
||||||
|
run: terraform plan
|
||||||
|
|
||||||
|
- name: Print Terraform Plan
|
||||||
|
shell: bash
|
||||||
|
run: echo "${{ steps.plan.outputs.stdout }}"
|
||||||
|
|
||||||
|
terraform-run-local-no-wrapper:
|
||||||
|
name: 'Terraform Run Local No Wrapper'
|
||||||
|
runs-on: ${{ matrix.os }}
|
||||||
|
strategy:
|
||||||
|
matrix:
|
||||||
|
os: [ubuntu-latest, windows-latest, macos-latest]
|
||||||
|
defaults:
|
||||||
|
run:
|
||||||
|
working-directory: ./.github/workflows/data/local
|
||||||
|
steps:
|
||||||
|
- name: Checkout
|
||||||
|
uses: actions/checkout@v2
|
||||||
|
|
||||||
|
- name: Setup Terraform
|
||||||
|
uses: ./
|
||||||
|
with:
|
||||||
|
terraform_wrapper: false
|
||||||
|
|
||||||
|
- name: Terraform Init
|
||||||
|
shell: bash
|
||||||
|
run: terraform init
|
||||||
|
|
||||||
|
- name: Terraform Format
|
||||||
|
shell: bash
|
||||||
|
run: terraform fmt -check
|
||||||
|
|
||||||
|
- name: Terraform Plan
|
||||||
|
id: plan
|
||||||
|
shell: bash
|
||||||
|
run: terraform plan
|
||||||
68
.gitignore
vendored
Normal file
68
.gitignore
vendored
Normal file
|
|
@ -0,0 +1,68 @@
|
||||||
|
node_modules/
|
||||||
|
|
||||||
|
# Editors
|
||||||
|
.vscode
|
||||||
|
|
||||||
|
# Logs
|
||||||
|
logs
|
||||||
|
*.log
|
||||||
|
npm-debug.log*
|
||||||
|
yarn-debug.log*
|
||||||
|
yarn-error.log*
|
||||||
|
|
||||||
|
# Runtime data
|
||||||
|
pids
|
||||||
|
*.pid
|
||||||
|
*.seed
|
||||||
|
*.pid.lock
|
||||||
|
|
||||||
|
# Directory for instrumented libs generated by jscoverage/JSCover
|
||||||
|
lib-cov
|
||||||
|
|
||||||
|
# Coverage directory used by tools like istanbul
|
||||||
|
coverage
|
||||||
|
|
||||||
|
# nyc test coverage
|
||||||
|
.nyc_output
|
||||||
|
|
||||||
|
# Grunt intermediate storage (http://gruntjs.com/creating-plugins#storing-task-files)
|
||||||
|
.grunt
|
||||||
|
|
||||||
|
# Bower dependency directory (https://bower.io/)
|
||||||
|
bower_components
|
||||||
|
|
||||||
|
# node-waf configuration
|
||||||
|
.lock-wscript
|
||||||
|
|
||||||
|
# Compiled binary addons (https://nodejs.org/api/addons.html)
|
||||||
|
build/Release
|
||||||
|
|
||||||
|
# Other Dependency directories
|
||||||
|
jspm_packages/
|
||||||
|
|
||||||
|
# TypeScript v1 declaration files
|
||||||
|
typings/
|
||||||
|
|
||||||
|
# Optional npm cache directory
|
||||||
|
.npm
|
||||||
|
|
||||||
|
# Optional eslint cache
|
||||||
|
.eslintcache
|
||||||
|
|
||||||
|
# Optional REPL history
|
||||||
|
.node_repl_history
|
||||||
|
|
||||||
|
# Output of 'npm pack'
|
||||||
|
*.tgz
|
||||||
|
|
||||||
|
# Yarn Integrity file
|
||||||
|
.yarn-integrity
|
||||||
|
|
||||||
|
# dotenv environment variables file
|
||||||
|
.env
|
||||||
|
|
||||||
|
# next.js build output
|
||||||
|
.next
|
||||||
|
|
||||||
|
# ./wrapper/dist gets included in top-level ./dist
|
||||||
|
wrapper/dist
|
||||||
5
CODE_OF_CONDUCT.md
Normal file
5
CODE_OF_CONDUCT.md
Normal file
|
|
@ -0,0 +1,5 @@
|
||||||
|
# Code of Conduct
|
||||||
|
|
||||||
|
HashiCorp Community Guidelines apply to you when interacting with the community here on GitHub and contributing code.
|
||||||
|
|
||||||
|
Please read the full text at https://www.hashicorp.com/community-guidelines.
|
||||||
374
LICENSE
Normal file
374
LICENSE
Normal file
|
|
@ -0,0 +1,374 @@
|
||||||
|
Mozilla Public License Version 2.0
|
||||||
|
==================================
|
||||||
|
|
||||||
|
1. Definitions
|
||||||
|
--------------
|
||||||
|
|
||||||
|
1.1. "Contributor"
|
||||||
|
means each individual or legal entity that creates, contributes to
|
||||||
|
the creation of, or owns Covered Software.
|
||||||
|
|
||||||
|
1.2. "Contributor Version"
|
||||||
|
means the combination of the Contributions of others (if any) used
|
||||||
|
by a Contributor and that particular Contributor's Contribution.
|
||||||
|
|
||||||
|
1.3. "Contribution"
|
||||||
|
means Covered Software of a particular Contributor.
|
||||||
|
|
||||||
|
1.4. "Covered Software"
|
||||||
|
means Source Code Form to which the initial Contributor has attached
|
||||||
|
the notice in Exhibit A, the Executable Form of such Source Code
|
||||||
|
Form, and Modifications of such Source Code Form, in each case
|
||||||
|
including portions thereof.
|
||||||
|
|
||||||
|
1.5. "Incompatible With Secondary Licenses"
|
||||||
|
means
|
||||||
|
|
||||||
|
(a) that the initial Contributor has attached the notice described
|
||||||
|
in Exhibit B to the Covered Software; or
|
||||||
|
|
||||||
|
(b) that the Covered Software was made available under the terms of
|
||||||
|
version 1.1 or earlier of the License, but not also under the
|
||||||
|
terms of a Secondary License.
|
||||||
|
|
||||||
|
1.6. "Executable Form"
|
||||||
|
means any form of the work other than Source Code Form.
|
||||||
|
|
||||||
|
1.7. "Larger Work"
|
||||||
|
means a work that combines Covered Software with other material, in
|
||||||
|
a separate file or files, that is not Covered Software.
|
||||||
|
|
||||||
|
1.8. "License"
|
||||||
|
means this document.
|
||||||
|
|
||||||
|
1.9. "Licensable"
|
||||||
|
means having the right to grant, to the maximum extent possible,
|
||||||
|
whether at the time of the initial grant or subsequently, any and
|
||||||
|
all of the rights conveyed by this License.
|
||||||
|
|
||||||
|
1.10. "Modifications"
|
||||||
|
means any of the following:
|
||||||
|
|
||||||
|
(a) any file in Source Code Form that results from an addition to,
|
||||||
|
deletion from, or modification of the contents of Covered
|
||||||
|
Software; or
|
||||||
|
|
||||||
|
(b) any new file in Source Code Form that contains any Covered
|
||||||
|
Software.
|
||||||
|
|
||||||
|
1.11. "Patent Claims" of a Contributor
|
||||||
|
means any patent claim(s), including without limitation, method,
|
||||||
|
process, and apparatus claims, in any patent Licensable by such
|
||||||
|
Contributor that would be infringed, but for the grant of the
|
||||||
|
License, by the making, using, selling, offering for sale, having
|
||||||
|
made, import, or transfer of either its Contributions or its
|
||||||
|
Contributor Version.
|
||||||
|
|
||||||
|
1.12. "Secondary License"
|
||||||
|
means either the GNU General Public License, Version 2.0, the GNU
|
||||||
|
Lesser General Public License, Version 2.1, the GNU Affero General
|
||||||
|
Public License, Version 3.0, or any later versions of those
|
||||||
|
licenses.
|
||||||
|
|
||||||
|
1.13. "Source Code Form"
|
||||||
|
means the form of the work preferred for making modifications.
|
||||||
|
|
||||||
|
1.14. "You" (or "Your")
|
||||||
|
means an individual or a legal entity exercising rights under this
|
||||||
|
License. For legal entities, "You" includes any entity that
|
||||||
|
controls, is controlled by, or is under common control with You. For
|
||||||
|
purposes of this definition, "control" means (a) the power, direct
|
||||||
|
or indirect, to cause the direction or management of such entity,
|
||||||
|
whether by contract or otherwise, or (b) ownership of more than
|
||||||
|
fifty percent (50%) of the outstanding shares or beneficial
|
||||||
|
ownership of such entity.
|
||||||
|
|
||||||
|
2. License Grants and Conditions
|
||||||
|
--------------------------------
|
||||||
|
|
||||||
|
2.1. Grants
|
||||||
|
|
||||||
|
Each Contributor hereby grants You a world-wide, royalty-free,
|
||||||
|
non-exclusive license:
|
||||||
|
|
||||||
|
(a) under intellectual property rights (other than patent or trademark)
|
||||||
|
Licensable by such Contributor to use, reproduce, make available,
|
||||||
|
modify, display, perform, distribute, and otherwise exploit its
|
||||||
|
Contributions, either on an unmodified basis, with Modifications, or
|
||||||
|
as part of a Larger Work; and
|
||||||
|
|
||||||
|
(b) under Patent Claims of such Contributor to make, use, sell, offer
|
||||||
|
for sale, have made, import, and otherwise transfer either its
|
||||||
|
Contributions or its Contributor Version.
|
||||||
|
|
||||||
|
2.2. Effective Date
|
||||||
|
|
||||||
|
The licenses granted in Section 2.1 with respect to any Contribution
|
||||||
|
become effective for each Contribution on the date the Contributor first
|
||||||
|
distributes such Contribution.
|
||||||
|
|
||||||
|
2.3. Limitations on Grant Scope
|
||||||
|
|
||||||
|
The licenses granted in this Section 2 are the only rights granted under
|
||||||
|
this License. No additional rights or licenses will be implied from the
|
||||||
|
distribution or licensing of Covered Software under this License.
|
||||||
|
Notwithstanding Section 2.1(b) above, no patent license is granted by a
|
||||||
|
Contributor:
|
||||||
|
|
||||||
|
(a) for any code that a Contributor has removed from Covered Software;
|
||||||
|
or
|
||||||
|
|
||||||
|
(b) for infringements caused by: (i) Your and any other third party's
|
||||||
|
modifications of Covered Software, or (ii) the combination of its
|
||||||
|
Contributions with other software (except as part of its Contributor
|
||||||
|
Version); or
|
||||||
|
|
||||||
|
(c) under Patent Claims infringed by Covered Software in the absence of
|
||||||
|
its Contributions.
|
||||||
|
|
||||||
|
This License does not grant any rights in the trademarks, service marks,
|
||||||
|
or logos of any Contributor (except as may be necessary to comply with
|
||||||
|
the notice requirements in Section 3.4).
|
||||||
|
|
||||||
|
2.4. Subsequent Licenses
|
||||||
|
|
||||||
|
No Contributor makes additional grants as a result of Your choice to
|
||||||
|
distribute the Covered Software under a subsequent version of this
|
||||||
|
License (see Section 10.2) or under the terms of a Secondary License (if
|
||||||
|
permitted under the terms of Section 3.3).
|
||||||
|
|
||||||
|
2.5. Representation
|
||||||
|
|
||||||
|
Each Contributor represents that the Contributor believes its
|
||||||
|
Contributions are its original creation(s) or it has sufficient rights
|
||||||
|
to grant the rights to its Contributions conveyed by this License.
|
||||||
|
|
||||||
|
2.6. Fair Use
|
||||||
|
|
||||||
|
This License is not intended to limit any rights You have under
|
||||||
|
applicable copyright doctrines of fair use, fair dealing, or other
|
||||||
|
equivalents.
|
||||||
|
|
||||||
|
2.7. Conditions
|
||||||
|
|
||||||
|
Sections 3.1, 3.2, 3.3, and 3.4 are conditions of the licenses granted
|
||||||
|
in Section 2.1.
|
||||||
|
|
||||||
|
3. Responsibilities
|
||||||
|
-------------------
|
||||||
|
|
||||||
|
3.1. Distribution of Source Form
|
||||||
|
|
||||||
|
All distribution of Covered Software in Source Code Form, including any
|
||||||
|
Modifications that You create or to which You contribute, must be under
|
||||||
|
the terms of this License. You must inform recipients that the Source
|
||||||
|
Code Form of the Covered Software is governed by the terms of this
|
||||||
|
License, and how they can obtain a copy of this License. You may not
|
||||||
|
attempt to alter or restrict the recipients' rights in the Source Code
|
||||||
|
Form.
|
||||||
|
|
||||||
|
3.2. Distribution of Executable Form
|
||||||
|
|
||||||
|
If You distribute Covered Software in Executable Form then:
|
||||||
|
|
||||||
|
(a) such Covered Software must also be made available in Source Code
|
||||||
|
Form, as described in Section 3.1, and You must inform recipients of
|
||||||
|
the Executable Form how they can obtain a copy of such Source Code
|
||||||
|
Form by reasonable means in a timely manner, at a charge no more
|
||||||
|
than the cost of distribution to the recipient; and
|
||||||
|
|
||||||
|
(b) You may distribute such Executable Form under the terms of this
|
||||||
|
License, or sublicense it under different terms, provided that the
|
||||||
|
license for the Executable Form does not attempt to limit or alter
|
||||||
|
the recipients' rights in the Source Code Form under this License.
|
||||||
|
|
||||||
|
3.3. Distribution of a Larger Work
|
||||||
|
|
||||||
|
You may create and distribute a Larger Work under terms of Your choice,
|
||||||
|
provided that You also comply with the requirements of this License for
|
||||||
|
the Covered Software. If the Larger Work is a combination of Covered
|
||||||
|
Software with a work governed by one or more Secondary Licenses, and the
|
||||||
|
Covered Software is not Incompatible With Secondary Licenses, this
|
||||||
|
License permits You to additionally distribute such Covered Software
|
||||||
|
under the terms of such Secondary License(s), so that the recipient of
|
||||||
|
the Larger Work may, at their option, further distribute the Covered
|
||||||
|
Software under the terms of either this License or such Secondary
|
||||||
|
License(s).
|
||||||
|
|
||||||
|
3.4. Notices
|
||||||
|
|
||||||
|
You may not remove or alter the substance of any license notices
|
||||||
|
(including copyright notices, patent notices, disclaimers of warranty,
|
||||||
|
or limitations of liability) contained within the Source Code Form of
|
||||||
|
the Covered Software, except that You may alter any license notices to
|
||||||
|
the extent required to remedy known factual inaccuracies.
|
||||||
|
|
||||||
|
3.5. Application of Additional Terms
|
||||||
|
|
||||||
|
You may choose to offer, and to charge a fee for, warranty, support,
|
||||||
|
indemnity or liability obligations to one or more recipients of Covered
|
||||||
|
Software. However, You may do so only on Your own behalf, and not on
|
||||||
|
behalf of any Contributor. You must make it absolutely clear that any
|
||||||
|
such warranty, support, indemnity, or liability obligation is offered by
|
||||||
|
You alone, and You hereby agree to indemnify every Contributor for any
|
||||||
|
liability incurred by such Contributor as a result of warranty, support,
|
||||||
|
indemnity or liability terms You offer. You may include additional
|
||||||
|
disclaimers of warranty and limitations of liability specific to any
|
||||||
|
jurisdiction.
|
||||||
|
|
||||||
|
4. Inability to Comply Due to Statute or Regulation
|
||||||
|
---------------------------------------------------
|
||||||
|
|
||||||
|
If it is impossible for You to comply with any of the terms of this
|
||||||
|
License with respect to some or all of the Covered Software due to
|
||||||
|
statute, judicial order, or regulation then You must: (a) comply with
|
||||||
|
the terms of this License to the maximum extent possible; and (b)
|
||||||
|
describe the limitations and the code they affect. Such description must
|
||||||
|
be placed in a text file included with all distributions of the Covered
|
||||||
|
Software under this License. Except to the extent prohibited by statute
|
||||||
|
or regulation, such description must be sufficiently detailed for a
|
||||||
|
recipient of ordinary skill to be able to understand it.
|
||||||
|
|
||||||
|
5. Termination
|
||||||
|
--------------
|
||||||
|
|
||||||
|
5.1. The rights granted under this License will terminate automatically
|
||||||
|
if You fail to comply with any of its terms. However, if You become
|
||||||
|
compliant, then the rights granted under this License from a particular
|
||||||
|
Contributor are reinstated (a) provisionally, unless and until such
|
||||||
|
Contributor explicitly and finally terminates Your grants, and (b) on an
|
||||||
|
ongoing basis, if such Contributor fails to notify You of the
|
||||||
|
non-compliance by some reasonable means prior to 60 days after You have
|
||||||
|
come back into compliance. Moreover, Your grants from a particular
|
||||||
|
Contributor are reinstated on an ongoing basis if such Contributor
|
||||||
|
notifies You of the non-compliance by some reasonable means, this is the
|
||||||
|
first time You have received notice of non-compliance with this License
|
||||||
|
from such Contributor, and You become compliant prior to 30 days after
|
||||||
|
Your receipt of the notice.
|
||||||
|
|
||||||
|
5.2. If You initiate litigation against any entity by asserting a patent
|
||||||
|
infringement claim (excluding declaratory judgment actions,
|
||||||
|
counter-claims, and cross-claims) alleging that a Contributor Version
|
||||||
|
directly or indirectly infringes any patent, then the rights granted to
|
||||||
|
You by any and all Contributors for the Covered Software under Section
|
||||||
|
2.1 of this License shall terminate.
|
||||||
|
|
||||||
|
5.3. In the event of termination under Sections 5.1 or 5.2 above, all
|
||||||
|
end user license agreements (excluding distributors and resellers) which
|
||||||
|
have been validly granted by You or Your distributors under this License
|
||||||
|
prior to termination shall survive termination.
|
||||||
|
|
||||||
|
************************************************************************
|
||||||
|
* *
|
||||||
|
* 6. Disclaimer of Warranty *
|
||||||
|
* ------------------------- *
|
||||||
|
* *
|
||||||
|
* Covered Software is provided under this License on an "as is" *
|
||||||
|
* basis, without warranty of any kind, either expressed, implied, or *
|
||||||
|
* statutory, including, without limitation, warranties that the *
|
||||||
|
* Covered Software is free of defects, merchantable, fit for a *
|
||||||
|
* particular purpose or non-infringing. The entire risk as to the *
|
||||||
|
* quality and performance of the Covered Software is with You. *
|
||||||
|
* Should any Covered Software prove defective in any respect, You *
|
||||||
|
* (not any Contributor) assume the cost of any necessary servicing, *
|
||||||
|
* repair, or correction. This disclaimer of warranty constitutes an *
|
||||||
|
* essential part of this License. No use of any Covered Software is *
|
||||||
|
* authorized under this License except under this disclaimer. *
|
||||||
|
* *
|
||||||
|
************************************************************************
|
||||||
|
|
||||||
|
************************************************************************
|
||||||
|
* *
|
||||||
|
* 7. Limitation of Liability *
|
||||||
|
* -------------------------- *
|
||||||
|
* *
|
||||||
|
* Under no circumstances and under no legal theory, whether tort *
|
||||||
|
* (including negligence), contract, or otherwise, shall any *
|
||||||
|
* Contributor, or anyone who distributes Covered Software as *
|
||||||
|
* permitted above, be liable to You for any direct, indirect, *
|
||||||
|
* special, incidental, or consequential damages of any character *
|
||||||
|
* including, without limitation, damages for lost profits, loss of *
|
||||||
|
* goodwill, work stoppage, computer failure or malfunction, or any *
|
||||||
|
* and all other commercial damages or losses, even if such party *
|
||||||
|
* shall have been informed of the possibility of such damages. This *
|
||||||
|
* limitation of liability shall not apply to liability for death or *
|
||||||
|
* personal injury resulting from such party's negligence to the *
|
||||||
|
* extent applicable law prohibits such limitation. Some *
|
||||||
|
* jurisdictions do not allow the exclusion or limitation of *
|
||||||
|
* incidental or consequential damages, so this exclusion and *
|
||||||
|
* limitation may not apply to You. *
|
||||||
|
* *
|
||||||
|
************************************************************************
|
||||||
|
|
||||||
|
8. Litigation
|
||||||
|
-------------
|
||||||
|
|
||||||
|
Any litigation relating to this License may be brought only in the
|
||||||
|
courts of a jurisdiction where the defendant maintains its principal
|
||||||
|
place of business and such litigation shall be governed by laws of that
|
||||||
|
jurisdiction, without reference to its conflict-of-law provisions.
|
||||||
|
Nothing in this Section shall prevent a party's ability to bring
|
||||||
|
cross-claims or counter-claims.
|
||||||
|
|
||||||
|
9. Miscellaneous
|
||||||
|
----------------
|
||||||
|
|
||||||
|
This License represents the complete agreement concerning the subject
|
||||||
|
matter hereof. If any provision of this License is held to be
|
||||||
|
unenforceable, such provision shall be reformed only to the extent
|
||||||
|
necessary to make it enforceable. Any law or regulation which provides
|
||||||
|
that the language of a contract shall be construed against the drafter
|
||||||
|
shall not be used to construe this License against a Contributor.
|
||||||
|
|
||||||
|
10. Versions of the License
|
||||||
|
---------------------------
|
||||||
|
|
||||||
|
10.1. New Versions
|
||||||
|
|
||||||
|
Mozilla Foundation is the license steward. Except as provided in Section
|
||||||
|
10.3, no one other than the license steward has the right to modify or
|
||||||
|
publish new versions of this License. Each version will be given a
|
||||||
|
distinguishing version number.
|
||||||
|
|
||||||
|
10.2. Effect of New Versions
|
||||||
|
|
||||||
|
You may distribute the Covered Software under the terms of the version
|
||||||
|
of the License under which You originally received the Covered Software,
|
||||||
|
or under the terms of any subsequent version published by the license
|
||||||
|
steward.
|
||||||
|
|
||||||
|
10.3. Modified Versions
|
||||||
|
|
||||||
|
If you create software not governed by this License, and you want to
|
||||||
|
create a new license for such software, you may create and use a
|
||||||
|
modified version of this License if you rename the license and remove
|
||||||
|
any references to the name of the license steward (except to note that
|
||||||
|
such modified license differs from this License).
|
||||||
|
|
||||||
|
10.4. Distributing Source Code Form that is Incompatible With Secondary
|
||||||
|
Licenses
|
||||||
|
|
||||||
|
If You choose to distribute Source Code Form that is Incompatible With
|
||||||
|
Secondary Licenses under the terms of this version of the License, the
|
||||||
|
notice described in Exhibit B of this License must be attached.
|
||||||
|
|
||||||
|
Exhibit A - Source Code Form License Notice
|
||||||
|
-------------------------------------------
|
||||||
|
|
||||||
|
This Source Code Form is subject to the terms of the Mozilla Public
|
||||||
|
License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||||
|
file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||||
|
|
||||||
|
If it is not possible or desirable to put the notice in a particular
|
||||||
|
file, then You may include the notice in a location (such as a LICENSE
|
||||||
|
file in a relevant directory) where a recipient would be likely to look
|
||||||
|
for such a notice.
|
||||||
|
|
||||||
|
You may add additional accurate notices of copyright ownership.
|
||||||
|
|
||||||
|
Exhibit B - "Incompatible With Secondary Licenses" Notice
|
||||||
|
---------------------------------------------------------
|
||||||
|
|
||||||
|
This Source Code Form is "Incompatible With Secondary Licenses", as
|
||||||
|
defined by the Mozilla Public License, v. 2.0.
|
||||||
|
|
||||||
28
NOTICE
Normal file
28
NOTICE
Normal file
|
|
@ -0,0 +1,28 @@
|
||||||
|
# Notice
|
||||||
|
|
||||||
|
This project includes code under the following license(s):
|
||||||
|
|
||||||
|
```
|
||||||
|
MIT License
|
||||||
|
|
||||||
|
Copyright (c) 2020 GitHub, Inc.
|
||||||
|
|
||||||
|
Permission is hereby granted, free of charge, to any person obtaining a copy
|
||||||
|
of this software and associated documentation files (the "Software"), to deal
|
||||||
|
in the Software without restriction, including without limitation the rights
|
||||||
|
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
||||||
|
copies of the Software, and to permit persons to whom the Software is
|
||||||
|
furnished to do so, subject to the following conditions:
|
||||||
|
|
||||||
|
The above copyright notice and this permission notice shall be included in all
|
||||||
|
copies or substantial portions of the Software.
|
||||||
|
|
||||||
|
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
||||||
|
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
||||||
|
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
||||||
|
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
||||||
|
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
||||||
|
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
||||||
|
SOFTWARE.
|
||||||
|
|
||||||
|
```
|
||||||
133
README.md
Normal file
133
README.md
Normal file
|
|
@ -0,0 +1,133 @@
|
||||||
|
# setup-terraform
|
||||||
|
|
||||||
|
<p align="left">
|
||||||
|
<a href="https://github.com/hashicorp/setup-terraform/actions"><img alt="Continuous Integration" src="https://github.com/hashicorp/setup-terraform/workflows/Continuous%20Integration/badge.svg" /></a>
|
||||||
|
<a href="https://github.com/hashicorp/setup-terraform/actions"><img alt="Setup Terraform" src="https://github.com/hashicorp/setup-terraform/workflows/Setup%20Terraform/badge.svg" /></a>
|
||||||
|
</p>
|
||||||
|
|
||||||
|
This action sets up Terraform CLI in your [GitHub Actions](https://github.com/features/actions) workflow by:
|
||||||
|
|
||||||
|
- Downloading a specific version of Terraform CLI and adding it to the `PATH`.
|
||||||
|
- Configuring the Terraform CLI configuration file with a Terraform Cloud/Enterprise hostname and API token.
|
||||||
|
- Optionally installing a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively.
|
||||||
|
|
||||||
|
## Usage
|
||||||
|
|
||||||
|
This action can be run on `ubuntu-latest`, `windows-latest`, and `macos-latest` GitHub Actions runners. When running on `windows-latest` the shell should be set to Bash.
|
||||||
|
|
||||||
|
The default configuration installs the latest version of Terraform CLI and installs the wrapper to wrap subsequent calls to the `terraform` binary.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: hashicorp/setup-terraform@v1
|
||||||
|
```
|
||||||
|
|
||||||
|
A specific version of Terraform CLI can be installed.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: hashicorp/setup-terraform@v1
|
||||||
|
with:
|
||||||
|
terraform_version: 0.12.24
|
||||||
|
```
|
||||||
|
|
||||||
|
Credentials for Terraform Cloud (app.terraform.io) can be configured.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: hashicorp/setup-terraform@v1
|
||||||
|
with:
|
||||||
|
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
Credentials for Terraform Enterprise can be configured.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: hashicorp/setup-terraform@v1
|
||||||
|
with:
|
||||||
|
cli_config_credentials_hostname: 'terraform.example.com'
|
||||||
|
cli_config_credentials_token: ${{ secrets.TF_API_TOKEN }}
|
||||||
|
```
|
||||||
|
|
||||||
|
The wrapper installation can be skipped.
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: hashicorp/setup-terraform@v1
|
||||||
|
with:
|
||||||
|
terraform_wrapper: false
|
||||||
|
```
|
||||||
|
|
||||||
|
Subsequent steps can access outputs when the wrapper is installed.
|
||||||
|
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: hashicorp/setup-terraform@v1
|
||||||
|
|
||||||
|
- run: terraform init
|
||||||
|
|
||||||
|
- id: plan
|
||||||
|
run: terraform plan -no-color
|
||||||
|
|
||||||
|
- run: echo ${{ steps.plan.outputs.stdout }}
|
||||||
|
- run: echo ${{ steps.plan.outputs.stderr }}
|
||||||
|
- run: echo ${{ steps.plan.outputs.exitcode }}
|
||||||
|
```
|
||||||
|
|
||||||
|
The outputs can be used in subsequent steps to comment on the pull request:
|
||||||
|
|
||||||
|
```yaml
|
||||||
|
steps:
|
||||||
|
- uses: hashicorp/setup-terraform@v1
|
||||||
|
|
||||||
|
- run: terraform init
|
||||||
|
|
||||||
|
- id: plan
|
||||||
|
run: terraform plan -no-color
|
||||||
|
|
||||||
|
- uses: actions/github-script@0.9.0
|
||||||
|
if: github.event_name == 'pull_request'
|
||||||
|
env:
|
||||||
|
STDOUT: "```${{ steps.plan.outputs.stdout }}```"
|
||||||
|
with:
|
||||||
|
github-token: ${{ secrets.GITHUB_TOKEN }}
|
||||||
|
script: |
|
||||||
|
github.issues.createComment({
|
||||||
|
issue_number: context.issue.number,
|
||||||
|
owner: context.repo.owner,
|
||||||
|
repo: context.repo.repo,
|
||||||
|
body: process.env.STDOUT
|
||||||
|
})
|
||||||
|
```
|
||||||
|
|
||||||
|
## Inputs
|
||||||
|
|
||||||
|
The following inputs are supported.
|
||||||
|
|
||||||
|
- `cli_config_credentials_hostname` - (optional) The hostname of a Terraform Cloud/Enterprise instance to place within the credentials block of the Terraform CLI configuration file.
|
||||||
|
|
||||||
|
- `cli_config_credentials_token` - (optional) The API token for a Terraform Cloud/Enterprise instance to place within the credentials block of the Terraform CLI configuration file.
|
||||||
|
|
||||||
|
- `terraform_version` - (optional) The version of Terraform CLI to install. A value of `latest` will install the latest version of Terraform CLI. Defaults to `latest`.
|
||||||
|
|
||||||
|
- `terraform_wrapper` - (optional) Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.
|
||||||
|
|
||||||
|
## Outputs
|
||||||
|
|
||||||
|
This action does not configure any outputs directly. However, when the `terraform_wrapper` input is set to `true`, the following outputs will be available for subsequent steps that call the `terraform` binary.
|
||||||
|
|
||||||
|
- `stdout` - The STDOUT stream of the call to the `terraform` binary.
|
||||||
|
|
||||||
|
- `stderr` - The STDERR stream of the call to the `terraform` binary.
|
||||||
|
|
||||||
|
- `exitcode` - The exit code of the call to the `terraform` binary..
|
||||||
|
|
||||||
|
## License
|
||||||
|
|
||||||
|
[Mozilla Public License v2.0](https://github.com/hashicorp/setup-terraform/blob/master/LICENSE)
|
||||||
|
|
||||||
|
## Code of Conduct
|
||||||
|
|
||||||
|
[Code of Conduct](https://github.com/hashicorp/setup-terraform/blob/master/CODE_OF_CONDUCT.md)
|
||||||
25
action.yml
Normal file
25
action.yml
Normal file
|
|
@ -0,0 +1,25 @@
|
||||||
|
name: 'HashiCorp - Setup Terraform'
|
||||||
|
description: 'Sets up Terraform CLI in your GitHub Actions workflow.'
|
||||||
|
author: 'HashiCorp, Inc.'
|
||||||
|
inputs:
|
||||||
|
cli_config_credentials_hostname:
|
||||||
|
description: 'The hostname of a Terraform Cloud/Enterprise instance to place within the credentials block of the Terraform CLI configuration file.'
|
||||||
|
default: 'app.terraform.io'
|
||||||
|
required: false
|
||||||
|
cli_config_credentials_token:
|
||||||
|
description: 'The API token for a Terraform Cloud/Enterprise instance to place within the credentials block of the Terraform CLI configuration file.'
|
||||||
|
required: false
|
||||||
|
terraform_version:
|
||||||
|
description: 'The version of Terraform CLI to install. A value of `latest` will install the latest version of Terraform CLI. Defaults to `latest`.'
|
||||||
|
default: 'latest'
|
||||||
|
required: false
|
||||||
|
terraform_wrapper:
|
||||||
|
description: 'Whether or not to install a wrapper to wrap subsequent calls of the `terraform` binary and expose its STDOUT, STDERR, and exit code as outputs named `stdout`, `stderr`, and `exitcode` respectively. Defaults to `true`.'
|
||||||
|
default: 'true'
|
||||||
|
required: false
|
||||||
|
runs:
|
||||||
|
using: 'node12'
|
||||||
|
main: 'dist/index.js'
|
||||||
|
branding:
|
||||||
|
icon: 'terminal'
|
||||||
|
color: 'purple'
|
||||||
8511
dist/index.js
vendored
Normal file
8511
dist/index.js
vendored
Normal file
File diff suppressed because it is too large
Load diff
1647
dist/index1.js
vendored
Executable file
1647
dist/index1.js
vendored
Executable file
File diff suppressed because it is too large
Load diff
11
index.js
Normal file
11
index.js
Normal file
|
|
@ -0,0 +1,11 @@
|
||||||
|
const core = require('@actions/core');
|
||||||
|
|
||||||
|
const setup = require('./lib/setup-terraform');
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
try {
|
||||||
|
await setup();
|
||||||
|
} catch (error) {
|
||||||
|
core.setFailed(error.message);
|
||||||
|
}
|
||||||
|
})();
|
||||||
204
lib/setup-terraform.js
Normal file
204
lib/setup-terraform.js
Normal file
|
|
@ -0,0 +1,204 @@
|
||||||
|
// Node.js core
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
// External
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
const io = require('@actions/io');
|
||||||
|
const fetch = require('node-fetch');
|
||||||
|
const semver = require('semver');
|
||||||
|
|
||||||
|
// Find latest version given list of all available
|
||||||
|
function findLatest (allVersions) {
|
||||||
|
core.debug('Parsing version list for latest version');
|
||||||
|
|
||||||
|
let latest = '0.0.0';
|
||||||
|
|
||||||
|
for (const version in allVersions.versions) {
|
||||||
|
// is "version" greater than "latest"
|
||||||
|
latest = semver.gt(version, latest) ? version : latest;
|
||||||
|
}
|
||||||
|
|
||||||
|
return allVersions.versions[latest];
|
||||||
|
}
|
||||||
|
|
||||||
|
// Find specific version given list of all available
|
||||||
|
function findSpecific (allVersions, version) {
|
||||||
|
core.debug(`Parsing version list for version ${version}`);
|
||||||
|
|
||||||
|
const versionObj = allVersions.versions[version];
|
||||||
|
|
||||||
|
if (!versionObj) {
|
||||||
|
throw new Error(`Could not find Terraform version ${version} in version list`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return versionObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadMetadata () {
|
||||||
|
core.debug('Downloading version metadata');
|
||||||
|
|
||||||
|
return fetch('https://releases.hashicorp.com/terraform/index.json')
|
||||||
|
.then(res => res.json())
|
||||||
|
.catch(err => {
|
||||||
|
core.setFailed(`Failed to fetch version metadata. ${err}`);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
// arch in [arm, x32, x64...] (https://nodejs.org/api/os.html#os_os_arch)
|
||||||
|
// return value in [amd64, 386, arm]
|
||||||
|
function mapArch (arch) {
|
||||||
|
const mappings = {
|
||||||
|
x32: '386',
|
||||||
|
x64: 'amd64'
|
||||||
|
};
|
||||||
|
return mappings[arch] || arch;
|
||||||
|
}
|
||||||
|
|
||||||
|
// os in [darwin, linux, win32...] (https://nodejs.org/api/os.html#os_os_platform)
|
||||||
|
// return value in [darwin, linux, windows]
|
||||||
|
function mapOS (os) {
|
||||||
|
const mappings = {
|
||||||
|
win32: 'windows'
|
||||||
|
};
|
||||||
|
return mappings[os] || os;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Get build for an operating system and architecture
|
||||||
|
function getBuild (versionObj, os, arch) {
|
||||||
|
core.debug(`Getting build for Terraform version ${versionObj.version}, os ${os}, and arch ${arch}`);
|
||||||
|
|
||||||
|
const buildObj = versionObj.builds.length &&
|
||||||
|
versionObj.builds.find(build =>
|
||||||
|
build.arch === mapArch(arch) &&
|
||||||
|
build.os === mapOS(os)
|
||||||
|
);
|
||||||
|
|
||||||
|
if (!buildObj) {
|
||||||
|
throw new Error(`Terraform version ${versionObj.version} not available for ${os} and ${arch}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return buildObj;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function downloadCLI (url) {
|
||||||
|
core.debug(`Downloading Terraform CLI from ${url}`);
|
||||||
|
const pathToCLIZip = await tc.downloadTool(url);
|
||||||
|
|
||||||
|
core.debug('Extracting Terraform CLI zip file');
|
||||||
|
const pathToCLI = await tc.extractZip(pathToCLIZip);
|
||||||
|
core.debug(`Terraform CLI path is ${pathToCLI}.`);
|
||||||
|
|
||||||
|
if (!pathToCLIZip || !pathToCLI) {
|
||||||
|
throw new Error(`Unable to download Terraform from ${url}`);
|
||||||
|
}
|
||||||
|
|
||||||
|
return pathToCLI;
|
||||||
|
}
|
||||||
|
|
||||||
|
async function installWrapper (pathToCLI) {
|
||||||
|
let source, target;
|
||||||
|
|
||||||
|
// If we're on Windows, then the executable ends with .exe
|
||||||
|
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
|
||||||
|
|
||||||
|
// Rename terraform(.exe) to terraform-bin(.exe)
|
||||||
|
try {
|
||||||
|
source = [pathToCLI, `terraform${exeSuffix}`].join(path.sep);
|
||||||
|
target = [pathToCLI, `terraform-bin${exeSuffix}`].join(path.sep);
|
||||||
|
core.debug(`Moving ${source} to ${target}.`);
|
||||||
|
await io.mv(source, target);
|
||||||
|
} catch (e) {
|
||||||
|
core.error(`Unable to move ${source} to ${target}.`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Install our wrapper as terraform
|
||||||
|
try {
|
||||||
|
source = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
|
||||||
|
target = [pathToCLI, 'terraform'].join(path.sep);
|
||||||
|
core.debug(`Copying ${source} to ${target}.`);
|
||||||
|
await io.cp(source, target);
|
||||||
|
} catch (e) {
|
||||||
|
core.error(`Unable to copy ${source} to ${target}.`);
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Export a new environment variable, so our wrapper can locate the binary
|
||||||
|
core.exportVariable('TERRAFORM_CLI_PATH', pathToCLI);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add credentials to CLI Configuration File
|
||||||
|
// https://www.terraform.io/docs/commands/cli-config.html
|
||||||
|
async function addCredentials (credentialsHostname, credentialsToken, osPlat) {
|
||||||
|
// format HCL block
|
||||||
|
// eslint-disable
|
||||||
|
const creds = `
|
||||||
|
credentials "${credentialsHostname}" {
|
||||||
|
token = "${credentialsToken}"
|
||||||
|
}`.trim();
|
||||||
|
// eslint-enable
|
||||||
|
|
||||||
|
// default to OS-specific path
|
||||||
|
let credsFile = osPlat === 'win32'
|
||||||
|
? `${process.env.APPDATA}/terraform.rc`
|
||||||
|
: `${process.env.HOME}/.terraformrc`;
|
||||||
|
|
||||||
|
// override with TF_CLI_CONFIG_FILE environment variable
|
||||||
|
credsFile = process.env.TF_CLI_CONFIG_FILE ? process.env.TF_CLI_CONFIG_FILE : credsFile;
|
||||||
|
|
||||||
|
// get containing folder
|
||||||
|
const credsFolder = path.dirname(credsFile);
|
||||||
|
|
||||||
|
core.debug(`Creating ${credsFolder}`);
|
||||||
|
await io.mkdirP(credsFolder);
|
||||||
|
|
||||||
|
core.debug(`Adding credentials to ${credsFile}`);
|
||||||
|
await fs.writeFile(credsFile, creds);
|
||||||
|
}
|
||||||
|
|
||||||
|
async function run () {
|
||||||
|
try {
|
||||||
|
// Gather GitHub Actions inputs
|
||||||
|
const version = core.getInput('terraform_version');
|
||||||
|
const credentialsHostname = core.getInput('cli_config_credentials_hostname');
|
||||||
|
const credentialsToken = core.getInput('cli_config_credentials_token');
|
||||||
|
const wrapper = core.getInput('terraform_wrapper') === 'true';
|
||||||
|
|
||||||
|
// Gather OS details
|
||||||
|
const osPlat = os.platform();
|
||||||
|
const osArch = os.arch();
|
||||||
|
|
||||||
|
// Download metadata about all versions of Terraform CLI
|
||||||
|
const versionMetadata = await downloadMetadata();
|
||||||
|
|
||||||
|
// Find latest or a specific version like 0.1.0
|
||||||
|
const versionObj = version.toLowerCase() === 'latest' ? findLatest(versionMetadata) : findSpecific(versionMetadata, version);
|
||||||
|
|
||||||
|
// Get the build available for this runner's OS and a 64 bit architecture
|
||||||
|
const buildObj = getBuild(versionObj, osPlat, osArch);
|
||||||
|
|
||||||
|
// Download requested version
|
||||||
|
const pathToCLI = await downloadCLI(buildObj.url);
|
||||||
|
|
||||||
|
// Install our wrapper
|
||||||
|
if (wrapper) {
|
||||||
|
await installWrapper(pathToCLI);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Add to path
|
||||||
|
core.addPath(pathToCLI);
|
||||||
|
|
||||||
|
// Add credentials to file if they are provided
|
||||||
|
if (credentialsHostname && credentialsToken) {
|
||||||
|
await addCredentials(credentialsHostname, credentialsToken, osPlat);
|
||||||
|
}
|
||||||
|
} catch (error) {
|
||||||
|
core.error(error);
|
||||||
|
throw new Error(error);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = run;
|
||||||
7406
package-lock.json
generated
Normal file
7406
package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
47
package.json
Normal file
47
package.json
Normal file
|
|
@ -0,0 +1,47 @@
|
||||||
|
{
|
||||||
|
"name": "setup-terraform",
|
||||||
|
"version": "1.0.0",
|
||||||
|
"description": "Setup Terraform CLI for GitHub Actions",
|
||||||
|
"main": "index.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "cd wrapper && npm test && cd .. && semistandard --env jest && jest --coverage",
|
||||||
|
"lint": "cd wrapper && npm run lint && cd .. && semistandard --env jest --fix",
|
||||||
|
"build": "cd wrapper && npm run build && cd .. && ncc build index.js --out dist",
|
||||||
|
"postinstall": "cd wrapper && npm install"
|
||||||
|
},
|
||||||
|
"keywords": [],
|
||||||
|
"author": "",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.2.3",
|
||||||
|
"@actions/github": "^2.1.1",
|
||||||
|
"@actions/io": "^1.0.2",
|
||||||
|
"@actions/tool-cache": "^1.3.3",
|
||||||
|
"node-fetch": "^2.6.0",
|
||||||
|
"semver": "^7.1.3"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@zeit/ncc": "0.22.1",
|
||||||
|
"husky": "^4.2.3",
|
||||||
|
"jest": "^25.2.4",
|
||||||
|
"nock": "^12.0.3",
|
||||||
|
"semistandard": "^14.2.0"
|
||||||
|
},
|
||||||
|
"jest": {
|
||||||
|
"testPathIgnorePatterns": [
|
||||||
|
"<rootDir>/dist/",
|
||||||
|
"<rootDir>/node_modules/",
|
||||||
|
"<rootDir>/wrapper/"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"semistandard": {
|
||||||
|
"ignore": [
|
||||||
|
"dist/**",
|
||||||
|
"wrapper/**"
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"husky": {
|
||||||
|
"hooks": {
|
||||||
|
"pre-commit": "npm run build && git add dist/"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
181
test/index.json
Normal file
181
test/index.json
Normal file
|
|
@ -0,0 +1,181 @@
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"versions": {
|
||||||
|
"0.1.0": {
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"shasums": "terraform_0.1.0_SHA256SUMS",
|
||||||
|
"shasums_signature": "terraform_0.1.0_SHA256SUMS.sig",
|
||||||
|
"builds": [
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"os": "darwin",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.1.0_darwin_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.0/terraform_0.1.0_darwin_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"os": "linux",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.1.0_linux_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.0/terraform_0.1.0_linux_386.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"os": "linux",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.1.0_linux_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.0/terraform_0.1.0_linux_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.0",
|
||||||
|
"os": "windows",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.1.0_windows_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.0/terraform_0.1.0_windows_386.zip"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"0.1.1": {
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"shasums": "terraform_0.1.1_SHA256SUMS",
|
||||||
|
"shasums_signature": "terraform_0.1.1_SHA256SUMS.sig",
|
||||||
|
"builds": [
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"os": "darwin",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.1.1_darwin_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.1/terraform_0.1.1_darwin_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"os": "linux",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.1.1_linux_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.1/terraform_0.1.1_linux_386.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"os": "linux",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.1.1_linux_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.1/terraform_0.1.1_linux_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.1.1",
|
||||||
|
"os": "windows",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.1.1_windows_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.1.1/terraform_0.1.1_windows_386.zip"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
},
|
||||||
|
"0.10.0": {
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"shasums": "terraform_0.10.0_SHA256SUMS",
|
||||||
|
"shasums_signature": "terraform_0.10.0_SHA256SUMS.sig",
|
||||||
|
"builds": [
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "darwin",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.10.0_darwin_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_darwin_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "freebsd",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.10.0_freebsd_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_freebsd_386.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "freebsd",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.10.0_freebsd_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_freebsd_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "freebsd",
|
||||||
|
"arch": "arm",
|
||||||
|
"filename": "terraform_0.10.0_freebsd_arm.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_freebsd_arm.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "linux",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.10.0_linux_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_linux_386.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "linux",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.10.0_linux_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_linux_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "linux",
|
||||||
|
"arch": "arm",
|
||||||
|
"filename": "terraform_0.10.0_linux_arm.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_linux_arm.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "openbsd",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.10.0_openbsd_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_openbsd_386.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "openbsd",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.10.0_openbsd_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_openbsd_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "solaris",
|
||||||
|
"arch": "amd64",
|
||||||
|
"filename": "terraform_0.10.0_solaris_amd64.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_solaris_amd64.zip"
|
||||||
|
},
|
||||||
|
{
|
||||||
|
"name": "terraform",
|
||||||
|
"version": "0.10.0",
|
||||||
|
"os": "windows",
|
||||||
|
"arch": "386",
|
||||||
|
"filename": "terraform_0.10.0_windows_386.zip",
|
||||||
|
"url": "https://releases.hashicorp.com/terraform/0.10.0/terraform_0.10.0_windows_386.zip"
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
373
test/setup-terraform.test.js
Normal file
373
test/setup-terraform.test.js
Normal file
|
|
@ -0,0 +1,373 @@
|
||||||
|
// Mock external modules by default
|
||||||
|
jest.mock('@actions/core');
|
||||||
|
jest.mock('@actions/tool-cache');
|
||||||
|
// Mock Node.js core modules
|
||||||
|
jest.mock('os');
|
||||||
|
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
|
const fs = require('fs').promises;
|
||||||
|
|
||||||
|
const io = require('@actions/io');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const tc = require('@actions/tool-cache');
|
||||||
|
const nock = require('nock');
|
||||||
|
|
||||||
|
const json = require('./index.json');
|
||||||
|
const setup = require('../lib/setup-terraform');
|
||||||
|
|
||||||
|
// Overwrite defaults
|
||||||
|
// core.debug = jest
|
||||||
|
// .fn(console.log);
|
||||||
|
// core.error = jest
|
||||||
|
// .fn(console.error);
|
||||||
|
|
||||||
|
describe('Setup Terraform', () => {
|
||||||
|
const HOME = process.env.HOME;
|
||||||
|
const APPDATA = process.env.APPDATA;
|
||||||
|
|
||||||
|
beforeEach(() => {
|
||||||
|
process.env.HOME = '/tmp/asdf';
|
||||||
|
process.env.APPDATA = '/tmp/asdf';
|
||||||
|
});
|
||||||
|
|
||||||
|
afterEach(async () => {
|
||||||
|
await io.rmRF(process.env.HOME);
|
||||||
|
process.env.HOME = HOME;
|
||||||
|
process.env.APPDATA = APPDATA;
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gets specific version and adds token and hostname on linux, amd64', async () => {
|
||||||
|
const version = '0.1.1';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken);
|
||||||
|
|
||||||
|
tc.downloadTool = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file.zip');
|
||||||
|
|
||||||
|
tc.extractZip = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file');
|
||||||
|
|
||||||
|
os.platform = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('linux');
|
||||||
|
|
||||||
|
os.arch = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('amd64');
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
// downloaded CLI has been added to path
|
||||||
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
|
|
||||||
|
// expect credentials are in ${HOME}.terraformrc
|
||||||
|
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
||||||
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gets specific version and adds token and hostname on windows, 386', async () => {
|
||||||
|
const version = '0.1.1';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken);
|
||||||
|
|
||||||
|
tc.downloadTool = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file.zip');
|
||||||
|
|
||||||
|
tc.extractZip = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file');
|
||||||
|
|
||||||
|
os.platform = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('win32');
|
||||||
|
|
||||||
|
os.arch = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('386');
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
// downloaded CLI has been added to path
|
||||||
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
|
|
||||||
|
// expect credentials are in ${HOME}.terraformrc
|
||||||
|
const creds = await fs.readFile(`${process.env.HOME}/terraform.rc`, { encoding: 'utf8' });
|
||||||
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('gets latest version and adds token and hostname on linux, amd64', async () => {
|
||||||
|
const version = 'latest';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken);
|
||||||
|
|
||||||
|
tc.downloadTool = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file.zip');
|
||||||
|
|
||||||
|
tc.extractZip = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file');
|
||||||
|
|
||||||
|
os.platform = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('linux');
|
||||||
|
|
||||||
|
os.arch = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('amd64');
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
// downloaded CLI has been added to path
|
||||||
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
|
|
||||||
|
// expect credentials are in ${HOME}.terraformrc
|
||||||
|
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
||||||
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fails when metadata cannot be downloaded', async () => {
|
||||||
|
const version = 'latest';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken);
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(404);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await setup();
|
||||||
|
} catch (e) {
|
||||||
|
expect(core.error).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fails when specific version cannot be found', async () => {
|
||||||
|
const version = '0.9.9';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken);
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
try {
|
||||||
|
await setup();
|
||||||
|
} catch (e) {
|
||||||
|
expect(core.error).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fails when CLI for os and architecture cannot be found', async () => {
|
||||||
|
const version = '0.1.1';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken);
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
tc.downloadTool = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file.zip');
|
||||||
|
|
||||||
|
tc.extractZip = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file');
|
||||||
|
|
||||||
|
os.platform = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('madeupplat');
|
||||||
|
|
||||||
|
os.arch = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('madeuparch');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await setup();
|
||||||
|
} catch (e) {
|
||||||
|
expect(core.error).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('fails when CLI cannot be downloaded', async () => {
|
||||||
|
const version = '0.1.1';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken);
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
tc.downloadTool = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('');
|
||||||
|
|
||||||
|
tc.extractZip = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('');
|
||||||
|
|
||||||
|
os.platform = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('linux');
|
||||||
|
|
||||||
|
os.arch = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('amd64');
|
||||||
|
|
||||||
|
try {
|
||||||
|
await setup();
|
||||||
|
} catch (e) {
|
||||||
|
expect(core.error).toHaveBeenCalled();
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
test('installs wrapper on linux', async () => {
|
||||||
|
const version = '0.1.1';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
const wrapperPath = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
|
||||||
|
|
||||||
|
const ioMv = jest.spyOn(io, 'mv')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
const ioCp = jest.spyOn(io, 'cp')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken)
|
||||||
|
.mockReturnValueOnce('true');
|
||||||
|
|
||||||
|
tc.downloadTool = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file.zip');
|
||||||
|
|
||||||
|
tc.extractZip = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file');
|
||||||
|
|
||||||
|
os.platform = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('linux');
|
||||||
|
|
||||||
|
os.arch = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('amd64');
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
expect(ioMv).toHaveBeenCalledWith(`file${path.sep}terraform`, `file${path.sep}terraform-bin`);
|
||||||
|
expect(ioCp).toHaveBeenCalledWith(wrapperPath, `file${path.sep}terraform`);
|
||||||
|
});
|
||||||
|
|
||||||
|
test('installs wrapper on windows', async () => {
|
||||||
|
const version = '0.1.1';
|
||||||
|
const credentialsHostname = 'app.terraform.io';
|
||||||
|
const credentialsToken = 'asdfjkl';
|
||||||
|
const wrapperPath = path.resolve([__dirname, '..', 'wrapper', 'dist', 'index.js'].join(path.sep));
|
||||||
|
|
||||||
|
const ioMv = jest.spyOn(io, 'mv')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
const ioCp = jest.spyOn(io, 'cp')
|
||||||
|
.mockImplementation(() => {});
|
||||||
|
|
||||||
|
core.getInput = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce(version)
|
||||||
|
.mockReturnValueOnce(credentialsHostname)
|
||||||
|
.mockReturnValueOnce(credentialsToken)
|
||||||
|
.mockReturnValueOnce('true');
|
||||||
|
|
||||||
|
tc.downloadTool = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file.zip');
|
||||||
|
|
||||||
|
tc.extractZip = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValueOnce('file');
|
||||||
|
|
||||||
|
os.platform = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('win32');
|
||||||
|
|
||||||
|
os.arch = jest
|
||||||
|
.fn()
|
||||||
|
.mockReturnValue('386');
|
||||||
|
|
||||||
|
nock('https://releases.hashicorp.com')
|
||||||
|
.get('/terraform/index.json')
|
||||||
|
.reply(200, json);
|
||||||
|
|
||||||
|
await setup();
|
||||||
|
|
||||||
|
expect(ioMv).toHaveBeenCalledWith(`file${path.sep}terraform.exe`, `file${path.sep}terraform-bin.exe`);
|
||||||
|
expect(ioCp).toHaveBeenCalledWith(wrapperPath, `file${path.sep}terraform`);
|
||||||
|
});
|
||||||
|
});
|
||||||
36
wrapper/lib/output-listener.js
Normal file
36
wrapper/lib/output-listener.js
Normal file
|
|
@ -0,0 +1,36 @@
|
||||||
|
/**
|
||||||
|
* Acts as a listener for @actions/exec, by capturing STDOUT and STDERR
|
||||||
|
* streams, and exposing them via a contents attribute.
|
||||||
|
*
|
||||||
|
* @example
|
||||||
|
* // Instantiate a new listener
|
||||||
|
* const listener = new OutputListener();
|
||||||
|
* // Register listener against STDOUT stream
|
||||||
|
* await exec.exec('ls', ['-ltr'], {
|
||||||
|
* listeners: {
|
||||||
|
* stdout: listener.listener
|
||||||
|
* }
|
||||||
|
* });
|
||||||
|
* // Log out STDOUT contents
|
||||||
|
* console.log(listener.contents);
|
||||||
|
*/
|
||||||
|
class OutputListener {
|
||||||
|
constructor () {
|
||||||
|
this._buff = [];
|
||||||
|
}
|
||||||
|
|
||||||
|
get listener () {
|
||||||
|
const listen = function listen (data) {
|
||||||
|
this._buff.push(data);
|
||||||
|
};
|
||||||
|
return listen.bind(this);
|
||||||
|
}
|
||||||
|
|
||||||
|
get contents () {
|
||||||
|
return this._buff
|
||||||
|
.map(chunk => chunk.toString())
|
||||||
|
.join('');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
module.exports = OutputListener;
|
||||||
9
wrapper/lib/terraform-bin.js
Normal file
9
wrapper/lib/terraform-bin.js
Normal file
|
|
@ -0,0 +1,9 @@
|
||||||
|
const os = require('os');
|
||||||
|
const path = require('path');
|
||||||
|
|
||||||
|
module.exports = (() => {
|
||||||
|
// If we're on Windows, then the executable ends with .exe
|
||||||
|
const exeSuffix = os.platform().startsWith('win') ? '.exe' : '';
|
||||||
|
|
||||||
|
return [process.env.TERRAFORM_CLI_PATH, `terraform-bin${exeSuffix}`].join(path.sep);
|
||||||
|
})();
|
||||||
7295
wrapper/package-lock.json
generated
Normal file
7295
wrapper/package-lock.json
generated
Normal file
File diff suppressed because it is too large
Load diff
27
wrapper/package.json
Normal file
27
wrapper/package.json
Normal file
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"name": "terraform.js",
|
||||||
|
"version": "0.0.0",
|
||||||
|
"description": "JavaScript wrapper for terraform binary",
|
||||||
|
"main": "terraform.js",
|
||||||
|
"scripts": {
|
||||||
|
"test": "semistandard --env jest && jest --coverage",
|
||||||
|
"lint": "semistandard --env jest --fix",
|
||||||
|
"build": "ncc build terraform.js --out dist"
|
||||||
|
},
|
||||||
|
"author": "",
|
||||||
|
"dependencies": {
|
||||||
|
"@actions/core": "^1.2.3",
|
||||||
|
"@actions/exec": "^1.0.3",
|
||||||
|
"@actions/io": "^1.0.2"
|
||||||
|
},
|
||||||
|
"devDependencies": {
|
||||||
|
"@zeit/ncc": "0.22.1",
|
||||||
|
"jest": "^25.4.0",
|
||||||
|
"semistandard": "^14.2.0"
|
||||||
|
},
|
||||||
|
"semistandard": {
|
||||||
|
"ignore": [
|
||||||
|
"dist/**"
|
||||||
|
]
|
||||||
|
}
|
||||||
|
}
|
||||||
48
wrapper/terraform.js
Executable file
48
wrapper/terraform.js
Executable file
|
|
@ -0,0 +1,48 @@
|
||||||
|
#!/usr/bin/env node
|
||||||
|
const io = require('@actions/io');
|
||||||
|
const core = require('@actions/core');
|
||||||
|
const { exec } = require('@actions/exec');
|
||||||
|
|
||||||
|
const OutputListener = require('./lib/output-listener');
|
||||||
|
const pathToCLI = require('./lib/terraform-bin');
|
||||||
|
|
||||||
|
async function checkTerraform () {
|
||||||
|
// Setting check to `true` will cause `which` to throw if terraform isn't found
|
||||||
|
const check = true;
|
||||||
|
return io.which(pathToCLI, check);
|
||||||
|
}
|
||||||
|
|
||||||
|
(async () => {
|
||||||
|
// This will fail if Terraform isn't found, which is what we want
|
||||||
|
await checkTerraform();
|
||||||
|
|
||||||
|
// Create listeners to receive output (in memory) as well
|
||||||
|
const stdout = new OutputListener();
|
||||||
|
const stderr = new OutputListener();
|
||||||
|
const listeners = {
|
||||||
|
stdout: stdout.listener,
|
||||||
|
stderr: stderr.listener
|
||||||
|
};
|
||||||
|
|
||||||
|
// Execute terraform and capture output
|
||||||
|
const args = process.argv.slice(2);
|
||||||
|
const options = {
|
||||||
|
listeners,
|
||||||
|
ignoreReturnCode: true
|
||||||
|
};
|
||||||
|
const exitCode = await exec(pathToCLI, args, options);
|
||||||
|
core.debug(`Terraform exited with code ${exitCode}.`);
|
||||||
|
core.debug(`stdout: ${stdout.contents}`);
|
||||||
|
core.debug(`stderr: ${stderr.contents}`);
|
||||||
|
core.debug(`exitcode: ${exitCode}`);
|
||||||
|
|
||||||
|
// Set outputs, result, exitcode, and stderr
|
||||||
|
core.setOutput('stdout', stdout.contents);
|
||||||
|
core.setOutput('stderr', stderr.contents);
|
||||||
|
core.setOutput('exitcode', exitCode.toString(10));
|
||||||
|
|
||||||
|
// A non-zero exitCode is considered an error
|
||||||
|
if (exitCode !== 0) {
|
||||||
|
core.setFailed(`Terraform exited with code ${exitCode}.`);
|
||||||
|
}
|
||||||
|
})();
|
||||||
12
wrapper/test/output-listener.test.js
Normal file
12
wrapper/test/output-listener.test.js
Normal file
|
|
@ -0,0 +1,12 @@
|
||||||
|
const OutputListener = require('../lib/output-listener');
|
||||||
|
|
||||||
|
describe('output-listener', () => {
|
||||||
|
it('receives and exposes data', () => {
|
||||||
|
const listener = new OutputListener();
|
||||||
|
const listen = listener.listener;
|
||||||
|
listen(Buffer.from('foo'));
|
||||||
|
listen(Buffer.from('bar'));
|
||||||
|
listen(Buffer.from('baz'));
|
||||||
|
expect(listener.contents).toEqual('foobarbaz');
|
||||||
|
});
|
||||||
|
});
|
||||||
Loading…
Add table
Add a link
Reference in a new issue