From 66abae5f713fb5e48181928bff552daa4fc62c3c Mon Sep 17 00:00:00 2001 From: Malte Janduda Date: Fri, 27 Jun 2014 17:42:52 +0200 Subject: [PATCH 1/2] vagrant aws: adding associate public ip functionality --- README.md | 15 ++++++++------- aws/Vagrantfile | 9 ++++++--- 2 files changed, 14 insertions(+), 10 deletions(-) diff --git a/README.md b/README.md index 87265e90..e2668677 100644 --- a/README.md +++ b/README.md @@ -176,13 +176,14 @@ These rules are cleared on restart. They can be saved and configured to be reloa |Name|Description|Default| |---|---|---| -|BOSH_AWS_ACCESS_KEY_ID |AWS access key ID | | -|BOSH_AWS_SECRET_ACCESS_KEY |AWS secret access key | | -|BOSH_LITE_KEYPAIR |AWS keypair name |bosh| -|BOSH_LITE_NAME |AWS instance name |Vagrant| -|BOSH_LITE_SECURITY_GROUP |AWS security group |inception| -|BOSH_LITE_PRIVATE_KEY |path to private key matching keypair |~/.ssh/id_rsa_bosh| -|[VPC only] BOSH_LITE_SUBNET_ID |AWS VPC subnet ID | | +|BOSH_AWS_ACCESS_KEY_ID |AWS access key ID | | +|BOSH_AWS_SECRET_ACCESS_KEY |AWS secret access key | | +|BOSH_LITE_KEYPAIR |AWS keypair name |bosh| +|BOSH_LITE_NAME |AWS instance name |Vagrant| +|BOSH_LITE_SECURITY_GROUP |AWS security group |inception| +|BOSH_LITE_PRIVATE_KEY |path to private key matching keypair |~/.ssh/id_rsa_bosh| +|[VPC only] BOSH_LITE_SUBNET_ID |AWS VPC subnet ID | | +|[VPC only] BOSH_LITE_ASSOCIATE_PUBLIC_IP |Associate a public ip to the VPC instance | false | ## Restart the Director diff --git a/aws/Vagrantfile b/aws/Vagrantfile index 0308b0eb..99dec686 100644 --- a/aws/Vagrantfile +++ b/aws/Vagrantfile @@ -15,6 +15,8 @@ Vagrant.configure('2') do |config| # better error messages from Hash.fetch env = ENV.to_hash + associate_public_ip = ( env.fetch('BOSH_LITE_ASSOCIATE_PUBLIC_IP') =~ (/^(true|t|yes|y|1)$/i) ) if env.include?('BOSH_LITE_ASSOCIATE_PUBLIC_IP') + config.vm.box = 'dummy' config.vm.box_url = 'https://github.com/mitchellh/vagrant-aws/blob/master/dummy.box?raw=true' config.vm.provider :aws do |aws, override| @@ -37,12 +39,13 @@ Vagrant.configure('2') do |config| aws.security_groups = [ env.fetch('BOSH_LITE_SECURITY_GROUP', 'inception') ] aws.subnet_id = env.fetch('BOSH_LITE_SUBNET_ID') if env.include?('BOSH_LITE_SUBNET_ID') + + aws.associate_public_ip = associate_public_ip override.ssh.username = 'ubuntu' override.ssh.private_key_path = env.fetch('BOSH_LITE_PRIVATE_KEY', '~/.ssh/id_rsa_bosh') end - - endpoint = env.include?('BOSH_LITE_SUBNET_ID') ? 'local-ipv4' : 'public-ipv4' + endpoint = ( associate_public_ip or not env.include?('BOSH_LITE_SUBNET_ID') ) ? 'public-ipv4' : 'local-ipv4' PORT_FORWARDING = <<-IP_SCRIPT ip=`curl -s http://169.254.169.254/latest/meta-data/#{endpoint}` @@ -56,4 +59,4 @@ IP_SCRIPT config.vm.provision :shell, :inline => PORT_FORWARDING -end \ No newline at end of file +end From 1ad14f9a1efcb2a7840c923a8b959b6e7dfb9388 Mon Sep 17 00:00:00 2001 From: Malte Janduda Date: Mon, 30 Jun 2014 14:40:10 +0200 Subject: [PATCH 2/2] fixing environment variable evaluation --- aws/Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/aws/Vagrantfile b/aws/Vagrantfile index 99dec686..776408ed 100644 --- a/aws/Vagrantfile +++ b/aws/Vagrantfile @@ -15,7 +15,7 @@ Vagrant.configure('2') do |config| # better error messages from Hash.fetch env = ENV.to_hash - associate_public_ip = ( env.fetch('BOSH_LITE_ASSOCIATE_PUBLIC_IP') =~ (/^(true|t|yes|y|1)$/i) ) if env.include?('BOSH_LITE_ASSOCIATE_PUBLIC_IP') + associate_public_ip = ( ['true','1'].include? env.fetch('BOSH_LITE_ASSOCIATE_PUBLIC_IP').downcase ) if env.include?('BOSH_LITE_ASSOCIATE_PUBLIC_IP') config.vm.box = 'dummy' config.vm.box_url = 'https://github.com/mitchellh/vagrant-aws/blob/master/dummy.box?raw=true'