Skip to content

Commit

Permalink
provider/openstack: Enable DHCP By Default
Browse files Browse the repository at this point in the history
The openstack_networking_subnet_v2 resource was originally designed
to have DHCP disabled by default; however, a bug in the original
implementation caused DHCP to always be enabled and never be
disabled. This bug was fixed in hashicorp#6052.

Recent discussions have shown that users prefer if DHCP is enabled
by default. This commit implements makes the change.
  • Loading branch information
jtopjian authored and cristicalin committed May 24, 2016
1 parent 211a41a commit eaa8c56
Show file tree
Hide file tree
Showing 3 changed files with 35 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func resourceNetworkingSubnetV2() *schema.Resource {
Type: schema.TypeBool,
Optional: true,
ForceNew: false,
Computed: true,
Default: true,
},
"dns_nameservers": &schema.Schema{
Type: schema.TypeSet,
Expand Down Expand Up @@ -188,7 +188,6 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("tenant_id", s.TenantID)
d.Set("allocation_pools", s.AllocationPools)
d.Set("gateway_ip", s.GatewayIP)
d.Set("enable_dhcp", s.EnableDHCP)
d.Set("dns_nameservers", s.DNSNameservers)
d.Set("host_routes", s.HostRoutes)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ func TestAccNetworkingV2Subnet_basic(t *testing.T) {
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "name", "tf-test-subnet"),
resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "gateway_ip", "192.168.199.1"),
resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "false"),
resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "true"),
),
},
},
Expand All @@ -55,6 +55,25 @@ func TestAccNetworkingV2Subnet_enableDHCP(t *testing.T) {
})
}

func TestAccNetworkingV2Subnet_disableDHCP(t *testing.T) {
var subnet subnets.Subnet

resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckNetworkingV2SubnetDestroy,
Steps: []resource.TestStep{
resource.TestStep{
Config: testAccNetworkingV2Subnet_disableDHCP,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet),
resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "false"),
),
},
},
})
}

func TestAccNetworkingV2Subnet_noGateway(t *testing.T) {
var subnet subnets.Subnet

Expand Down Expand Up @@ -184,6 +203,19 @@ var testAccNetworkingV2Subnet_enableDHCP = fmt.Sprintf(`
enable_dhcp = true
}`)

var testAccNetworkingV2Subnet_disableDHCP = fmt.Sprintf(`
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
admin_state_up = "true"
}
resource "openstack_networking_subnet_v2" "subnet_1" {
name = "tf-test-subnet"
network_id = "${openstack_networking_network_v2.network_1.id}"
cidr = "192.168.199.0/24"
enable_dhcp = false
}`)

var testAccNetworkingV2Subnet_noGateway = fmt.Sprintf(`
resource "openstack_networking_network_v2" "network_1" {
name = "network_1"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ The following arguments are supported:

* `enable_dhcp` - (Optional) The administrative state of the network.
Acceptable values are "true" and "false". Changing this value enables or
disables the DHCP capabilities of the existing subnet.
disables the DHCP capabilities of the existing subnet. Defaults to true.

* `dns_nameservers` - (Optional) An array of DNS name server names used by hosts
in this subnet. Changing this updates the DNS name servers for the existing
Expand Down

0 comments on commit eaa8c56

Please sign in to comment.