add an option custom_endpoint_ec2 for amazon builder, add a condition if vpc_id is empty don't add the parameter to the aws call

This commit is contained in:
Rémi Jouannet 2017-05-17 18:45:20 +02:00
parent 94360f4b39
commit 45143bb6f4
2 changed files with 17 additions and 7 deletions

View File

@ -17,12 +17,13 @@ import (
// AccessConfig is for common configuration related to AWS access
type AccessConfig struct {
AccessKey string `mapstructure:"access_key"`
SecretKey string `mapstructure:"secret_key"`
RawRegion string `mapstructure:"region"`
SkipValidation bool `mapstructure:"skip_region_validation"`
Token string `mapstructure:"token"`
ProfileName string `mapstructure:"profile"`
AccessKey string `mapstructure:"access_key"`
SecretKey string `mapstructure:"secret_key"`
RawRegion string `mapstructure:"region"`
SkipValidation bool `mapstructure:"skip_region_validation"`
Token string `mapstructure:"token"`
ProfileName string `mapstructure:"profile"`
CustomEndpointEc2 string `mapstructure:"custom_endpoint_ec2"`
}
// Config returns a valid aws.Config object for access to AWS services, or
@ -35,6 +36,11 @@ func (c *AccessConfig) Config() (*aws.Config, error) {
return nil, err
}
config := aws.NewConfig().WithRegion(region).WithMaxRetries(11)
if c.CustomEndpointEc2 != "" {
config.Endpoint = &c.CustomEndpointEc2
}
if c.ProfileName != "" {
profile, err := NewFromProfile(c.ProfileName)
if err != nil {

View File

@ -55,8 +55,12 @@ func (s *StepSecurityGroup) Run(state multistep.StateBag) multistep.StepAction {
group := &ec2.CreateSecurityGroupInput{
GroupName: &groupName,
Description: aws.String("Temporary group for Packer"),
VpcId: &s.VpcId,
}
if s.VpcId != "" {
group.VpcId = &s.VpcId
}
groupResp, err := ec2conn.CreateSecurityGroup(group)
if err != nil {
ui.Error(err.Error())