【问题标题】:Run command automatically after terraform applyterraform apply 后自动运行命令
【发布时间】:2020-04-16 08:46:40
【问题描述】:

terraform apply成功后如何运行特定的终端命令?

更具体地说,我想将输出变量保存到某个 S3 存储桶中(状态已经在 S3 中,但它包含敏感输出,因此存储桶具有受限访问权限),虽然此功能请求 is still open,但我正在使用此解决方法:

terraform apply && terraform output -json | aws s3 cp - s3://bucket/output.json

但是可以强制 terraform 自动调用这个命令吗?

【问题讨论】:

  • 如何运行 Terraform?通过 CI?本地?你是使用包装脚本还是直接调用 Terraform 命令?
  • 我使用普通的 CLI。本质上,我有一个 Makefile 和命令 terraform apply && terraform output ... 用于部署目标。可以,但不优雅。它还增加了构建时间,因为当状态位于 S3 存储桶中时,terraform 输出需要相当长的时间。

标签: amazon-web-services amazon-s3 terraform


【解决方案1】:

虽然它可能看起来像是更多的前期工作,并且不完全使用 terraform 上传到 s3,但我会使用一个工具,比如 Jenkins,它同时具有 terraform 和 AWS 插件。然后,您可以不断添加到您的管道并查看过去的运行情况。

见: https://wiki.jenkins.io/display/JENKINS/Terraform+Plugin https://wiki.jenkins.io/display/JENKINS/S3+Plugin

您可以配置 Jenkins 来运行 terraform,然后您应该能够使用 s3 插件上传到 AWS。

【讨论】:

    猜你喜欢
    • 2022-12-19
    • 2019-06-03
    • 2020-05-18
    • 2021-09-07
    • 2020-10-04
    • 2018-11-21
    • 2021-04-10
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多