Fix no-op in container when all 'ports' blocks are deleted. (#168)

* docker_container Fix no-op when all port blocks are deleted
* Update changelog for v2.1.1
* Closes #167
This commit is contained in:
Sid Verma 2019-08-02 03:46:50 +05:30 committed by Manuel Vogel
parent f02d302323
commit 53f74755e4
3 changed files with 19 additions and 3 deletions

View file

@ -1,4 +1,8 @@
## 2.1.1 (Unreleased)
BUG FIXES
* Fixes 'No changes' for containers when all port blocks have been removed ([#167](https://github.com/terraform-providers/terraform-provider-docker/issues/167))
## 2.1.0 (July 19, 2019)
IMPROVEMENTS

View file

@ -718,6 +718,10 @@ func resourceDockerContainer() *schema.Resource {
func suppressIfPortsDidNotChangeForMigrationV0ToV1() schema.SchemaDiffSuppressFunc {
return func(k, old, new string, d *schema.ResourceData) bool {
if k == "ports.#" && old != new {
log.Printf("[DEBUG] suppress diff ports: old and new don't have the same length")
return false
}
portsOldRaw, portsNewRaw := d.GetChange("ports")
portsOld := portsOldRaw.([]interface{})
portsNew := portsNewRaw.([]interface{})

View file

@ -717,6 +717,14 @@ func TestAccDockerContainer_port(t *testing.T) {
resource.TestCheckResourceAttr("docker_container.foo", "ports.0.external", "32787"),
),
},
{
Config: testAccDockerContainerConfig,
Check: resource.ComposeTestCheckFunc(
testAccContainerRunning("docker_container.foo", &c),
resource.TestCheckResourceAttr("docker_container.foo", "name", "tf-test"),
resource.TestCheckResourceAttr("docker_container.foo", "ports.#", "0"),
),
},
},
})
}