From c2319da1aa49ba0d5411181048a395457396d31c Mon Sep 17 00:00:00 2001 From: Stephan Epping Date: Thu, 16 Apr 2015 15:21:14 +0200 Subject: [PATCH 1/4] Add docker container network settings to output attribute --- .../docker/resource_docker_container.go | 20 +++++++++++++++++++ .../docker/resource_docker_container_funcs.go | 6 ++++++ 2 files changed, 26 insertions(+) diff --git a/builtin/providers/docker/resource_docker_container.go b/builtin/providers/docker/resource_docker_container.go index de0b0b667..a3a9b4928 100644 --- a/builtin/providers/docker/resource_docker_container.go +++ b/builtin/providers/docker/resource_docker_container.go @@ -116,6 +116,26 @@ func resourceDockerContainer() *schema.Resource { Elem: &schema.Schema{Type: schema.TypeString}, Set: stringSetHash, }, + + "ip_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + + "ip_prefix_length": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, + + "gateway": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, + + "bridge": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, } } diff --git a/builtin/providers/docker/resource_docker_container_funcs.go b/builtin/providers/docker/resource_docker_container_funcs.go index ae0a6e6bd..d4fd4c9de 100644 --- a/builtin/providers/docker/resource_docker_container_funcs.go +++ b/builtin/providers/docker/resource_docker_container_funcs.go @@ -138,6 +138,12 @@ func resourceDockerContainerRead(d *schema.ResourceData, meta interface{}) error return resourceDockerContainerDelete(d, meta) } + // Read Network Settings + d.Set("ip_address", container.NetworkSettings.IPAddress) + d.Set("ip_prefix_length", container.NetworkSettings.IPPrefixLen) + d.Set("gateway", container.NetworkSettings.Gateway) + d.Set("bridge", container.NetworkSettings.Bridge) + return nil } From 3ded884d95f29b4dad74ddf2ed5326fc4b234df4 Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 20 Apr 2015 12:42:36 -0500 Subject: [PATCH 2/4] provider/docker: guard against nil NetworkSettings --- .../docker/resource_docker_container_funcs.go | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/builtin/providers/docker/resource_docker_container_funcs.go b/builtin/providers/docker/resource_docker_container_funcs.go index d4fd4c9de..c6bd9dea8 100644 --- a/builtin/providers/docker/resource_docker_container_funcs.go +++ b/builtin/providers/docker/resource_docker_container_funcs.go @@ -138,11 +138,13 @@ func resourceDockerContainerRead(d *schema.ResourceData, meta interface{}) error return resourceDockerContainerDelete(d, meta) } - // Read Network Settings - d.Set("ip_address", container.NetworkSettings.IPAddress) - d.Set("ip_prefix_length", container.NetworkSettings.IPPrefixLen) - d.Set("gateway", container.NetworkSettings.Gateway) - d.Set("bridge", container.NetworkSettings.Bridge) + // Read Network Settings + if container.NetworkSettings != nil { + d.Set("ip_address", container.NetworkSettings.IPAddress) + d.Set("ip_prefix_length", container.NetworkSettings.IPPrefixLen) + d.Set("gateway", container.NetworkSettings.Gateway) + d.Set("bridge", container.NetworkSettings.Bridge) + } return nil } From aada41aa55013b22fab2a0d8e4122503d464bc4c Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 20 Apr 2015 12:45:58 -0500 Subject: [PATCH 3/4] docs: provider/docker - network settings attrs --- .../docs/providers/docker/r/container.html.markdown | 13 +++++++++++++ 1 file changed, 13 insertions(+) diff --git a/website/source/docs/providers/docker/r/container.html.markdown b/website/source/docs/providers/docker/r/container.html.markdown index ebeabaa00..d5a4c823e 100644 --- a/website/source/docs/providers/docker/r/container.html.markdown +++ b/website/source/docs/providers/docker/r/container.html.markdown @@ -77,3 +77,16 @@ the following: is coming from. * `read_only` - (Optinal, bool) If true, this volume will be readonly. Defaults to false. + +## Attributes Reference + +The following attributes are exported: + + * `ip_address` - The IP address of the container as read from its + NetworkSettings. + * `ip_prefix_length` - The IP prefix length of the container as read from its + NetworkSettings. + * `gateway` - The network gateway of the container as read from its + NetworkSettings. + * `bridge` - The network bridge of the container as read from its + NetworkSettings. From d55c8d84045f5a537ecc2db1a5c905dba4565b8c Mon Sep 17 00:00:00 2001 From: Paul Hinze Date: Mon, 20 Apr 2015 14:18:46 -0500 Subject: [PATCH 4/4] provider/docker: fmt on container resource --- .../docker/resource_docker_container.go | 32 +++++++++---------- 1 file changed, 16 insertions(+), 16 deletions(-) diff --git a/builtin/providers/docker/resource_docker_container.go b/builtin/providers/docker/resource_docker_container.go index a3a9b4928..10481b268 100644 --- a/builtin/providers/docker/resource_docker_container.go +++ b/builtin/providers/docker/resource_docker_container.go @@ -117,25 +117,25 @@ func resourceDockerContainer() *schema.Resource { Set: stringSetHash, }, - "ip_address": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, + "ip_address": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, - "ip_prefix_length": &schema.Schema{ - Type: schema.TypeInt, - Computed: true, - }, + "ip_prefix_length": &schema.Schema{ + Type: schema.TypeInt, + Computed: true, + }, - "gateway": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, + "gateway": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, - "bridge": &schema.Schema{ - Type: schema.TypeString, - Computed: true, - }, + "bridge": &schema.Schema{ + Type: schema.TypeString, + Computed: true, + }, }, } }