Hi,
I'm using a number of provisioners to walk through:
- copying data in to a folder locally (data/) using a local-exec
- create a new directory at /srv/puppet on a Terraform-instantiated EC2 instance using a remote-exec
- copy the entire local data/ directory to /srv/puppet remotely using a remote-exec
- delete the data/ directory locally to clean things up
Here are the provisioners I'm using, in order:
provisioner "local-exec" {
command = "sudo mkdir -p data/ && sudo rsync -av ../* data/ --exclude '.*' --exclude 'vendor/' --exclude '*.lock'"
provisioner "remote-exec" {
inline = "sudo mkdir -p /srv/puppet"
destination = "/srv/puppet"
provisioner "local-exec" {
command = "sudo rm -rf data/*"
My connection block specifies the use of the 'ubuntu' user, since that's the default user in the AMIs I'm using to instantiate my EC2 instance. The first two provisioners work flawlessly, however the file provisioner breaks down when it tries to create directories under /srv/puppet remotely, claiming 'permission denied'.
I've played for a few minutes and worked out that it would work if I were able to preface the underlying SCP command that's occurring with `sudo`. Using the previous remote-exec to add the `ubuntu` user to the `sudo` group (`sudo adduser ubuntu sudo`) complains that the `ubuntu` user is already in the sudo group, so that doesn't help me much.
One idea I had was to create a user in a remote-exec before the file provisioner occurs, but that's not really that nice on a number of fronts. Ideally, there would be a way to ensure that the file provisioner runs with sudo privileges, or similar.
I'd be grateful for any pointers or advice on this one!
Cheers,
Andrew