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

Is there a way to add comments for Teraform to display at the end of 'Terraform apply' logs?

我希望能够添加自定义评论,例如 'Please update xxx manually in AWS console and re-run Terraform apply. Ignore this message if not applicable'。

类似这样的事情,有没有办法在 Terraform 脚本中配置它?

您可以在根模块中使用 outputs 然后当您 运行 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"
}

将在使用 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"

如果你重新运行 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"