bc3*_*ech 4 terraform github-actions
我有一个使用 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
Run Code Online (Sandbox Code Playgroud)
然后将其放入工作工件中
- name: Upload output file
uses: actions/upload-artifact@v2
with:
name: terraform-output
path: terraform/tfoutput.json
Run Code Online (Sandbox Code Playgroud)
内容结果文件如下所示:
[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
Run Code Online (Sandbox Code Playgroud)
当然,这意味着它绝对不像Terraform 的 JSON 输出那样是机器可读的。
我还没有找到任何方法来删除所有无关的垃圾。值得注意的是,在 Azure DevOps 中,这一工作流程的执行完全符合人们的预期。
我采取的方法是将所有内容放入一项作业中(以避免重定向输出和传递工件),然后使用terraform output | jq -r ...将 terraform 的输出获取到我的 jq 语句中以提取值,但它仍然不起作用。由于某种原因,该命令的输出似乎确实是垃圾。
不确定这是否是我可以解决的问题,是 terraform 操作中的错误,还是一般 GH 操作中的错误。
另外,我应该在哪里提交 GH Actions 的错误???
bc3*_*ech 12
解决方案是添加terraform_wrapper: false到您的设置 Terraform 步骤:
- name: Setup terraform\n uses: hashicorp/setup-terraform@v1\n with:\n terraform_version: ${{ env.TERRAFORM_VERSION }}\n terraform_wrapper: false\nRun Code Online (Sandbox Code Playgroud)\n因为默认情况下,Terraform Action 会将其所有输出包装在这个垃圾中。\xe2\x80\x8d\xe2\x99\x82\xef\xb8\x8f
\n| 归档时间: |
|
| 查看次数: |
2424 次 |
| 最近记录: |