issue5606: follow the convention to use AccessConfig to create new aws session for step_create_tags etc.
This commit is contained in:
parent
1de0004710
commit
3e92b1374e
|
@ -281,6 +281,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
Ctx: b.config.ctx,
|
||||
},
|
||||
&awscommon.StepCreateTags{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Tags: b.config.AMITags,
|
||||
SnapshotTags: b.config.SnapshotTags,
|
||||
Ctx: b.config.ctx,
|
||||
|
@ -303,6 +304,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
|
||||
// Build the artifact and return it
|
||||
artifact := &awscommon.Artifact{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Amis: state.Get("amis").(map[string]string),
|
||||
BuilderIdValue: BuilderId,
|
||||
Conn: ec2conn,
|
||||
|
|
|
@ -6,14 +6,14 @@ import (
|
|||
"sort"
|
||||
"strings"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
)
|
||||
|
||||
// Artifact is an artifact implementation that contains built AMIs.
|
||||
type Artifact struct {
|
||||
AccessConfig *AccessConfig
|
||||
|
||||
// A map of regions to AMI IDs.
|
||||
Amis map[string]string
|
||||
|
||||
|
@ -69,11 +69,7 @@ func (a *Artifact) Destroy() error {
|
|||
for region, imageId := range a.Amis {
|
||||
log.Printf("Deregistering image ID (%s) from region (%s)", imageId, region)
|
||||
|
||||
regionConfig := &aws.Config{
|
||||
Credentials: a.Conn.Config.Credentials,
|
||||
Region: aws.String(region),
|
||||
}
|
||||
session, err := session.NewSession(regionConfig)
|
||||
session, err := a.AccessConfig.Session()
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
|
|
@ -5,7 +5,6 @@ import (
|
|||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/aws/session"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
retry "github.com/hashicorp/packer/common"
|
||||
"github.com/hashicorp/packer/packer"
|
||||
|
@ -14,6 +13,7 @@ import (
|
|||
)
|
||||
|
||||
type StepCreateTags struct {
|
||||
AccessConfig *AccessConfig
|
||||
Tags map[string]string
|
||||
SnapshotTags map[string]string
|
||||
Ctx interpolate.Context
|
||||
|
@ -36,15 +36,11 @@ func (s *StepCreateTags) Run(state multistep.StateBag) multistep.StepAction {
|
|||
}
|
||||
|
||||
// Adds tags to AMIs and snapshots
|
||||
for region, ami := range amis {
|
||||
for ami := range amis {
|
||||
ui.Say(fmt.Sprintf("Adding tags to AMI (%s)...", ami))
|
||||
|
||||
// Declare list of resources to tag
|
||||
awsConfig := aws.Config{
|
||||
Credentials: ec2conn.Config.Credentials,
|
||||
Region: aws.String(region),
|
||||
}
|
||||
session, err := session.NewSession(&awsConfig)
|
||||
session, err := s.AccessConfig.Session()
|
||||
if err != nil {
|
||||
err := fmt.Errorf("Error creating AWS session: %s", err)
|
||||
state.Put("error", err)
|
||||
|
|
|
@ -245,6 +245,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
Ctx: b.config.ctx,
|
||||
},
|
||||
&awscommon.StepCreateTags{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Tags: b.config.AMITags,
|
||||
SnapshotTags: b.config.SnapshotTags,
|
||||
Ctx: b.config.ctx,
|
||||
|
@ -267,6 +268,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
|
||||
// Build the artifact and return it
|
||||
artifact := &awscommon.Artifact{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Amis: state.Get("amis").(map[string]string),
|
||||
BuilderIdValue: BuilderId,
|
||||
Conn: ec2conn,
|
||||
|
|
|
@ -263,6 +263,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
Ctx: b.config.ctx,
|
||||
},
|
||||
&awscommon.StepCreateTags{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Tags: b.config.AMITags,
|
||||
SnapshotTags: b.config.SnapshotTags,
|
||||
Ctx: b.config.ctx,
|
||||
|
@ -281,6 +282,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
if amis, ok := state.GetOk("amis"); ok {
|
||||
// Build the artifact and return it
|
||||
artifact := &awscommon.Artifact{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Amis: amis.(map[string]string),
|
||||
BuilderIdValue: BuilderId,
|
||||
Conn: ec2conn,
|
||||
|
|
|
@ -317,6 +317,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
Ctx: b.config.ctx,
|
||||
},
|
||||
&awscommon.StepCreateTags{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Tags: b.config.AMITags,
|
||||
SnapshotTags: b.config.SnapshotTags,
|
||||
Ctx: b.config.ctx,
|
||||
|
@ -339,6 +340,7 @@ func (b *Builder) Run(ui packer.Ui, hook packer.Hook, cache packer.Cache) (packe
|
|||
|
||||
// Build the artifact and return it
|
||||
artifact := &awscommon.Artifact{
|
||||
AccessConfig: &b.config.AccessConfig,
|
||||
Amis: state.Get("amis").(map[string]string),
|
||||
BuilderIdValue: BuilderId,
|
||||
Conn: ec2conn,
|
||||
|
|
|
@ -365,6 +365,7 @@ func (p *PostProcessor) PostProcess(ui packer.Ui, artifact packer.Artifact) (pac
|
|||
// Add the reported AMI ID to the artifact list
|
||||
log.Printf("Adding created AMI ID %s in region %s to output artifacts", createdami, *config.Region)
|
||||
artifact = &awscommon.Artifact{
|
||||
AccessConfig: &p.config.AccessConfig,
|
||||
Amis: map[string]string{
|
||||
*config.Region: createdami,
|
||||
},
|
||||
|
|
Loading…
Reference in New Issue