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

Viewed 662

I wanted to be able to add a customised comment like 'Please update xxx manually in AWS console and re-run Terraform apply. Ignore this message if not applicable'.

Something like this, is there a way to configure this in Terraform script?

1 Answers

You could use outputs in the root module which would then be outputted to the terminal when you run terraform apply.

As a short example:

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"
}

Will output the following on creation with 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"

If you rerun terraform apply then you'll see this:

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"
Related