diff --git a/README.md b/README.md index a34c6f65..c0c1df62 100644 --- a/README.md +++ b/README.md @@ -108,4 +108,9 @@ To contribute, please read the contribution guidelines: [Contributing to Terrafo ## License -The Terraform Provider Docker is available to everyone under the terms of the Mozilla Public License Version 2.0. [Take a look the LICENSE file](LICENSE). \ No newline at end of file +The Terraform Provider Docker is available to everyone under the terms of the Mozilla Public License Version 2.0. [Take a look the LICENSE file](LICENSE). + + +## Stargazers over time + +[![Stargazers over time](https://starchart.cc/kreuzwerker/terraform-provider-docker.svg)](https://starchart.cc/kreuzwerker/terraform-provider-docker) diff --git a/docs/resources/container.md b/docs/resources/container.md index 467adcdc..87443e40 100644 --- a/docs/resources/container.md +++ b/docs/resources/container.md @@ -76,7 +76,7 @@ resource "docker_image" "ubuntu" { - **read_only** (Boolean) If `true`, the container will be started as readonly. Defaults to `false`. - **remove_volumes** (Boolean) If `true`, it will remove anonymous volumes associated with the container. Defaults to `true`. - **restart** (String) The restart policy for the container. Must be one of 'no', 'on-failure', 'always', 'unless-stopped'. Defaults to `no`. -- **rm** (Boolean) If `true`, then the container will be automatically removed after his execution. Terraform won't check this container after creation. Defaults to `false`. +- **rm** (Boolean) If `true`, then the container will be automatically removed when it exits. Defaults to `false`. - **security_opts** (Set of String) List of string values to customize labels for MLS systems, such as SELinux. See https://docs.docker.com/engine/reference/run/#security-configuration. - **shm_size** (Number) Size of `/dev/shm` in MBs. - **start** (Boolean) If `true`, then the Docker container will be started after creation. If `false`, then the container is only created. Defaults to `true`. diff --git a/docs/resources/registry_image.md b/docs/resources/registry_image.md index f80928c2..614c3d43 100644 --- a/docs/resources/registry_image.md +++ b/docs/resources/registry_image.md @@ -3,13 +3,12 @@ page_title: "docker_registry_image Resource - terraform-provider-docker" subcategory: "" description: |- - Manages the lifecycle of docker image/tag in a registry. + Manages the lifecycle of docker image/tag in a registry means it can store one or more version of specific docker images and identified by their tags. --- # docker_registry_image (Resource) -Manages the lifecycle of docker image/tag in a registry means it can store one or more version -of specific docker images and identified by their tags. +Manages the lifecycle of docker image/tag in a registry means it can store one or more version of specific docker images and identified by their tags. ## Example Usage diff --git a/internal/provider/resource_docker_container.go b/internal/provider/resource_docker_container.go index 82ec89b2..08106d32 100644 --- a/internal/provider/resource_docker_container.go +++ b/internal/provider/resource_docker_container.go @@ -44,7 +44,7 @@ func resourceDockerContainer() *schema.Resource { "rm": { Type: schema.TypeBool, - Description: "If `true`, then the container will be automatically removed after his execution. Terraform won't check this container after creation. Defaults to `false`.", + Description: "If `true`, then the container will be automatically removed when it exits. Defaults to `false`.", Default: false, Optional: true, }, diff --git a/internal/provider/resource_docker_container_funcs.go b/internal/provider/resource_docker_container_funcs.go index 3cfb29e1..81ae6c6e 100644 --- a/internal/provider/resource_docker_container_funcs.go +++ b/internal/provider/resource_docker_container_funcs.go @@ -824,32 +824,39 @@ func resourceDockerContainerUpdate(ctx context.Context, d *schema.ResourceData, func resourceDockerContainerDelete(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics { client := meta.(*ProviderConfig).DockerClient - if d.Get("rm").(bool) { - d.SetId("") - return nil - } - if !d.Get("attach").(bool) { // Stop the container before removing if destroy_grace_seconds is defined + var timeout time.Duration if d.Get("destroy_grace_seconds").(int) > 0 { - timeout := time.Duration(int32(d.Get("destroy_grace_seconds").(int))) * time.Second + timeout = time.Duration(int32(d.Get("destroy_grace_seconds").(int))) * time.Second + } - if err := client.ContainerStop(ctx, d.Id(), &timeout); err != nil { - return diag.Errorf("Error stopping container %s: %s", d.Id(), err) - } + log.Printf("[INFO] Stopping Container '%s' with timeout %v", d.Id(), timeout) + if err := client.ContainerStop(ctx, d.Id(), &timeout); err != nil { + return diag.Errorf("Error stopping container %s: %s", d.Id(), err) } } removeOpts := types.ContainerRemoveOptions{ RemoveVolumes: d.Get("remove_volumes").(bool), + RemoveLinks: d.Get("rm").(bool), Force: true, } + log.Printf("[INFO] Removing Container '%s'", d.Id()) if err := client.ContainerRemove(ctx, d.Id(), removeOpts); err != nil { - return diag.Errorf("Error deleting container %s: %s", d.Id(), err) + if !containsIgnorableErrorMessage(err.Error(), "No such container", "is already in progress") { + return diag.Errorf("Error deleting container %s: %s", d.Id(), err) + } } - waitOkC, errorC := client.ContainerWait(ctx, d.Id(), container.WaitConditionRemoved) + waitCondition := container.WaitConditionNotRunning + if d.Get("rm").(bool) { + waitCondition = container.WaitConditionRemoved + } + + log.Printf("[INFO] Waiting for Container '%s' with condition '%s'", d.Id(), waitCondition) + waitOkC, errorC := client.ContainerWait(ctx, d.Id(), waitCondition) select { case waitOk := <-waitOkC: log.Printf("[INFO] Container exited with code [%v]: '%s'", waitOk.StatusCode, d.Id()) @@ -857,6 +864,7 @@ func resourceDockerContainerDelete(ctx context.Context, d *schema.ResourceData, if !containsIgnorableErrorMessage(err.Error(), "No such container", "is already in progress") { return diag.Errorf("Error waiting for container removal '%s': %s", d.Id(), err) } + log.Printf("[INFO] Waiting for Container '%s' errord: '%s'", d.Id(), err.Error()) } d.SetId("") diff --git a/internal/provider/resource_docker_container_test.go b/internal/provider/resource_docker_container_test.go index c1b6d8b3..53636ff3 100644 --- a/internal/provider/resource_docker_container_test.go +++ b/internal/provider/resource_docker_container_test.go @@ -1730,7 +1730,9 @@ func testAccContainerWaitConditionRemoved(ctx context.Context, n string, ct *typ select { case err := <-errC: if err != nil { - return fmt.Errorf("Container has not been removed") + if !containsIgnorableErrorMessage(err.Error(), "No such container", "is already in progress") { + return fmt.Errorf("Container has not been removed: '%s'", err.Error()) + } } case <-statusC: } diff --git a/internal/provider/resource_docker_registry_image.go b/internal/provider/resource_docker_registry_image.go index 2348b79c..baefd09c 100644 --- a/internal/provider/resource_docker_registry_image.go +++ b/internal/provider/resource_docker_registry_image.go @@ -8,7 +8,7 @@ import ( func resourceDockerRegistryImage() *schema.Resource { return &schema.Resource{ - Description: "Manages the lifecycle of docker image/tag in a registry.", + Description: "Manages the lifecycle of docker image/tag in a registry means it can store one or more version of specific docker images and identified by their tags.", CreateContext: resourceDockerRegistryImageCreate, ReadContext: resourceDockerRegistryImageRead, diff --git a/templates/resources/registry_image.md.tmpl b/templates/resources/registry_image.md.tmpl index 8b807b13..3e43ffe1 100644 --- a/templates/resources/registry_image.md.tmpl +++ b/templates/resources/registry_image.md.tmpl @@ -12,6 +12,8 @@ description: |- ## Example Usage +To be able to update an image itself when an updated image arrives. + {{tffile "examples/resources/docker_registry_image/resource.tf"}} {{ .SchemaMarkdown | trimspace }} \ No newline at end of file