provider/docker: Add network create --internal flag support (#10932)

* provider/docker: Add network create --internal flag support

* provider/docker: Add acceptance tests for network --internal flag
This commit is contained in:
VERDOÏA Laurent 2017-01-03 12:46:16 +01:00 committed by Paul Stack
parent b8c26b622b
commit f8ce2f76e3
4 changed files with 50 additions and 0 deletions

View File

@ -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,

View File

@ -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
@ -53,6 +56,9 @@ func resourceDockerNetworkCreate(d *schema.ResourceData, meta interface{}) error
d.Set("driver", retNetwork.Driver)
d.Set("options", retNetwork.Options)
// The 'internal' property is not send back when create network
d.Set("internal", createOpts.Internal)
return nil
}
@ -74,6 +80,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
}

View File

@ -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"
}
`

View File

@ -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