hashicorp / terraform-provider-docker

As part of our introduction to self-service publishing in the Terraform Registry, this copy of the provider has been archived, and ownership has been transferred to active maintainers in the community. Please see the new location on the Terraform Registry: https://registry.terraform.io/providers/kreuzwerker/docker/latest
https://registry.terraform.io/providers/kreuzwerker/docker/latest
Mozilla Public License 2.0
132 stars 92 forks source link

Replacement triggered for docker network with ipam_config #279

Open project0 opened 4 years ago

project0 commented 4 years ago

I experience strange behavior that it tries to replace my docker network after rebooting the server. Looks like the ipam_config stanza cannot be properly merged and then triggeres the replacement.

Terraform v0.12.28
+ provider.docker v2.7.1
resource "docker_network" "server" {
  name            = local.network_name
  check_duplicate = true

  driver = "bridge"
  ipv6   = true

  ipam_config {
    subnet = var.subnets.ipv4_cidr
  }

  ipam_config {
    subnet = var.subnets.ipv6_cidr
  }
}
  # module.base.docker_network.server must be replaced
-/+ resource "docker_network" "server" {
      - attachable      = false -> null
        check_duplicate = true
        driver          = "bridge"
      ~ id              = "f565f7f1a0db0c184f69c24e8f113ce7d88c12e43ae4bf862b0f51c15940a633" -> (known after apply)
      - ingress         = false -> null
      ~ internal        = false -> (known after apply)
        ipam_driver     = "default"
        ipv6            = true
        name            = "server-vagrant"
      ~ options         = {} -> (known after apply)
      ~ scope           = "local" -> (known after apply)

      - ipam_config { # forces replacement
          - aux_address = {} -> null
          - gateway     = "172.16.10.1" -> null
          - subnet      = "172.16.10.0/24" -> null
        }
      - ipam_config { # forces replacement
          - aux_address = {} -> null
          - gateway     = "2001:1:6d:99f:400::1" -> null
          - subnet      = "2001:1:006d:099f:0100:0000:0000:0000/80" -> null
        }
      + ipam_config { # forces replacement
          + subnet = "172.16.10.0/24"
        }
      + ipam_config { # forces replacement
          + subnet = "2001:1:006d:099f:0100:0000:0000:0000/80"
        }
    }

docker inspect after creation:

    {
        "Name": "server-vagrant",
        "Id": "7347683ef27d04299465172f017fc89b352e7a1546ba50ec2bd7b3223a9721fa",
        "Created": "2020-07-09T16:53:23.763556354Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": true,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.16.10.0/24"
                },
                {
                    "Subnet": "2001:1:006d:099f:0100:0000:0000:0000/80"
                }
            ]
        }
  }

docker inspect after reboot:

    {
        "Name": "server-vagrant",
        "Id": "f565f7f1a0db0c184f69c24e8f113ce7d88c12e43ae4bf862b0f51c15940a633",
        "Created": "2020-07-06T18:43:47.35749164Z",
        "Scope": "local",
        "Driver": "bridge",
        "EnableIPv6": true,
        "IPAM": {
            "Driver": "default",
            "Options": null,
            "Config": [
                {
                    "Subnet": "172.16.10.0/24",
                    "Gateway": "172.16.10.1"
                },
                {
                    "Subnet": "2001:1:006d:099f:0100:0000:0000:0000/80",
                    "Gateway": "2001:1:6d:99f:100::1"
                }
            ]
        }
}
project0 commented 4 years ago

i fixed that by generating the gateway attribute at my own, not sure if this is an expected behavior as the documentation tells its an "optional" parameter.

gateway = cidrhost(var.subnets.ipv4_cidr,1)