Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
P
packer
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kristopher Ruzic
packer
Commits
a9c299d9
Commit
a9c299d9
authored
Jul 28, 2015
by
Chris Bednarski
Browse files
Options
Browse Files
Download
Plain Diff
Merge pull request #2404 from mitchellh/b-instance-destroy
amazon/common: store instance ID earlier for cleanup
parents
68a6a0df
26aa3dd5
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
16 additions
and
14 deletions
+16
-14
builder/amazon/common/step_run_source_instance.go
builder/amazon/common/step_run_source_instance.go
+16
-14
No files found.
builder/amazon/common/step_run_source_instance.go
View file @
a9c299d9
...
@@ -31,7 +31,7 @@ type StepRunSourceInstance struct {
...
@@ -31,7 +31,7 @@ type StepRunSourceInstance struct {
UserData
string
UserData
string
UserDataFile
string
UserDataFile
string
instance
*
ec2
.
Instance
instance
Id
string
spotRequest
*
ec2
.
SpotInstanceRequest
spotRequest
*
ec2
.
SpotInstanceRequest
}
}
...
@@ -235,6 +235,9 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
...
@@ -235,6 +235,9 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
instanceId
=
*
spotResp
.
SpotInstanceRequests
[
0
]
.
InstanceID
instanceId
=
*
spotResp
.
SpotInstanceRequests
[
0
]
.
InstanceID
}
}
// Set the instance ID so that the cleanup works properly
s
.
instanceId
=
instanceId
ui
.
Message
(
fmt
.
Sprintf
(
"Instance ID: %s"
,
instanceId
))
ui
.
Message
(
fmt
.
Sprintf
(
"Instance ID: %s"
,
instanceId
))
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for instance (%v) to become ready..."
,
instanceId
))
ui
.
Say
(
fmt
.
Sprintf
(
"Waiting for instance (%v) to become ready..."
,
instanceId
))
stateChange
:=
StateChangeConf
{
stateChange
:=
StateChangeConf
{
...
@@ -251,7 +254,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
...
@@ -251,7 +254,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
return
multistep
.
ActionHalt
return
multistep
.
ActionHalt
}
}
s
.
instance
=
latestInstance
.
(
*
ec2
.
Instance
)
instance
:
=
latestInstance
.
(
*
ec2
.
Instance
)
ec2Tags
:=
make
([]
*
ec2
.
Tag
,
1
,
len
(
s
.
Tags
)
+
1
)
ec2Tags
:=
make
([]
*
ec2
.
Tag
,
1
,
len
(
s
.
Tags
)
+
1
)
ec2Tags
[
0
]
=
&
ec2
.
Tag
{
Key
:
aws
.
String
(
"Name"
),
Value
:
aws
.
String
(
"Packer Builder"
)}
ec2Tags
[
0
]
=
&
ec2
.
Tag
{
Key
:
aws
.
String
(
"Name"
),
Value
:
aws
.
String
(
"Packer Builder"
)}
...
@@ -261,7 +264,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
...
@@ -261,7 +264,7 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
_
,
err
=
ec2conn
.
CreateTags
(
&
ec2
.
CreateTagsInput
{
_
,
err
=
ec2conn
.
CreateTags
(
&
ec2
.
CreateTagsInput
{
Tags
:
ec2Tags
,
Tags
:
ec2Tags
,
Resources
:
[]
*
string
{
s
.
instance
.
InstanceID
},
Resources
:
[]
*
string
{
instance
.
InstanceID
},
})
})
if
err
!=
nil
{
if
err
!=
nil
{
ui
.
Message
(
ui
.
Message
(
...
@@ -269,20 +272,20 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
...
@@ -269,20 +272,20 @@ func (s *StepRunSourceInstance) Run(state multistep.StateBag) multistep.StepActi
}
}
if
s
.
Debug
{
if
s
.
Debug
{
if
s
.
instance
.
PublicDNSName
!=
nil
&&
*
s
.
instance
.
PublicDNSName
!=
""
{
if
instance
.
PublicDNSName
!=
nil
&&
*
instance
.
PublicDNSName
!=
""
{
ui
.
Message
(
fmt
.
Sprintf
(
"Public DNS: %s"
,
*
s
.
instance
.
PublicDNSName
))
ui
.
Message
(
fmt
.
Sprintf
(
"Public DNS: %s"
,
*
instance
.
PublicDNSName
))
}
}
if
s
.
instance
.
PublicIPAddress
!=
nil
&&
*
s
.
instance
.
PublicIPAddress
!=
""
{
if
instance
.
PublicIPAddress
!=
nil
&&
*
instance
.
PublicIPAddress
!=
""
{
ui
.
Message
(
fmt
.
Sprintf
(
"Public IP: %s"
,
*
s
.
instance
.
PublicIPAddress
))
ui
.
Message
(
fmt
.
Sprintf
(
"Public IP: %s"
,
*
instance
.
PublicIPAddress
))
}
}
if
s
.
instance
.
PrivateIPAddress
!=
nil
&&
*
s
.
instance
.
PrivateIPAddress
!=
""
{
if
instance
.
PrivateIPAddress
!=
nil
&&
*
instance
.
PrivateIPAddress
!=
""
{
ui
.
Message
(
fmt
.
Sprintf
(
"Private IP: %s"
,
*
s
.
instance
.
PrivateIPAddress
))
ui
.
Message
(
fmt
.
Sprintf
(
"Private IP: %s"
,
*
instance
.
PrivateIPAddress
))
}
}
}
}
state
.
Put
(
"instance"
,
s
.
instance
)
state
.
Put
(
"instance"
,
instance
)
return
multistep
.
ActionContinue
return
multistep
.
ActionContinue
}
}
...
@@ -313,16 +316,15 @@ func (s *StepRunSourceInstance) Cleanup(state multistep.StateBag) {
...
@@ -313,16 +316,15 @@ func (s *StepRunSourceInstance) Cleanup(state multistep.StateBag) {
}
}
// Terminate the source instance if it exists
// Terminate the source instance if it exists
if
s
.
instance
!=
nil
{
if
s
.
instanceId
!=
""
{
ui
.
Say
(
"Terminating the source AWS instance..."
)
ui
.
Say
(
"Terminating the source AWS instance..."
)
if
_
,
err
:=
ec2conn
.
TerminateInstances
(
&
ec2
.
TerminateInstancesInput
{
InstanceIDs
:
[]
*
string
{
s
.
instance
.
InstanceID
}});
err
!=
nil
{
if
_
,
err
:=
ec2conn
.
TerminateInstances
(
&
ec2
.
TerminateInstancesInput
{
InstanceIDs
:
[]
*
string
{
&
s
.
instanceId
}});
err
!=
nil
{
ui
.
Error
(
fmt
.
Sprintf
(
"Error terminating instance, may still be around: %s"
,
err
))
ui
.
Error
(
fmt
.
Sprintf
(
"Error terminating instance, may still be around: %s"
,
err
))
return
return
}
}
stateChange
:=
StateChangeConf
{
stateChange
:=
StateChangeConf
{
Pending
:
[]
string
{
"pending"
,
"running"
,
"shutting-down"
,
"stopped"
,
"stopping"
},
Pending
:
[]
string
{
"pending"
,
"running"
,
"shutting-down"
,
"stopped"
,
"stopping"
},
Refresh
:
InstanceStateRefreshFunc
(
ec2conn
,
*
s
.
instance
.
InstanceID
),
Refresh
:
InstanceStateRefreshFunc
(
ec2conn
,
s
.
instanceId
),
Target
:
"terminated"
,
Target
:
"terminated"
,
}
}
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment