diff --git a/CHANGELOG.md b/CHANGELOG.md index 246d82a02..2dd048267 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -34,6 +34,7 @@ BUG FIXES: * builder/amazon-instance: Fix deprecation warning for `ec2-bundle-vol` [GH-1424] * builder/amazon/all: `delete_on_termination` set to false will work. + * builder/amazon/all: Fix race condition on setting tags. [GH-1367] * builder/amazon/all: More desctriptive error messages if Amazon only sends an error code. [GH-1189] * builder/docker: Remove the container during cleanup. [GH-1206] diff --git a/builder/amazon/common/step_run_source_instance.go b/builder/amazon/common/step_run_source_instance.go index c9827e589..43fcd1c97 100644 --- a/builder/amazon/common/step_run_source_instance.go +++ b/builder/amazon/common/step_run_source_instance.go @@ -93,18 +93,6 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi s.instance = &runResp.Instances[0] ui.Message(fmt.Sprintf("Instance ID: %s", s.instance.InstanceId)) - ec2Tags := make([]ec2.Tag, 1, len(s.Tags)+1) - ec2Tags[0] = ec2.Tag{"Name", "Packer Builder"} - for k, v := range s.Tags { - ec2Tags = append(ec2Tags, ec2.Tag{k, v}) - } - - _, err = ec2conn.CreateTags([]string{s.instance.InstanceId}, ec2Tags) - if err != nil { - ui.Message( - fmt.Sprintf("Failed to tag a Name on the builder instance: %s", err)) - } - ui.Say(fmt.Sprintf("Waiting for instance (%s) to become ready...", s.instance.InstanceId)) stateChange := StateChangeConf{ Pending: []string{"pending"}, @@ -122,6 +110,18 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi s.instance = latestInstance.(*ec2.Instance) + ec2Tags := make([]ec2.Tag, 1, len(s.Tags)+1) + ec2Tags[0] = ec2.Tag{"Name", "Packer Builder"} + for k, v := range s.Tags { + ec2Tags = append(ec2Tags, ec2.Tag{k, v}) + } + + _, err = ec2conn.CreateTags([]string{s.instance.InstanceId}, ec2Tags) + if err != nil { + ui.Message( + fmt.Sprintf("Failed to tag a Name on the builder instance: %s", err)) + } + if s.Debug { if s.instance.DNSName != "" { ui.Message(fmt.Sprintf("Public DNS: %s", s.instance.DNSName))