mirror of
https://github.com/kreuzwerker/terraform-provider-docker.git
synced 2026-02-03 04:09:29 -05:00
Add destroy_grace_seconds option to stop container before delete (#7513)
This commit is contained in:
parent
6154fad933
commit
439a19426c
3 changed files with 14 additions and 0 deletions
|
|
@ -285,6 +285,11 @@ func resourceDockerContainer() *schema.Resource {
|
|||
ForceNew: true,
|
||||
},
|
||||
|
||||
"destroy_grace_seconds": &schema.Schema{
|
||||
Type: schema.TypeInt,
|
||||
Optional: true,
|
||||
},
|
||||
|
||||
"labels": &schema.Schema{
|
||||
Type: schema.TypeMap,
|
||||
Optional: true,
|
||||
|
|
|
|||
|
|
@ -265,6 +265,14 @@ func resourceDockerContainerUpdate(d *schema.ResourceData, meta interface{}) err
|
|||
func resourceDockerContainerDelete(d *schema.ResourceData, meta interface{}) error {
|
||||
client := meta.(*dc.Client)
|
||||
|
||||
// Stop the container before removing if destroy_grace_seconds is defined
|
||||
if d.Get("destroy_grace_seconds").(int) > 0 {
|
||||
var timeout = uint(d.Get("destroy_grace_seconds").(int))
|
||||
if err := client.StopContainer(d.Id(), timeout); err != nil {
|
||||
return fmt.Errorf("Error stopping container %s: %s", d.Id(), err)
|
||||
}
|
||||
}
|
||||
|
||||
removeOpts := dc.RemoveContainerOptions{
|
||||
ID: d.Id(),
|
||||
RemoveVolumes: true,
|
||||
|
|
|
|||
|
|
@ -255,6 +255,7 @@ resource "docker_container" "foo" {
|
|||
entrypoint = ["/bin/bash", "-c", "ping localhost"]
|
||||
user = "root:root"
|
||||
restart = "on-failure"
|
||||
destroy_grace_seconds = 10
|
||||
max_retry_count = 5
|
||||
memory = 512
|
||||
memory_swap = 2048
|
||||
|
|
|
|||
Loading…
Reference in a new issue