From 45143bb6f45208aac5752c22c65d7f7d6fe06039 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?R=C3=A9mi=20Jouannet?= Date: Wed, 17 May 2017 18:45:20 +0200 Subject: [PATCH] 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 --- builder/amazon/common/access_config.go | 18 ++++++++++++------ builder/amazon/common/step_security_group.go | 6 +++++- 2 files changed, 17 insertions(+), 7 deletions(-) diff --git a/builder/amazon/common/access_config.go b/builder/amazon/common/access_config.go index eb501e070..959a88fda 100644 --- a/builder/amazon/common/access_config.go +++ b/builder/amazon/common/access_config.go @@ -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 { diff --git a/builder/amazon/common/step_security_group.go b/builder/amazon/common/step_security_group.go index db525fa43..b71eb9bfe 100644 --- a/builder/amazon/common/step_security_group.go +++ b/builder/amazon/common/step_security_group.go @@ -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())