有没有办法为 Teraform 添加注释以显示在“Terraform apply”日志末尾?

waw*_*awa 7 terraform terraform-provider-aws terraform0.12+

我希望能够添加自定义注释,例如“请在 AWS 控制台中手动更新 xxx 并重新运行 Terraform apply”。如果不适用,请忽略此消息。

像这样的东西,有没有办法在 Terraform 脚本中配置它?

yda*_*coR 6

您可以使用根模块中的输出,然后在运行时将其输出到终端terraform apply

作为一个简短的例子:

resource "null_resource" "foo" {

}

output "next_steps" {
  value = "Please update xxx manually in AWS console and re-run Terraform apply. Ignore this message if not applicable"
}
Run Code Online (Sandbox Code Playgroud)

将在创建时输出以下内容terraform apply

An execution plan has been generated and is shown below.
Resource actions are indicated with the following symbols:
  + create

Terraform will perform the following actions:

  # null_resource.foo will be created
  + resource "null_resource" "foo" {
      + id = (known after apply)
    }

Plan: 1 to add, 0 to change, 0 to destroy.

Changes to Outputs:
  + next_steps = "Please update xxx manually in AWS console and re-run Terraform apply. Ignore this message if not applicable"

Do you want to perform these actions?
  Terraform will perform the actions described above.
  Only 'yes' will be accepted to approve.

  Enter a value: yes

null_resource.foo: Creating...
null_resource.foo: Creation complete after 0s [id=347317219666477450]

Apply complete! Resources: 1 added, 0 changed, 0 destroyed.

Outputs:

next_steps = "Please update xxx manually in AWS console and re-run Terraform apply. Ignore this message if not applicable"
Run Code Online (Sandbox Code Playgroud)

如果您重新运行terraform apply,您将看到以下内容:

null_resource.foo: Refreshing state... [id=347317219666477450]

Apply complete! Resources: 0 added, 0 changed, 0 destroyed.

Outputs:

next_steps = "Please update xxx manually in AWS console and re-run Terraform apply. Ignore this message if not applicable"
Run Code Online (Sandbox Code Playgroud)