mirror of
https://github.com/hashicorp/setup-terraform.git
synced 2025-12-17 08:52:37 +00:00
Merge f872146a9f into 92e4d08fe1
This commit is contained in:
commit
fefd48d0f9
4 changed files with 44 additions and 70 deletions
36
.github/workflows/setup-terraform.yml
vendored
36
.github/workflows/setup-terraform.yml
vendored
|
|
@ -116,17 +116,10 @@ jobs:
|
||||||
with:
|
with:
|
||||||
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
||||||
|
|
||||||
- name: Validate Terraform Credentials (Windows)
|
- name: Validate Terraform Credentials
|
||||||
if: runner.os == 'Windows'
|
|
||||||
run: |
|
run: |
|
||||||
cat ${APPDATA}/terraform.rc | grep 'credentials "app.terraform.io"'
|
cat ${RUNNER_TEMP}/setup-terraform.tfrc | grep 'credentials "app.terraform.io"'
|
||||||
cat ${APPDATA}/terraform.rc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
cat ${RUNNER_TEMP}/setup-terraform.tfrc | 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:
|
terraform-credentials-enterprise:
|
||||||
name: 'Terraform Enterprise Credentials'
|
name: 'Terraform Enterprise Credentials'
|
||||||
|
|
@ -146,17 +139,10 @@ jobs:
|
||||||
cli_config_credentials_hostname: 'terraform.example.com'
|
cli_config_credentials_hostname: 'terraform.example.com'
|
||||||
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
cli_config_credentials_token: ${{ env.TF_CLOUD_API_TOKEN }}
|
||||||
|
|
||||||
- name: Validate Terraform Credentials (Windows)
|
- name: Validate Terraform Credentials
|
||||||
if: runner.os == 'Windows'
|
|
||||||
run: |
|
run: |
|
||||||
cat ${APPDATA}/terraform.rc | grep 'credentials "terraform.example.com"'
|
cat ${RUNNER_TEMP}/setup-terraform.tfrc | grep 'credentials "terraform.example.com"'
|
||||||
cat ${APPDATA}/terraform.rc | grep 'token = "${{ env.TF_CLOUD_API_TOKEN }}"'
|
cat ${RUNNER_TEMP}/setup-terraform.tfrc | 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:
|
terraform-credentials-none:
|
||||||
name: 'Terraform No Credentials'
|
name: 'Terraform No Credentials'
|
||||||
|
|
@ -171,15 +157,9 @@ jobs:
|
||||||
- name: Setup Terraform
|
- name: Setup Terraform
|
||||||
uses: ./
|
uses: ./
|
||||||
|
|
||||||
- name: Validate Terraform Credentials (Windows)
|
- name: Validate Teraform Credentials
|
||||||
if: runner.os == 'Windows'
|
|
||||||
run: |
|
run: |
|
||||||
[[ -f ${APPDATA}/terraform.rc ]] || exit 0
|
[[ -f ${RUNNER_TEMP}/setup-terraform.tfrc ]] || exit 0
|
||||||
|
|
||||||
- name: Validate Teraform Credentials (Linux & macOS)
|
|
||||||
if: runner.os != 'Windows'
|
|
||||||
run: |
|
|
||||||
[[ -f ${HOME}/.terraformrc ]] || exit 0
|
|
||||||
|
|
||||||
terraform-arguments:
|
terraform-arguments:
|
||||||
name: 'Terraform Arguments'
|
name: 'Terraform Arguments'
|
||||||
|
|
|
||||||
16
dist/index.js
vendored
16
dist/index.js
vendored
|
|
@ -109,15 +109,15 @@ credentials "${credentialsHostname}" {
|
||||||
}`.trim();
|
}`.trim();
|
||||||
// eslint-enable
|
// eslint-enable
|
||||||
|
|
||||||
// default to OS-specific path
|
// set or use the TF_CLI_CONFIG_FILE environment variable
|
||||||
let credsFile = osPlat === 'win32'
|
let credsFile = process.env.TF_CLI_CONFIG_FILE;
|
||||||
? `${process.env.APPDATA}/terraform.rc`
|
if (!credsFile) {
|
||||||
: `${process.env.HOME}/.terraformrc`;
|
credsFile = path.join(process.env.RUNNER_TEMP, 'setup-terraform.tfrc');
|
||||||
|
core.debug(`Default CLI config created as ${credsFile}`);
|
||||||
|
core.exportVariable('TF_CLI_CONFIG_FILE', credsFile);
|
||||||
|
}
|
||||||
|
|
||||||
// override with TF_CLI_CONFIG_FILE environment variable
|
// create containing folder in case it doesn't exist
|
||||||
credsFile = process.env.TF_CLI_CONFIG_FILE ? process.env.TF_CLI_CONFIG_FILE : credsFile;
|
|
||||||
|
|
||||||
// get containing folder
|
|
||||||
const credsFolder = path.dirname(credsFile);
|
const credsFolder = path.dirname(credsFile);
|
||||||
|
|
||||||
core.debug(`Creating ${credsFolder}`);
|
core.debug(`Creating ${credsFolder}`);
|
||||||
|
|
|
||||||
|
|
@ -103,15 +103,15 @@ credentials "${credentialsHostname}" {
|
||||||
}`.trim();
|
}`.trim();
|
||||||
// eslint-enable
|
// eslint-enable
|
||||||
|
|
||||||
// default to OS-specific path
|
// set or use the TF_CLI_CONFIG_FILE environment variable
|
||||||
let credsFile = osPlat === 'win32'
|
let credsFile = process.env.TF_CLI_CONFIG_FILE;
|
||||||
? `${process.env.APPDATA}/terraform.rc`
|
if (!credsFile) {
|
||||||
: `${process.env.HOME}/.terraformrc`;
|
credsFile = path.join(process.env.RUNNER_TEMP, 'setup-terraform.tfrc');
|
||||||
|
core.debug(`Default CLI config created as ${credsFile}`);
|
||||||
|
core.exportVariable('TF_CLI_CONFIG_FILE', credsFile);
|
||||||
|
}
|
||||||
|
|
||||||
// override with TF_CLI_CONFIG_FILE environment variable
|
// create containing folder in case it doesn't exist
|
||||||
credsFile = process.env.TF_CLI_CONFIG_FILE ? process.env.TF_CLI_CONFIG_FILE : credsFile;
|
|
||||||
|
|
||||||
// get containing folder
|
|
||||||
const credsFolder = path.dirname(credsFile);
|
const credsFolder = path.dirname(credsFile);
|
||||||
|
|
||||||
core.debug(`Creating ${credsFolder}`);
|
core.debug(`Creating ${credsFolder}`);
|
||||||
|
|
|
||||||
|
|
@ -28,18 +28,12 @@ const setup = require('../lib/setup-terraform');
|
||||||
// .fn(console.error);
|
// .fn(console.error);
|
||||||
|
|
||||||
describe('Setup Terraform', () => {
|
describe('Setup Terraform', () => {
|
||||||
const HOME = process.env.HOME;
|
|
||||||
const APPDATA = process.env.APPDATA;
|
|
||||||
|
|
||||||
beforeEach(() => {
|
beforeEach(() => {
|
||||||
process.env.HOME = '/tmp/asdf';
|
process.env.RUNNER_TEMP = '/tmp/asdf';
|
||||||
process.env.APPDATA = '/tmp/asdf';
|
|
||||||
});
|
});
|
||||||
|
|
||||||
afterEach(async () => {
|
afterEach(async () => {
|
||||||
await io.rmRF(process.env.HOME);
|
await io.rmRF(process.env.RUNNER_TEMP);
|
||||||
process.env.HOME = HOME;
|
|
||||||
process.env.APPDATA = APPDATA;
|
|
||||||
});
|
});
|
||||||
|
|
||||||
test('gets specific version and adds token and hostname on linux, amd64', async () => {
|
test('gets specific version and adds token and hostname on linux, amd64', async () => {
|
||||||
|
|
@ -78,8 +72,8 @@ describe('Setup Terraform', () => {
|
||||||
|
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -123,8 +117,8 @@ describe('Setup Terraform', () => {
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
|
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/terraform.rc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -166,8 +160,8 @@ describe('Setup Terraform', () => {
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
|
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -209,8 +203,8 @@ describe('Setup Terraform', () => {
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
|
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -251,8 +245,8 @@ describe('Setup Terraform', () => {
|
||||||
|
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -293,8 +287,8 @@ describe('Setup Terraform', () => {
|
||||||
|
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -335,8 +329,8 @@ describe('Setup Terraform', () => {
|
||||||
|
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -377,8 +371,8 @@ describe('Setup Terraform', () => {
|
||||||
|
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
@ -419,8 +413,8 @@ describe('Setup Terraform', () => {
|
||||||
|
|
||||||
// downloaded CLI has been added to path
|
// downloaded CLI has been added to path
|
||||||
expect(core.addPath).toHaveBeenCalled();
|
expect(core.addPath).toHaveBeenCalled();
|
||||||
// expect credentials are in ${HOME}.terraformrc
|
// expect credentials are in ${RUNNER_TEMP}/setup-terraform.tfrc
|
||||||
const creds = await fs.readFile(`${process.env.HOME}/.terraformrc`, { encoding: 'utf8' });
|
const creds = await fs.readFile(`${process.env.RUNNER_TEMP}/setup-terraform.tfrc`, { encoding: 'utf8' });
|
||||||
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsHostname)).toBeGreaterThan(-1);
|
||||||
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
expect(creds.indexOf(credentialsToken)).toBeGreaterThan(-1);
|
||||||
});
|
});
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue