Last active
November 7, 2017 11:11
-
-
Save michaelgrosser/35c10eeddc78b66fb2f1831c1d687f93 to your computer and use it in GitHub Desktop.
Share Host AWS Credentials with Vagrant Guest
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# Copy AWS credentials and config from host to guest | |
$aws_credentials_path = ENV['HOME'] + "/.aws/credentials" | |
$aws_config_path = ENV['HOME'] + "/.aws/config" | |
if File.file?($aws_credentials_path) && File.file?($aws_config_path) then | |
config.vm.provision "shell", | |
inline: "mkdir -p /root/.aws", | |
privileged: true | |
config.vm.provision "shell", | |
inline: "mkdir -p /home/nginx/.aws", | |
privileged: true | |
config.vm.provision "file", | |
source: $aws_credentials_path, | |
destination: "/home/vagrant/.aws/credentials" | |
config.vm.provision "shell", | |
inline: "/bin/cp -f /home/vagrant/.aws/credentials /root/.aws/credentials", | |
privileged: true | |
config.vm.provision "shell", | |
inline: "/bin/cp -f /home/vagrant/.aws/credentials /home/nginx/.aws/credentials", | |
privileged: true | |
config.vm.provision "shell", | |
inline: "chown nginx:nginx /home/nginx/.aws/credentials && chmod 0644 /home/nginx/.aws/credentials", | |
privileged: true | |
config.vm.provision "file", | |
source: $aws_config_path, | |
destination: "/home/vagrant/.aws/config" | |
config.vm.provision "shell", | |
inline: "/bin/cp -f /home/vagrant/.aws/config /root/.aws/config", | |
privileged: true | |
config.vm.provision "shell", | |
inline: "/bin/cp -f /home/vagrant/.aws/config /home/nginx/.aws/config", | |
privileged: true | |
config.vm.provision "shell", | |
inline: "chown nginx:nginx /home/nginx/.aws/config && chmod 0644 /home/nginx/.aws/config", | |
privileged: true | |
else | |
puts "AWS Credentials do not exist on host!" | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment