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/openstack: Fix Disabling DHCP on Subnets #6052

Merged
merged 1 commit into from
Apr 8, 2016
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
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,8 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
return fmt.Errorf("Error creating OpenStack networking client: %s", err)
}

enableDHCP := d.Get("enable_dhcp").(bool)

createOpts := subnets.CreateOpts{
NetworkID: d.Get("network_id").(string),
CIDR: d.Get("cidr").(string),
Expand All @@ -127,11 +129,7 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
IPVersion: d.Get("ip_version").(int),
DNSNameservers: resourceSubnetDNSNameserversV2(d),
HostRoutes: resourceSubnetHostRoutesV2(d),
}

if raw, ok := d.GetOk("enable_dhcp"); ok {
value := raw.(bool)
createOpts.EnableDHCP = &value
EnableDHCP: &enableDHCP,
}

log.Printf("[DEBUG] Create Options: %#v", createOpts)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,26 @@ 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"),
),
},
},
})
}

func TestAccNetworkingV2Subnet_enableDHCP(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_enableDHCP,
Check: resource.ComposeTestCheckFunc(
testAccCheckNetworkingV2SubnetExists(t, "openstack_networking_subnet_v2.subnet_1", &subnet),
resource.TestCheckResourceAttr("openstack_networking_subnet_v2.subnet_1", "enable_dhcp", "true"),
),
},
},
Expand Down Expand Up @@ -90,28 +110,38 @@ func testAccCheckNetworkingV2SubnetExists(t *testing.T, n string, subnet *subnet

var testAccNetworkingV2Subnet_basic = fmt.Sprintf(`
resource "openstack_networking_network_v2" "network_1" {
region = "%s"
name = "network_1"
admin_state_up = "true"
}

resource "openstack_networking_subnet_v2" "subnet_1" {
region = "%s"
network_id = "${openstack_networking_network_v2.network_1.id}"
cidr = "192.168.199.0/24"
}`, OS_REGION_NAME, OS_REGION_NAME)
}`)

var testAccNetworkingV2Subnet_update = fmt.Sprintf(`
resource "openstack_networking_network_v2" "network_1" {
region = "%s"
name = "network_1"
admin_state_up = "true"
}

resource "openstack_networking_subnet_v2" "subnet_1" {
region = "%s"
name = "tf-test-subnet"
network_id = "${openstack_networking_network_v2.network_1.id}"
cidr = "192.168.199.0/24"
gateway_ip = "192.168.199.1"
}`, OS_REGION_NAME, OS_REGION_NAME)
}`)

var testAccNetworkingV2Subnet_enableDHCP = 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"
gateway_ip = "192.168.199.1"
enable_dhcp = true
}`)