From 576346f91655a96653ad4459c5d2142e6f789a53 Mon Sep 17 00:00:00 2001 From: Ellis Clayton Date: Sat, 2 May 2020 12:29:59 +1000 Subject: [PATCH] feat: Expose IPv6 properties as attributes Docker IPv6 addresses can be set automatically, provided the Docker network in use is set up for it. In this situation, it can be useful to be able to access the IPv6 properties as attributes. Resolves https://github.com/terraform-providers/terraform-provider-docker/issues/265 --- docker/resource_docker_container.go | 24 +++++++++++++++++++++++ docker/resource_docker_container_funcs.go | 3 +++ docker/resource_docker_container_test.go | 4 ++++ 3 files changed, 31 insertions(+) diff --git a/docker/resource_docker_container.go b/docker/resource_docker_container.go index 7806a33e..156caee6 100644 --- a/docker/resource_docker_container.go +++ b/docker/resource_docker_container.go @@ -513,6 +513,18 @@ func resourceDockerContainer() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "global_ipv6_address": { + Type: schema.TypeString, + Computed: true, + }, + "global_ipv6_prefix_length": { + Type: schema.TypeInt, + Computed: true, + }, + "ipv6_gateway": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, @@ -1291,6 +1303,18 @@ func resourceDockerContainerV1() *schema.Resource { Type: schema.TypeString, Computed: true, }, + "global_ipv6_address": { + Type: schema.TypeString, + Computed: true, + }, + "global_ipv6_prefix_length": { + Type: schema.TypeInt, + Computed: true, + }, + "ipv6_gateway": { + Type: schema.TypeString, + Computed: true, + }, }, }, }, diff --git a/docker/resource_docker_container_funcs.go b/docker/resource_docker_container_funcs.go index 3164122a..338947bc 100644 --- a/docker/resource_docker_container_funcs.go +++ b/docker/resource_docker_container_funcs.go @@ -845,6 +845,9 @@ func flattenContainerNetworks(in *types.NetworkSettings) []interface{} { m["ip_address"] = networkData.IPAddress m["ip_prefix_length"] = networkData.IPPrefixLen m["gateway"] = networkData.Gateway + m["global_ipv6_address"] = networkData.GlobalIPv6Address + m["global_ipv6_prefix_length"] = networkData.GlobalIPv6PrefixLen + m["ipv6_gateway"] = networkData.IPv6Gateway out = append(out, m) } return out diff --git a/docker/resource_docker_container_test.go b/docker/resource_docker_container_test.go index d17c7026..982649ba 100644 --- a/docker/resource_docker_container_test.go +++ b/docker/resource_docker_container_test.go @@ -1449,6 +1449,9 @@ func TestAccDockerContainer_ipv6address(t *testing.T) { testAccContainerRunning("docker_container.foo", &c), testCheck, resource.TestCheckResourceAttr("docker_container.foo", "name", "tf-test"), + resource.TestCheckResourceAttr("docker_container.foo", "network_data.0.global_ipv6_address", "fd00:0:0:0::123"), + resource.TestCheckResourceAttr("docker_container.foo", "network_data.0.global_ipv6_prefix_length", "64"), + resource.TestCheckResourceAttr("docker_container.foo", "network_data.0.ipv6_gateway", "fd00:0:0:0::f"), ), }, }, @@ -2138,6 +2141,7 @@ resource "docker_network" "test" { ipv6 = true ipam_config { subnet = "fd00::1/64" + gateway = "fd00:0:0:0::f" } } resource "docker_image" "foo" {