Created
March 26, 2018 00:18
-
-
Save dehowell/db3f5500fe4fb09b0c1973a3443b7131 to your computer and use it in GitHub Desktop.
Getting Serverless variables from terraform state
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const exec = require('child_process').exec; | |
function terraformOutput(name, tfModule) { | |
let mod = tfModule != undefined ? `-module ${tfModule}` : ''; | |
let cmd = `terraform output -json ${mod}`; | |
let outputs = new Promise((resolve, reject) => { | |
exec(cmd, {'cwd': 'infrastructure'}, | |
(error, stdout, stderr) => { | |
if (error) reject(error); | |
else resolve(stdout); | |
} | |
) | |
}); | |
return outputs | |
.then(JSON.parse) | |
.then(d => d[name].value); | |
} | |
module.exports = () => { | |
return { | |
web_bucket: terraformOutput('web_bucket', 'hosting'), | |
publisher_role: terraformOutput('publisher_role') | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
custom: ${file(./config.js)} | |
# then refer to the variables with ${self:custom.web_bucket} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment