Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Merged
merged 2 commits into from
Jan 3, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 7 additions & 0 deletions builtin/providers/docker/resource_docker_network.go
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
7 changes: 7 additions & 0 deletions builtin/providers/docker/resource_docker_network_funcs.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
}

Expand All @@ -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
}
Expand Down
34 changes: 34 additions & 0 deletions builtin/providers/docker/resource_docker_network_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
`
2 changes: 2 additions & 0 deletions website/source/docs/providers/docker/r/network.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down