loafoe/terraform-provider-ssh

Feature request: allow optional params in file block to set owner, group, and permissions for the file

Closed this issue · 3 comments

It would be very convenient if we could optionally specify the owner, group, and permissions for a file in the file block rather than using extra commands. These are very common operations and it is easy to mess up the path in the commands while if it were simply additional params in the file block the path is already provided.

For example, currently I would do this where I need to make sure to use the same path in the destination and in the commands.

resource "ssh_resource" "myhost-interactive-finish-install-script" {
  host = '1.2.3.4'
  user = "root"
  private_key = file("/Users/myuser/.ssh/id_rsa")

  file {
    content = data.local_file.interactive-finish-install-script.content
    destination = "/root/finish-install.sh"
  }

  commands = [
   "chown myuser:mygroup /root/finish-install.sh",
   "chmod 700 /root/finish-install.sh"
  ]
}

and it would be very nice and less error prone to just be able to do this. If provided the optional owner, group, and permissions would be used to set those file attributes on the destination.

resource "ssh_resource" "myhost-interactive-finish-install-script" {
  host = '1.2.3.4'
  user = "root"
  private_key = file("/Users/myuser/.ssh/id_rsa")

  file {
    content = data.local_file.interactive-finish-install-script.content
    destination = "/root/finish-install.sh"
    owner = "myuser"
    group = "mygroup"
    permissions = "700"
  }
}

Excellent idea! I will see if I can implement this in the next coming days

Implemented in v0.2.0

Fantastic!