I successfully created an Azure Ubuntu VM in Terraform that runs a remote-exec provisioner after the creation has been completed. Within this remote-exec block I create user accounts that can be accessed via SSH. Since I have the public keys, I also want to add each public key to their respective authorized_keys file. My approach is this:
"sudo adduser --quiet --disabled-password --shell /bin/bash --home /home/username--gecos \"Firstname Lastname\" username", "sudo mkdir ~/../username/.ssh", "sudo chmod 700 ~/../username/.ssh/", "sudo touch ~/../username/.ssh/authorized_keys", "sudo echo ${file("userKeys/username.pub")} > ~/../username/.ssh/authorized_keys", "sudo chmod 600 ~/../username/.ssh/authorized_keys", "sudo chown -R username.username ~/../username/"
Unfortunately, this causes Terraform to crash after applying, probably due to the double quotes within file. So I also tried
"echo ${file("userKeys/username.pub")}"
which works perfectly fine.
At this point I don't really know how to solve this problem. Maybe using file() within remote-exec is the wrong approach anyway?
https://stackoverflow.com/questions/67405509/use-file-in-remote-exec May 06, 2021 at 12:46AM
没有评论:
发表评论