mirror of https://github.com/docker/docs.git
Merge pull request #449 from sthulb/aws-assign-roles
IRC Req: EC2 IAM Instance Profile
This commit is contained in:
commit
5f01d4cda5
|
@ -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.
|
||||
|
|
|
@ -37,43 +37,45 @@ var (
|
|||
)
|
||||
|
||||
type Driver struct {
|
||||
Id string
|
||||
AccessKey string
|
||||
SecretKey string
|
||||
SessionToken string
|
||||
Region string
|
||||
AMI string
|
||||
SSHKeyID int
|
||||
KeyName string
|
||||
InstanceId string
|
||||
InstanceType string
|
||||
IPAddress string
|
||||
PrivateIPAddress string
|
||||
MachineName string
|
||||
SecurityGroupId string
|
||||
SecurityGroupName string
|
||||
ReservationId string
|
||||
RootSize int64
|
||||
VpcId string
|
||||
SubnetId string
|
||||
Zone string
|
||||
CaCertPath string
|
||||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
storePath string
|
||||
keyPath string
|
||||
Id string
|
||||
AccessKey string
|
||||
SecretKey string
|
||||
SessionToken string
|
||||
Region string
|
||||
AMI string
|
||||
SSHKeyID int
|
||||
KeyName string
|
||||
InstanceId string
|
||||
InstanceType string
|
||||
IPAddress string
|
||||
PrivateIPAddress string
|
||||
MachineName string
|
||||
SecurityGroupId string
|
||||
SecurityGroupName string
|
||||
ReservationId string
|
||||
RootSize int64
|
||||
IamInstanceProfile string
|
||||
VpcId string
|
||||
SubnetId string
|
||||
Zone string
|
||||
CaCertPath string
|
||||
PrivateKeyPath string
|
||||
SwarmMaster bool
|
||||
SwarmHost string
|
||||
SwarmDiscovery string
|
||||
storePath string
|
||||
keyPath string
|
||||
}
|
||||
|
||||
type CreateFlags struct {
|
||||
AccessKey *string
|
||||
SecretKey *string
|
||||
Region *string
|
||||
AMI *string
|
||||
InstanceType *string
|
||||
SubnetId *string
|
||||
RootSize *int64
|
||||
AccessKey *string
|
||||
SecretKey *string
|
||||
Region *string
|
||||
AMI *string
|
||||
InstanceType *string
|
||||
SubnetId *string
|
||||
RootSize *int64
|
||||
IamInstanceProfile *string
|
||||
}
|
||||
|
||||
func init() {
|
||||
|
@ -150,6 +152,10 @@ func GetCreateFlags() []cli.Flag {
|
|||
Value: defaultRootSize,
|
||||
EnvVar: "AWS_ROOT_SIZE",
|
||||
},
|
||||
cli.StringFlag{
|
||||
Name: "amazonec2-iam-instance-profile",
|
||||
Usage: "AWS IAM Instance Profile",
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -181,6 +187,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")
|
||||
|
@ -295,7 +302,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)
|
||||
|
|
|
@ -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)
|
||||
|
|
Loading…
Reference in New Issue