我有一个使用 Terraform 进行部署的 GitHub Actions 工作流程。
当 Terraform 完成后,我想获取 Terraform 输出并将其发送到工作流程中的下一个作业,以便可以提取和使用各个部分。具体来说,我的 Terraform 部署一个 Azure Function,然后输出函数应用名称。然后,它被用来告诉下一个作业在哪里部署函数代码。
但是,当我重定向输出时terraform output
像这样:
- name: save tf output
run: terraform output -json > tfoutput.json
shell: bash
working-directory: terraform
然后将其放入工作工件中
- name: Upload output file
uses: actions/upload-artifact@v2
with:
name: terraform-output
path: terraform/tfoutput.json
内容结果文件如下所示:
[command]/home/runner/work/_temp/fb419afc-033e-4058-b5f3-c44b90cb0bd0/terraform-bin output -json
{
"functionappname": {
"sensitive": false,
"type": "string",
"value": "telemetry-function"
}
}
::debug::Terraform exited with code 0.
::debug::stdout: {%0A "functionappname": {%0A "sensitive": false,%0A "type": "string",%0A "value": "telemetry-function"%0A }%0A}%0A
::debug::stderr:
::debug::exitcode: 0
::set-output name=stdout::{%0A "functionappname": {%0A "sensitive": false,%0A "type": "string",%0A "value": "telemetry-function"%0A }%0A}%0A
::set-output name=stderr::
::set-output name=exitcode::0
这当然意味着,这绝对是notTerraform 的 JSON 输出应该是机器可读的。
我还没有找到任何方法来删除所有无关的垃圾。值得注意的是,在 Azure DevOps 中,这一工作流程的执行完全符合人们的预期。
我采取的方法是将所有内容放入一项作业中(以避免重定向输出和传递工件),然后使用terraform output | jq -r ...
将 terraform 的输出获取到我的 jq 语句中以提取值及其still不起作用。由于某种原因,该命令的输出似乎确实是垃圾。
不确定这是否is我可以解决的问题,terraform 操作中的错误,或者一般 GH 操作中的错误。
另外,我应该在哪里提交 GH Actions 的错误???