setup-terraform/dist/index.js

1 line
115 KiB
JavaScript
Raw Normal View History

2020-10-04 09:40:55 -04:00
module.exports=(()=>{var __webpack_modules__={2932:(e,t,r)=>{const n=r(2186);const s=r(3117);(async()=>{try{await s()}catch(e){n.setFailed(e.message)}})()},3117:(e,t,r)=>{const n=r(5747).promises;const s=r(2087);const o=r(5622);const i=r(2186);const a=r(7784);const c=r(7436);const l=r(467);const u=r(1383);function findLatest(e){i.debug("Parsing version list for latest version");let t="0.0.0";for(const r in e.versions){if(u.prerelease(r)!==null){continue}t=u.gt(r,t)?r:t}i.info(`Latest version is ${t}`);return e.versions[t]}function findSpecific(e,t){i.debug(`Parsing version list for version ${t}`);return e.versions[t]}function findLatestMatchingSpecification(e,t){i.debug(`Parsing version list for latest matching specification ${t}`);const r=[];for(const t in e.versions){r.push(t)}const n=u.maxSatisfying(r,t);if(!n){throw new Error(`Could not find Terraform version matching ${t} in version list`)}i.info(`Latest version satisfying ${t} is ${n}`);return e.versions[n]}async function downloadMetadata(){i.debug("Downloading version metadata");return l("https://releases.hashicorp.com/terraform/index.json").then(e=>e.json()).catch(e=>{i.setFailed(`Failed to fetch version metadata. ${e}`)})}function mapArch(e){const t={x32:"386",x64:"amd64"};return t[e]||e}function mapOS(e){const t={win32:"windows"};return t[e]||e}function getBuild(e,t,r){i.debug(`Getting build for Terraform version ${e.version}, os ${t}, and arch ${r}`);const n=e.builds.length&&e.builds.find(e=>e.arch===mapArch(r)&&e.os===mapOS(t));if(!n){throw new Error(`Terraform version ${e.version} not available for ${t} and ${r}`)}return n}async function downloadCLI(e){i.debug(`Downloading Terraform CLI from ${e}`);const t=await a.downloadTool(e);i.debug("Extracting Terraform CLI zip file");const r=await a.extractZip(t);i.debug(`Terraform CLI path is ${r}.`);if(!t||!r){throw new Error(`Unable to download Terraform from ${e}`)}return r}async function installWrapper(e){let t,n;const a=s.platform().startsWith("win")?".exe":"";try{t=[e,`terraform${a}`].join(o.sep);n=[e,`terraform-bin${a}`].join(o.sep);i.debug(`Moving ${t} to ${n}.`);await c.mv(t,n)}catch(e){i.error(`Unable to move ${t} to ${n}.`);throw e}try{t=r.ab+"index1.js";n=[e,"terraform"].join(o.sep);i.debug(`Copying ${t} to ${n}.`);await c.cp(r.ab+"index1.js",n)}catch(e){i.error(`Unable to copy ${t} to ${n}.`);throw e}i.exportVariable("TERRAFORM_CLI_PATH",e)}async function addCredentials(e,t,r){const s=`\ncredentials "${e}" {\n token = "${t}"\n}`.trim();let a=r==="win32"?`${process.env.APPDATA}/terraform.rc`:`${process.env.HOME}/.terraformrc`;a=process.env.TF_CLI_CONFIG_FILE?process.env.TF_CLI_CONFIG_FILE:a;const l=o.dirname(a);i.debug(`Creating ${l}`);await c.mkdirP(l);i.debug(`Adding credentials to ${a}`);await n.writeFile(a,s)}async function run(){try{const e=i.getInput("terraform_version");const t=i.getInput("cli_config_credentials_hostname");const r=i.getInput("cli_config_credentials_token");const n=i.getInput("terraform_wrapper")==="true";const o=s.platform();const a=s.arch();const c=await downloadMetadata();const l=findSpecific(c,e);const u=e.toLowerCase()==="latest"?findLatest(c):l||findLatestMatchingSpecification(c,e);if(u){const e=getBuild(u,o,a);const s=await downloadCLI(e.url);if(n){await installWrapper(s)}i.addPath(s);if(t&&r){await addCredentials(t,r,o)}return u}else{i.setFailed(`Could not find Terraform version ${e} in version list`)}}catch(e){i.error(e);throw e}}e.exports=run},7351:function(e,t,r){"use strict";var n=this&&this.__importStar||function(e){if(e&&e.__esModule)return e;var t={};if(e!=null)for(var r in e)if(Object.hasOwnProperty.call(e,r))t[r]=e[r];t["default"]=e;return t};Object.defineProperty(t,"__esModule",{value:true});const s=n(r(2087));const o=r(5278);function issueCommand(e,t,r){const n=new Command(e,t,r);process.stdout.write(n.toString()+s.EOL)}t.issueCommand=issueCommand;function issue(e,t=""){issueCommand(e,{},t)}t.issue=issue;const i="::";class Command{constructor(e,t,r){if(!e){e="missing.command"}this.command=e;this.properties=t;this.message=r}toString(){let e=i+this.command;if(this