Class: Furnish::Provisioner::AWS

Inherits:
API
  • Object
show all
Includes:
Logger::Mixins
Defined in:
lib/furnish/provisioners/aws.rb

Overview

AWS base class, handles AWS API basics, argument checking, general utility methods.

See attributes and #new for contraints that apply to all provisioners that inherit from it.

Direct Known Subclasses

EC2, SecurityGroup

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ AWS

Construct a new provisioner. Hash for arguments is required, values supplied will be injected into attributes. If a hash is not supplied, an ArgumentError is raised.

The AWS #access_key and #secret_key are required, and also raise an ArgumentError unless supplied.

In some provisioners, a region may also be required. In those, an… ArgumentError will be raise if it isn’t supplied.

For further constraints, please see provisioners that inherit from this class.



59
60
61
62
# File 'lib/furnish/provisioners/aws.rb', line 59

def initialize(args)
  super
  check_aws_settings
end

Instance Method Details

#access_keyObject

:attr: access_key

The AWS access key ID. Required.



22
23
24
# File 'lib/furnish/provisioners/aws.rb', line 22

furnish_property :access_key,
"AWS access key ID",
String

#check_aws_settingsObject

Ensures #access_key and #secret_key are set. Used by initializer.



67
68
69
70
71
# File 'lib/furnish/provisioners/aws.rb', line 67

def check_aws_settings
  unless access_key and secret_key
    raise ArgumentError, "AWS credentials must be provided to the provisioner."
  end
end

#check_regionObject

Ensures the region is set. Is not used by default in the initializer, but is common to many provisioners.



77
78
79
80
81
# File 'lib/furnish/provisioners/aws.rb', line 77

def check_region
  unless region
    raise ArgumentError, "AWS region must be provided to the provisioner."
  end
end

#ec2Object

constructs an AWS::EC2 object. if a region is supplied, constraints it to the region and a AWS::EC2::Region object will be returned.

these have the same interface for most things, and things that require a region in AWS::EC2 are defaulted to us-east-1. See the aws-sdk documentation for more details.



91
92
93
94
95
96
97
98
# File 'lib/furnish/provisioners/aws.rb', line 91

def ec2
  ec2 = ::AWS::EC2.new(
    :access_key_id => access_key,
    :secret_access_key => secret_key
  )

  return region ? ec2.regions[region] : ec2
end

#regionObject

:attr: region

The AWS region. Not required. The default is nil. Inheriting provisioners may affect the default and/or make it required.



41
42
43
# File 'lib/furnish/provisioners/aws.rb', line 41

furnish_property :region,
"AWS region -- default is nil, may be defaulted or required by subclasses.",
String

#secret_keyObject

:attr: secret_key

The AWS secret key ID. Required.



31
32
33
# File 'lib/furnish/provisioners/aws.rb', line 31

furnish_property :secret_key,
"AWS secret key ID",
String