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



我希望能够添加一个自定义评论,比如"请在AWS控制台中手动更新xxx,然后重新运行Terraform apply。"。忽略此消息(如果不适用(。

像这样的东西,有没有一种方法可以在Terraform脚本中配置它?

您可以在根模块中使用输出,然后在运行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"

最新更新