Class: VagrantPlugins::AWS::Config
- Inherits:
-
Object
- Object
- VagrantPlugins::AWS::Config
- Defined in:
- lib/vagrant-aws/config.rb
Instance Attribute Summary collapse
-
#access_key_id ⇒ String
The access key ID for accessing AWS.
-
#ami ⇒ String
The ID of the AMI to use.
-
#associate_public_ip ⇒ Boolean
Assigning a public IP address in a VPC.
-
#availability_zone ⇒ String
The availability zone to launch the instance into.
-
#aws_dir ⇒ String
The directory where AWS files are stored (usually $HOME/.aws).
-
#aws_profile ⇒ String
The selected AWS named profile (as defined in $HOME/.aws/* files).
-
#block_device_mapping ⇒ Array<Hash>
Block device mappings.
-
#ebs_optimized ⇒ Boolean
EBS optimized instance.
-
#elastic_ip ⇒ String
If true, acquire and attach an elastic IP address.
-
#elb ⇒ String
The name of ELB, which an instance should be attached to.
-
#endpoint ⇒ String
The EC2 endpoint to connect to.
-
#iam_instance_profile_arn ⇒ String
The Amazon resource name (ARN) of the IAM Instance Profile to associate with the instance.
-
#iam_instance_profile_name ⇒ String
The name of the IAM Instance Profile to associate with the instance.
-
#instance_check_interval ⇒ Fixnum
The interval to wait for checking an instance’s state.
-
#instance_package_timeout ⇒ Fixnum
The timeout to wait for an instance to successfully burn into an AMI.
-
#instance_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
-
#instance_type ⇒ String
The type of instance to launch, such as “m3.medium”.
-
#kernel_id ⇒ String
Kernel Id.
-
#keypair_name ⇒ String
The name of the keypair to use.
-
#monitoring ⇒ Boolean
Enables Monitoring.
-
#package_tags ⇒ Hash<String, String>
The tags for the AMI generated with package.
-
#private_ip_address ⇒ String
The private IP address to give this machine (VPC).
-
#region ⇒ String
The name of the AWS region in which to create the instance.
-
#secret_access_key ⇒ String
The secret access key for accessing AWS.
-
#security_groups ⇒ Array<String>
The security groups to set on the instance.
-
#session_token ⇒ String
The token associated with the key for accessing AWS.
-
#source_dest_check ⇒ Boolean
Source Destination check.
-
#spot_instance ⇒ Boolean
Launch as spot instance.
-
#spot_max_price ⇒ String
Spot request max price.
-
#spot_price_product_description ⇒ String
The product description for the spot price history.
-
#spot_valid_until ⇒ Time
Spot request validity.
-
#ssh_host_attribute ⇒ Symbol
Specifies which address to connect to with ssh Must be one of: - :public_ip_address - :dns_name - :private_ip_address This attribute also accepts an array of symbols.
-
#subnet_id ⇒ String
The subnet ID to launch the machine into (VPC).
-
#tags ⇒ Hash<String, String>
The tags for the machine.
-
#tenancy ⇒ String
The tenancy of the instance in a VPC.
-
#terminate_on_shutdown ⇒ bool
Indicates whether an instance stops or terminates when you initiate shutdown from the instance.
-
#unregister_elb_from_az ⇒ Boolean
Disable unregisering ELB’s from AZ - useful in case of not using default VPC.
-
#use_iam_profile ⇒ Boolean
Use IAM Instance Role for authentication to AWS instead of an explicit access_id and secret_access_key.
-
#user_data ⇒ String
The user data string.
-
#version ⇒ String
The version of the AWS api to use.
Instance Method Summary collapse
- #finalize! ⇒ Object
-
#get_region_config(name) ⇒ Object
This gets the configuration for a specific region.
-
#initialize(region_specific = false) ⇒ Config
constructor
A new instance of Config.
-
#merge(other) ⇒ Object
——————————————————————- Internal methods.
-
#region_config(region, attributes = nil) {|config| ... } ⇒ Object
Allows region-specific overrides of any of the settings on this configuration object.
- #validate(machine) ⇒ Object
Constructor Details
#initialize(region_specific = false) ⇒ Config
Returns a new instance of Config.
219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 |
# File 'lib/vagrant-aws/config.rb', line 219 def initialize(region_specific=false) @access_key_id = UNSET_VALUE @ami = UNSET_VALUE @availability_zone = UNSET_VALUE @instance_check_interval = UNSET_VALUE @instance_ready_timeout = UNSET_VALUE @instance_package_timeout = UNSET_VALUE @instance_type = UNSET_VALUE @keypair_name = UNSET_VALUE @private_ip_address = UNSET_VALUE @region = UNSET_VALUE @endpoint = UNSET_VALUE @version = UNSET_VALUE @secret_access_key = UNSET_VALUE @session_token = UNSET_VALUE @security_groups = UNSET_VALUE @subnet_id = UNSET_VALUE @tags = {} @package_tags = {} @user_data = UNSET_VALUE @use_iam_profile = UNSET_VALUE @block_device_mapping = [] @elastic_ip = UNSET_VALUE @iam_instance_profile_arn = UNSET_VALUE @iam_instance_profile_name = UNSET_VALUE @terminate_on_shutdown = UNSET_VALUE @ssh_host_attribute = UNSET_VALUE @monitoring = UNSET_VALUE @ebs_optimized = UNSET_VALUE @source_dest_check = UNSET_VALUE @associate_public_ip = UNSET_VALUE @elb = UNSET_VALUE @unregister_elb_from_az = UNSET_VALUE @kernel_id = UNSET_VALUE @tenancy = UNSET_VALUE @aws_dir = UNSET_VALUE @aws_profile = UNSET_VALUE @spot_instance = UNSET_VALUE @spot_max_price = UNSET_VALUE @spot_valid_until = UNSET_VALUE # Internal state (prefix with __ so they aren't automatically # merged) @__compiled_region_configs = {} @__finalized = false @__region_config = {} @__region_specific = region_specific end |
Instance Attribute Details
#access_key_id ⇒ String
The access key ID for accessing AWS.
10 11 12 |
# File 'lib/vagrant-aws/config.rb', line 10 def access_key_id @access_key_id end |
#ami ⇒ String
The ID of the AMI to use.
15 16 17 |
# File 'lib/vagrant-aws/config.rb', line 15 def ami @ami end |
#associate_public_ip ⇒ Boolean
Assigning a public IP address in a VPC
166 167 168 |
# File 'lib/vagrant-aws/config.rb', line 166 def associate_public_ip @associate_public_ip end |
#availability_zone ⇒ String
The availability zone to launch the instance into. If nil, it will use the default for your account.
21 22 23 |
# File 'lib/vagrant-aws/config.rb', line 21 def availability_zone @availability_zone end |
#aws_dir ⇒ String
The directory where AWS files are stored (usually $HOME/.aws)
192 193 194 |
# File 'lib/vagrant-aws/config.rb', line 192 def aws_dir @aws_dir end |
#aws_profile ⇒ String
The selected AWS named profile (as defined in $HOME/.aws/* files)
197 198 199 |
# File 'lib/vagrant-aws/config.rb', line 197 def aws_profile @aws_profile end |
#block_device_mapping ⇒ Array<Hash>
Block device mappings
131 132 133 |
# File 'lib/vagrant-aws/config.rb', line 131 def block_device_mapping @block_device_mapping end |
#ebs_optimized ⇒ Boolean
EBS optimized instance
156 157 158 |
# File 'lib/vagrant-aws/config.rb', line 156 def ebs_optimized @ebs_optimized end |
#elastic_ip ⇒ String
If true, acquire and attach an elastic IP address. If set to an IP address, assign to the instance.
57 58 59 |
# File 'lib/vagrant-aws/config.rb', line 57 def elastic_ip @elastic_ip end |
#elb ⇒ String
The name of ELB, which an instance should be attached to
172 173 174 |
# File 'lib/vagrant-aws/config.rb', line 172 def elb @elb end |
#endpoint ⇒ String
The EC2 endpoint to connect to
67 68 69 |
# File 'lib/vagrant-aws/config.rb', line 67 def endpoint @endpoint end |
#iam_instance_profile_arn ⇒ String
The Amazon resource name (ARN) of the IAM Instance Profile to associate with the instance.
94 95 96 |
# File 'lib/vagrant-aws/config.rb', line 94 def iam_instance_profile_arn @iam_instance_profile_arn end |
#iam_instance_profile_name ⇒ String
The name of the IAM Instance Profile to associate with the instance.
100 101 102 |
# File 'lib/vagrant-aws/config.rb', line 100 def iam_instance_profile_name @iam_instance_profile_name end |
#instance_check_interval ⇒ Fixnum
The interval to wait for checking an instance’s state.
31 32 33 |
# File 'lib/vagrant-aws/config.rb', line 31 def instance_check_interval @instance_check_interval end |
#instance_package_timeout ⇒ Fixnum
The timeout to wait for an instance to successfully burn into an AMI.
36 37 38 |
# File 'lib/vagrant-aws/config.rb', line 36 def instance_package_timeout @instance_package_timeout end |
#instance_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
26 27 28 |
# File 'lib/vagrant-aws/config.rb', line 26 def instance_ready_timeout @instance_ready_timeout end |
#instance_type ⇒ String
The type of instance to launch, such as “m3.medium”
41 42 43 |
# File 'lib/vagrant-aws/config.rb', line 41 def instance_type @instance_type end |
#kernel_id ⇒ String
Kernel Id
181 182 183 |
# File 'lib/vagrant-aws/config.rb', line 181 def kernel_id @kernel_id end |
#keypair_name ⇒ String
The name of the keypair to use.
46 47 48 |
# File 'lib/vagrant-aws/config.rb', line 46 def keypair_name @keypair_name end |
#monitoring ⇒ Boolean
Enables Monitoring
151 152 153 |
# File 'lib/vagrant-aws/config.rb', line 151 def monitoring @monitoring end |
#package_tags ⇒ Hash<String, String>
The tags for the AMI generated with package.
115 116 117 |
# File 'lib/vagrant-aws/config.rb', line 115 def @package_tags end |
#private_ip_address ⇒ String
The private IP address to give this machine (VPC).
51 52 53 |
# File 'lib/vagrant-aws/config.rb', line 51 def private_ip_address @private_ip_address end |
#region ⇒ String
The name of the AWS region in which to create the instance.
62 63 64 |
# File 'lib/vagrant-aws/config.rb', line 62 def region @region end |
#secret_access_key ⇒ String
The secret access key for accessing AWS.
77 78 79 |
# File 'lib/vagrant-aws/config.rb', line 77 def secret_access_key @secret_access_key end |
#security_groups ⇒ Array<String>
The security groups to set on the instance. For VPC this must be a list of IDs. For EC2, it can be either.
88 89 90 |
# File 'lib/vagrant-aws/config.rb', line 88 def security_groups @security_groups end |
#session_token ⇒ String
The token associated with the key for accessing AWS.
82 83 84 |
# File 'lib/vagrant-aws/config.rb', line 82 def session_token @session_token end |
#source_dest_check ⇒ Boolean
Source Destination check
161 162 163 |
# File 'lib/vagrant-aws/config.rb', line 161 def source_dest_check @source_dest_check end |
#spot_instance ⇒ Boolean
Launch as spot instance
202 203 204 |
# File 'lib/vagrant-aws/config.rb', line 202 def spot_instance @spot_instance end |
#spot_max_price ⇒ String
Spot request max price
207 208 209 |
# File 'lib/vagrant-aws/config.rb', line 207 def spot_max_price @spot_max_price end |
#spot_price_product_description ⇒ String
The product description for the spot price history
217 218 219 |
# File 'lib/vagrant-aws/config.rb', line 217 def spot_price_product_description @spot_price_product_description end |
#spot_valid_until ⇒ Time
Spot request validity
212 213 214 |
# File 'lib/vagrant-aws/config.rb', line 212 def spot_valid_until @spot_valid_until end |
#ssh_host_attribute ⇒ Symbol
Specifies which address to connect to with ssh Must be one of:
- :public_ip_address
- :dns_name
- :private_ip_address
This attribute also accepts an array of symbols
146 147 148 |
# File 'lib/vagrant-aws/config.rb', line 146 def ssh_host_attribute @ssh_host_attribute end |
#subnet_id ⇒ String
The subnet ID to launch the machine into (VPC).
105 106 107 |
# File 'lib/vagrant-aws/config.rb', line 105 def subnet_id @subnet_id end |
#tags ⇒ Hash<String, String>
The tags for the machine.
110 111 112 |
# File 'lib/vagrant-aws/config.rb', line 110 def @tags end |
#tenancy ⇒ String
The tenancy of the instance in a VPC. Defaults to ‘default’.
187 188 189 |
# File 'lib/vagrant-aws/config.rb', line 187 def tenancy @tenancy end |
#terminate_on_shutdown ⇒ bool
Indicates whether an instance stops or terminates when you initiate shutdown from the instance
136 137 138 |
# File 'lib/vagrant-aws/config.rb', line 136 def terminate_on_shutdown @terminate_on_shutdown end |
#unregister_elb_from_az ⇒ Boolean
Disable unregisering ELB’s from AZ - useful in case of not using default VPC
176 177 178 |
# File 'lib/vagrant-aws/config.rb', line 176 def unregister_elb_from_az @unregister_elb_from_az end |
#use_iam_profile ⇒ Boolean
Use IAM Instance Role for authentication to AWS instead of an explicit access_id and secret_access_key
121 122 123 |
# File 'lib/vagrant-aws/config.rb', line 121 def use_iam_profile @use_iam_profile end |
#user_data ⇒ String
The user data string
126 127 128 |
# File 'lib/vagrant-aws/config.rb', line 126 def user_data @user_data end |
#version ⇒ String
The version of the AWS api to use
72 73 74 |
# File 'lib/vagrant-aws/config.rb', line 72 def version @version end |
Instance Method Details
#finalize! ⇒ Object
342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 |
# File 'lib/vagrant-aws/config.rb', line 342 def finalize! # If access_key_id or secret_access_key were not specified in Vagrantfile # then try to read from environment variables first, and if it fails from # the AWS folder. if @access_key_id == UNSET_VALUE or @secret_access_key == UNSET_VALUE @aws_profile = 'default' if @aws_profile == UNSET_VALUE @aws_dir = ENV['HOME'].to_s + '/.aws/' if @aws_dir == UNSET_VALUE @aws_region, @access_key_id, @secret_access_key, @session_token = Credentials.new.get_aws_info(@aws_profile, @aws_dir) @region = @aws_region if @region == UNSET_VALUE and !@aws_region.nil? else @aws_profile = nil @aws_dir = nil end # session token must be set to nil, empty string isn't enough! @session_token = nil if @session_token == UNSET_VALUE # AMI must be nil, since we can't default that @ami = nil if @ami == UNSET_VALUE # Set the default timeout for waiting for an instance to be ready @instance_ready_timeout = 120 if @instance_ready_timeout == UNSET_VALUE # Set the default interval to check instance state @instance_check_interval = 2 if @instance_check_interval == UNSET_VALUE # Set the default timeout for waiting for an instance to burn into and ami @instance_package_timeout = 600 if @instance_package_timeout == UNSET_VALUE # Default instance type is an m3.medium @instance_type = "m3.medium" if @instance_type == UNSET_VALUE # Keypair defaults to nil @keypair_name = nil if @keypair_name == UNSET_VALUE # Default the private IP to nil since VPC is not default @private_ip_address = nil if @private_ip_address == UNSET_VALUE # Acquire an elastic IP if requested @elastic_ip = nil if @elastic_ip == UNSET_VALUE # Default region is us-east-1. This is sensible because AWS # generally defaults to this as well. @region = "us-east-1" if @region == UNSET_VALUE @availability_zone = nil if @availability_zone == UNSET_VALUE @endpoint = nil if @endpoint == UNSET_VALUE @version = nil if @version == UNSET_VALUE # The security groups are empty by default. @security_groups = [] if @security_groups == UNSET_VALUE # Subnet is nil by default otherwise we'd launch into VPC. @subnet_id = nil if @subnet_id == UNSET_VALUE # IAM Instance profile arn/name is nil by default. @iam_instance_profile_arn = nil if @iam_instance_profile_arn == UNSET_VALUE @iam_instance_profile_name = nil if @iam_instance_profile_name == UNSET_VALUE # By default we don't use an IAM profile @use_iam_profile = false if @use_iam_profile == UNSET_VALUE # User Data is nil by default @user_data = nil if @user_data == UNSET_VALUE # default false @terminate_on_shutdown = false if @terminate_on_shutdown == UNSET_VALUE # default to nil @ssh_host_attribute = nil if @ssh_host_attribute == UNSET_VALUE # default false @monitoring = false if @monitoring == UNSET_VALUE # default false @ebs_optimized = false if @ebs_optimized == UNSET_VALUE # default to nil @source_dest_check = nil if @source_dest_check == UNSET_VALUE # default false @associate_public_ip = false if @associate_public_ip == UNSET_VALUE # default 'default' @tenancy = "default" if @tenancy == UNSET_VALUE # Don't attach instance to any ELB by default @elb = nil if @elb == UNSET_VALUE @unregister_elb_from_az = true if @unregister_elb_from_az == UNSET_VALUE # default to nil @kernel_id = nil if @kernel_id == UNSET_VALUE # By default don't use spot requests @spot_instance = false if @spot_instance == UNSET_VALUE # default to nil @spot_max_price = nil if @spot_max_price == UNSET_VALUE # Default: Request is effective indefinitely. @spot_valid_until = nil if @spot_valid_until == UNSET_VALUE # default to nil @spot_price_product_description = nil if @spot_price_product_description == UNSET_VALUE # Compile our region specific configurations only within # NON-REGION-SPECIFIC configurations. if !@__region_specific @__region_config.each do |region, blocks| config = self.class.new(true).merge(self) # Execute the configuration for each block blocks.each { |b| b.call(config) } # The region name of the configuration always equals the # region config name: config.region = region # Finalize the configuration config.finalize! # Store it for retrieval @__compiled_region_configs[region] = config end end # Mark that we finalized @__finalized = true end |
#get_region_config(name) ⇒ Object
This gets the configuration for a specific region. It shouldn’t be called by the general public and is only used internally.
505 506 507 508 509 510 511 512 |
# File 'lib/vagrant-aws/config.rb', line 505 def get_region_config(name) if !@__finalized raise "Configuration must be finalized before calling this method." end # Return the compiled region config @__compiled_region_configs[name] || self end |
#merge(other) ⇒ Object
Internal methods.
309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 |
# File 'lib/vagrant-aws/config.rb', line 309 def merge(other) super.tap do |result| # Copy over the region specific flag. "True" is retained if either # has it. new_region_specific = other.instance_variable_get(:@__region_specific) result.instance_variable_set( :@__region_specific, new_region_specific || @__region_specific) # Go through all the region configs and prepend ours onto # theirs. new_region_config = other.instance_variable_get(:@__region_config) @__region_config.each do |key, value| new_region_config[key] ||= [] new_region_config[key] = value + new_region_config[key] end # Set it result.instance_variable_set(:@__region_config, new_region_config) # Merge in the tags result..merge!(self.) result..merge!(other.) # Merge in the package tags result..merge!(self.) result..merge!(other.) # Merge block_device_mapping result.block_device_mapping |= self.block_device_mapping result.block_device_mapping |= other.block_device_mapping end end |
#region_config(region, attributes = nil) {|config| ... } ⇒ Object
Allows region-specific overrides of any of the settings on this configuration object. This allows the user to override things like AMI and keypair name for regions. Example:
aws.region_config "us-east-1" do |region|
region.ami = "ami-12345678"
region.keypair_name = "company-east"
end
287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/vagrant-aws/config.rb', line 287 def region_config(region, attributes=nil, &block) # Append the block to the list of region configs for that region. # We'll evaluate these upon finalization. @__region_config[region] ||= [] # Append a block that sets attributes if we got one if attributes attr_block = lambda do |config| config.(attributes) end @__region_config[region] << attr_block end # Append a block if we got one @__region_config[region] << block if block_given? end |
#validate(machine) ⇒ Object
472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 |
# File 'lib/vagrant-aws/config.rb', line 472 def validate(machine) errors = _detected_errors errors << I18n.t("vagrant_aws.config.aws_info_required", :profile => @aws_profile, :location => @aws_dir) if \ @aws_profile and (@access_key_id.nil? or @secret_access_key.nil? or @region.nil?) errors << I18n.t("vagrant_aws.config.region_required") if @region.nil? if @region # Get the configuration for the region we're using and validate only # that region. config = get_region_config(@region) if !config.use_iam_profile errors << I18n.t("vagrant_aws.config.access_key_id_required") if \ config.access_key_id.nil? errors << I18n.t("vagrant_aws.config.secret_access_key_required") if \ config.secret_access_key.nil? end if config.associate_public_ip && !config.subnet_id errors << I18n.t("vagrant_aws.config.subnet_id_required_with_public_ip") end errors << I18n.t("vagrant_aws.config.ami_required", :region => @region) if config.ami.nil? end { "AWS Provider" => errors } end |