adds the ability to set an instance role for ec2 instances

Signed-off-by: Simon Thulbourn <simon+github@thulbourn.com>
This commit is contained in:
Simon Thulbourn 2015-03-01 20:56:37 +00:00
parent c3878a9285
commit 2ce70bf5ac
3 changed files with 48 additions and 36 deletions

View File

@ -590,6 +590,7 @@ Options:
- `--amazonec2-access-key`: **required** Your access key id for the Amazon Web Services API.
- `--amazonec2-ami`: The AMI ID of the instance to use Default: `ami-4ae27e22`
- `--amazonec2-instance-type`: The instance type to run. Default: `t2.micro`
- `--amazonec2-iam-instance-profile`: The AWS IAM role name to be used as the instance profile
- `--amazonec2-region`: The region to use when launching the instance. Default: `us-east-1`
- `--amazonec2-root-size`: The root disk size of the instance (in GB). Default: `16`
- `--amazonec2-secret-key`: **required** Your secret access key for the Amazon Web Services API.

View File

@ -50,6 +50,7 @@ type Driver struct {
SecurityGroupName string
ReservationId string
RootSize int64
IamInstanceProfile string
VpcId string
SubnetId string
Zone string
@ -70,6 +71,7 @@ type CreateFlags struct {
InstanceType *string
SubnetId *string
RootSize *int64
IamInstanceProfile *string
}
func init() {
@ -146,6 +148,10 @@ func GetCreateFlags() []cli.Flag {
Value: defaultRootSize,
EnvVar: "AWS_ROOT_SIZE",
},
cli.StringFlag{
Name: "amazonec2-iam-instance-profile",
Usage: "AWS IAM Instance Profile",
},
}
}
@ -177,6 +183,7 @@ func (d *Driver) SetConfigFromFlags(flags drivers.DriverOptions) error {
zone := flags.String("amazonec2-zone")
d.Zone = zone[:]
d.RootSize = int64(flags.Int("amazonec2-root-size"))
d.IamInstanceProfile = flags.String("amazonec2-iam-instance-profile")
d.SwarmMaster = flags.Bool("swarm-master")
d.SwarmHost = flags.String("swarm-host")
d.SwarmDiscovery = flags.String("swarm-discovery")
@ -276,7 +283,7 @@ func (d *Driver) Create() error {
}
log.Debugf("launching instance in subnet %s", d.SubnetId)
instance, err := d.getClient().RunInstance(d.AMI, d.InstanceType, d.Zone, 1, 1, d.SecurityGroupId, d.KeyName, d.SubnetId, bdm)
instance, err := d.getClient().RunInstance(d.AMI, d.InstanceType, d.Zone, 1, 1, d.SecurityGroupId, d.KeyName, d.SubnetId, bdm, d.IamInstanceProfile)
if err != nil {
return fmt.Errorf("Error launching instance: %s", err)

View File

@ -166,7 +166,7 @@ func (e *EC2) awsApiCall(v url.Values) (*http.Response, error) {
return resp, nil
}
func (e *EC2) RunInstance(amiId string, instanceType string, zone string, minCount int, maxCount int, securityGroup string, keyName string, subnetId string, bdm *BlockDeviceMapping) (EC2Instance, error) {
func (e *EC2) RunInstance(amiId string, instanceType string, zone string, minCount int, maxCount int, securityGroup string, keyName string, subnetId string, bdm *BlockDeviceMapping, role string) (EC2Instance, error) {
instance := Instance{}
v := url.Values{}
v.Set("Action", "RunInstances")
@ -181,6 +181,10 @@ func (e *EC2) RunInstance(amiId string, instanceType string, zone string, minCou
v.Set("NetworkInterface.0.SubnetId", subnetId)
v.Set("NetworkInterface.0.AssociatePublicIpAddress", "1")
if len(role) > 0 {
v.Set("IamInstanceProfile.Name", role)
}
if bdm != nil {
v.Set("BlockDeviceMapping.0.DeviceName", bdm.DeviceName)
v.Set("BlockDeviceMapping.0.VirtualName", bdm.VirtualName)