From 1fc3dac767531e4311fb6514e44acda842d5dcda Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Verdo=C3=AFa?= Date: Tue, 27 Dec 2016 20:41:13 +0100 Subject: [PATCH 1/2] provider/docker: Add network create --internal flag support --- builtin/providers/docker/resource_docker_network.go | 7 +++++++ builtin/providers/docker/resource_docker_network_funcs.go | 5 +++++ .../source/docs/providers/docker/r/network.html.markdown | 2 ++ 3 files changed, 14 insertions(+) diff --git a/builtin/providers/docker/resource_docker_network.go b/builtin/providers/docker/resource_docker_network.go index 4c14b2dea0ba..7279d2eebed0 100644 --- a/builtin/providers/docker/resource_docker_network.go +++ b/builtin/providers/docker/resource_docker_network.go @@ -42,6 +42,13 @@ func resourceDockerNetwork() *schema.Resource { Computed: true, }, + "internal": &schema.Schema{ + Type: schema.TypeBool, + Optional: true, + Computed: true, + ForceNew: true, + }, + "ipam_driver": &schema.Schema{ Type: schema.TypeString, Optional: true, diff --git a/builtin/providers/docker/resource_docker_network_funcs.go b/builtin/providers/docker/resource_docker_network_funcs.go index 61954f4aff86..12eeaa3125e3 100644 --- a/builtin/providers/docker/resource_docker_network_funcs.go +++ b/builtin/providers/docker/resource_docker_network_funcs.go @@ -22,6 +22,9 @@ func resourceDockerNetworkCreate(d *schema.ResourceData, meta interface{}) error if v, ok := d.GetOk("options"); ok { createOpts.Options = v.(map[string]interface{}) } + if v, ok := d.GetOk("internal"); ok { + createOpts.Internal = v.(bool) + } ipamOpts := dc.IPAMOptions{} ipamOptsSet := false @@ -52,6 +55,7 @@ func resourceDockerNetworkCreate(d *schema.ResourceData, meta interface{}) error d.Set("scope", retNetwork.Scope) d.Set("driver", retNetwork.Driver) d.Set("options", retNetwork.Options) + d.Set("internal", retNetwork.Internal) return nil } @@ -74,6 +78,7 @@ func resourceDockerNetworkRead(d *schema.ResourceData, meta interface{}) error { d.Set("scope", retNetwork.Scope) d.Set("driver", retNetwork.Driver) d.Set("options", retNetwork.Options) + d.Set("internal", retNetwork.Internal) return nil } diff --git a/website/source/docs/providers/docker/r/network.html.markdown b/website/source/docs/providers/docker/r/network.html.markdown index 72fe7e859b40..164548b66664 100644 --- a/website/source/docs/providers/docker/r/network.html.markdown +++ b/website/source/docs/providers/docker/r/network.html.markdown @@ -34,6 +34,8 @@ The following arguments are supported: `bridge` driver. * `options` - (Optional, map of strings) Network specific options to be used by the drivers. +* `internal` - (Optional, boolean) Restrict external access to the network. + Defaults to `false`. * `ipam_driver` - (Optional, string) Driver used by the custom IP scheme of the network. * `ipam_config` - (Optional, block) See [IPAM config](#ipam_config) below for From 8a73ba003e1df7e3de0202907d8e4d509894a027 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Laurent=20Verdo=C3=AFa?= Date: Tue, 3 Jan 2017 00:31:32 +0100 Subject: [PATCH 2/2] provider/docker: Add acceptance tests for network --internal flag --- .../docker/resource_docker_network_funcs.go | 4 ++- .../docker/resource_docker_network_test.go | 34 +++++++++++++++++++ 2 files changed, 37 insertions(+), 1 deletion(-) diff --git a/builtin/providers/docker/resource_docker_network_funcs.go b/builtin/providers/docker/resource_docker_network_funcs.go index 12eeaa3125e3..f5ff172b8a46 100644 --- a/builtin/providers/docker/resource_docker_network_funcs.go +++ b/builtin/providers/docker/resource_docker_network_funcs.go @@ -55,7 +55,9 @@ func resourceDockerNetworkCreate(d *schema.ResourceData, meta interface{}) error d.Set("scope", retNetwork.Scope) d.Set("driver", retNetwork.Driver) d.Set("options", retNetwork.Options) - d.Set("internal", retNetwork.Internal) + + // The 'internal' property is not send back when create network + d.Set("internal", createOpts.Internal) return nil } diff --git a/builtin/providers/docker/resource_docker_network_test.go b/builtin/providers/docker/resource_docker_network_test.go index 6e3bb4e3806c..5fe7f8b3e868 100644 --- a/builtin/providers/docker/resource_docker_network_test.go +++ b/builtin/providers/docker/resource_docker_network_test.go @@ -63,3 +63,37 @@ resource "docker_network" "foo" { name = "bar" } ` + +func TestAccDockerNetwork_internal(t *testing.T) { + var n dc.Network + + resource.Test(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + Steps: []resource.TestStep{ + resource.TestStep{ + Config: testAccDockerNetworkInternalConfig, + Check: resource.ComposeTestCheckFunc( + testAccNetwork("docker_network.foobar", &n), + testAccNetworkInternal(&n, true), + ), + }, + }, + }) +} + +func testAccNetworkInternal(network *dc.Network, internal bool) resource.TestCheckFunc { + return func(s *terraform.State) error { + if network.Internal != internal { + return fmt.Errorf("Bad value for attribute 'internal': %t", network.Internal) + } + return nil + } +} + +const testAccDockerNetworkInternalConfig = ` +resource "docker_network" "foobar" { + name = "foobar" + internal = "true" +} +`