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.
-
#availability_zone ⇒ String
The availability zone to launch the instance into.
-
#block_device_mapping ⇒ Array<Hash>
Block device mappings.
-
#ebs_optimized ⇒ Boolean
EBS optimized instance.
-
#elastic_ip ⇒ Boolean
Acquire and attach an elastic IP address (VPC).
-
#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_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
-
#instance_type ⇒ String
The type of instance to launch, such as “m1.small”.
-
#keypair_name ⇒ String
The name of the keypair to use.
-
#monitoring ⇒ Boolean
Enables Monitoring.
-
#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.
-
#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.
-
#terminate_on_shutdown ⇒ bool
Indicates whether an instance stops or terminates when you initiate shutdown from the instance.
-
#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.
136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 |
# File 'lib/vagrant-aws/config.rb', line 136 def initialize(region_specific=false) @access_key_id = UNSET_VALUE @ami = UNSET_VALUE @availability_zone = UNSET_VALUE @instance_ready_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 @security_groups = UNSET_VALUE @subnet_id = UNSET_VALUE @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 # 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.
9 10 11 |
# File 'lib/vagrant-aws/config.rb', line 9 def access_key_id @access_key_id end |
#ami ⇒ String
The ID of the AMI to use.
14 15 16 |
# File 'lib/vagrant-aws/config.rb', line 14 def ami @ami end |
#availability_zone ⇒ String
The availability zone to launch the instance into. If nil, it will use the default for your account.
20 21 22 |
# File 'lib/vagrant-aws/config.rb', line 20 def availability_zone @availability_zone end |
#block_device_mapping ⇒ Array<Hash>
Block device mappings
109 110 111 |
# File 'lib/vagrant-aws/config.rb', line 109 def block_device_mapping @block_device_mapping end |
#ebs_optimized ⇒ Boolean
EBS optimized instance
134 135 136 |
# File 'lib/vagrant-aws/config.rb', line 134 def ebs_optimized @ebs_optimized end |
#elastic_ip ⇒ Boolean
Acquire and attach an elastic IP address (VPC).
45 46 47 |
# File 'lib/vagrant-aws/config.rb', line 45 def elastic_ip @elastic_ip end |
#endpoint ⇒ String
The EC2 endpoint to connect to
55 56 57 |
# File 'lib/vagrant-aws/config.rb', line 55 def endpoint @endpoint end |
#iam_instance_profile_arn ⇒ String
The Amazon resource name (ARN) of the IAM Instance Profile to associate with the instance.
77 78 79 |
# File 'lib/vagrant-aws/config.rb', line 77 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.
83 84 85 |
# File 'lib/vagrant-aws/config.rb', line 83 def iam_instance_profile_name @iam_instance_profile_name end |
#instance_ready_timeout ⇒ Fixnum
The timeout to wait for an instance to become ready.
25 26 27 |
# File 'lib/vagrant-aws/config.rb', line 25 def instance_ready_timeout @instance_ready_timeout end |
#instance_type ⇒ String
The type of instance to launch, such as “m1.small”
30 31 32 |
# File 'lib/vagrant-aws/config.rb', line 30 def instance_type @instance_type end |
#keypair_name ⇒ String
The name of the keypair to use.
35 36 37 |
# File 'lib/vagrant-aws/config.rb', line 35 def keypair_name @keypair_name end |
#monitoring ⇒ Boolean
Enables Monitoring
129 130 131 |
# File 'lib/vagrant-aws/config.rb', line 129 def monitoring @monitoring end |
#private_ip_address ⇒ String
The private IP address to give this machine (VPC).
40 41 42 |
# File 'lib/vagrant-aws/config.rb', line 40 def private_ip_address @private_ip_address end |
#region ⇒ String
The name of the AWS region in which to create the instance.
50 51 52 |
# File 'lib/vagrant-aws/config.rb', line 50 def region @region end |
#secret_access_key ⇒ String
The secret access key for accessing AWS.
65 66 67 |
# File 'lib/vagrant-aws/config.rb', line 65 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.
71 72 73 |
# File 'lib/vagrant-aws/config.rb', line 71 def security_groups @security_groups 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
124 125 126 |
# File 'lib/vagrant-aws/config.rb', line 124 def ssh_host_attribute @ssh_host_attribute end |
#subnet_id ⇒ String
The subnet ID to launch the machine into (VPC).
88 89 90 |
# File 'lib/vagrant-aws/config.rb', line 88 def subnet_id @subnet_id end |
#tags ⇒ Hash<String, String>
The tags for the machine.
93 94 95 |
# File 'lib/vagrant-aws/config.rb', line 93 def @tags end |
#terminate_on_shutdown ⇒ bool
Indicates whether an instance stops or terminates when you initiate shutdown from the instance
114 115 116 |
# File 'lib/vagrant-aws/config.rb', line 114 def terminate_on_shutdown @terminate_on_shutdown end |
#use_iam_profile ⇒ Boolean
Use IAM Instance Role for authentication to AWS instead of an explicit access_id and secret_access_key
99 100 101 |
# File 'lib/vagrant-aws/config.rb', line 99 def use_iam_profile @use_iam_profile end |
#user_data ⇒ String
The user data string
104 105 106 |
# File 'lib/vagrant-aws/config.rb', line 104 def user_data @user_data end |
#version ⇒ String
The version of the AWS api to use
60 61 62 |
# File 'lib/vagrant-aws/config.rb', line 60 def version @version end |
Instance Method Details
#finalize! ⇒ Object
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 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 |
# File 'lib/vagrant-aws/config.rb', line 240 def finalize! # Try to get access keys from standard AWS environment variables; they # will default to nil if the environment variables are not present. @access_key_id = ENV['AWS_ACCESS_KEY'] if @access_key_id == UNSET_VALUE @secret_access_key = ENV['AWS_SECRET_KEY'] if @secret_access_key == 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 # Default instance type is an m1.small @instance_type = "m1.small" 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 # 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.
349 350 351 352 353 354 355 356 |
# File 'lib/vagrant-aws/config.rb', line 349 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.
211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 |
# File 'lib/vagrant-aws/config.rb', line 211 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 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
189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 |
# File 'lib/vagrant-aws/config.rb', line 189 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
324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/vagrant-aws/config.rb', line 324 def validate(machine) errors = _detected_errors 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 errors << I18n.t("vagrant_aws.config.ami_required") if config.ami.nil? end { "AWS Provider" => errors } end |