Terraform: Feature request: Show what commands terraform local-exec/remote-exec inline is running or add verbose mode for that

Created on 28 Jun 2017  路  3Comments  路  Source: hashicorp/terraform

I would like to build automation tools for developers which are not that familiar with many linux commands. I feel that most automation tries to hide away how it works and this makes it harder for newcomers to understand what's going on. IMO Just seeing the familiar commands in the output would help them understand how things are happening in the background.

It would be awesome if terraform would have a verbose = true option for remote-exec which would show what command is currently running.

If a command fails this makes it much easier to retry it too.

I know that I can do this by installing a bash script and running it instead but that requires one more step for the provisioner and then I would need to use template. I want this to be really easily approachable.

I'm happy to hear your thoughts.

Terraform Version

$ terraform -v
Terraform v0.9.9

Terraform Configuration Files

Here's an example setup which could show what it is doing.

resource "digitalocean_droplet" "test" {
  image     = "ubuntu-16-04-x64"
  name      = "test"
  region    = "fra1"
  size      = "512mb"
  ssh_keys  = [ "${digitalocean_ssh_key.test.id}" ]

  provisioner "remote-exec" {
    inline = [
      # Update all packages and remove unneeded packages
      "apt-get upgrade --yes",
      "apt-get autoremove --yes",

      # Enable ntp
      "sudo timedatectl set-ntp on"
    ]
  }
}
enhancement provisioneremote-exec

Most helpful comment

I have an alternative use case for this feature:

I'm running a local-exec command to launch another cli tool. This command can run quite long (10+ minutes). Normally it is quite verbose, but terraform seems to suppress stdout. It would be great to see the progress of this instead.

All 3 comments

Hi @onnimonni!

This seems like a reasonable idea! In general the provisioner output is already rather verbose so we've been disinclined to make it super-long, but we could probably have an opt-in here.

I wonder though if we could already make this work without any changes. Internally this provisioner is itself creating a shell script, uploading it to the server, and running it. In principle, therefore, it should work to add set -x to the start of the script (assuming that the shell is indeed bash) and then bash itself would echo out each command. Perhaps that can get you what you want with Terraform as it exists today? (I'm afraid I didn't get a chance to try it yet, so I'm not 100% sure it will work as expected.)

@apparentlymart thanks for that suggestion and it works just fine for everything else but pipes:

provisioner "remote-exec" {
    inline = [
      # Show all commands before they are run
      "set -x",

      # Enable non-interactive setup for dokku
      "echo 'dokku dokku/vhost_enable boolean true' | debconf-set-selections",
      # More steps here
      ...
      ]
}

Provides output:

digitalocean_droplet.dokku: Still creating... (50s elapsed)
digitalocean_droplet.dokku (remote-exec): Connected!
digitalocean_droplet.dokku (remote-exec): + + debconf-set-selections
digitalocean_droplet.dokku (remote-exec): echo dokku dokku/vhost_enable boolean true

I have an alternative use case for this feature:

I'm running a local-exec command to launch another cli tool. This command can run quite long (10+ minutes). Normally it is quite verbose, but terraform seems to suppress stdout. It would be great to see the progress of this instead.

Was this page helpful?
0 / 5 - 0 ratings