Skip to content

Commit

Permalink
Support for Stateless Address Autoconfiguration (SLAAC), Stateful DHC…
Browse files Browse the repository at this point in the history
…Pv6, and Stateless DHCPv6 on a subnet. (#193)

* vendor: Updating Gophercloud

* Adds support for Stateless Address Autoconfiguration (SLAAC), Stateful DHCPv6, and Stateless DHCPv6 on a subnet.

    * ipv6_ra_mode : https://developer.openstack.org/api-ref/network/v2/index.html#create-subnet
    * ipv6_address_mode : https://developer.openstack.org/api-ref/network/v2/index.html#create-subnet

Example:

resource "openstack_networking_subnet_v2" "subnet_ipv6" {
  name                = "terraform-subnet-ipv6"
  network_id          = "${openstack_networking_network_v2.network.id}"
  cidr                = "ffff:c0:1f0:1002::/64"
  ipv6_address_mode   = "slaac"
  ipv6_ra_mode        = "slaac"
  ip_version          = 6
  enable_dhcp         = "true"
  gateway_ip          = "ffff:c0:1f0:1002::1"
}

* Added Validate for resurce ipv6_ra_mode, ipv6_address_mode
  • Loading branch information
stone authored and jtopjian committed Dec 14, 2017
1 parent e197479 commit 74e9770
Show file tree
Hide file tree
Showing 7 changed files with 302 additions and 59 deletions.
24 changes: 24 additions & 0 deletions openstack/data_source_openstack_networking_subnet_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,20 @@ func dataSourceNetworkingSubnetV2() *schema.Resource {
},
},
},
"ipv6_address_mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validateSubnetV2IPv6Mode,
},
"ipv6_ra_mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validateSubnetV2IPv6Mode,
},
},
}
}
Expand Down Expand Up @@ -175,6 +189,14 @@ func dataSourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{})
listOpts.ID = v.(string)
}

if v, ok := d.GetOk("ipv6_address_mode"); ok {
listOpts.IPv6AddressMode = v.(string)
}

if v, ok := d.GetOk("ipv6_ra_mode"); ok {
listOpts.IPv6RAMode = v.(string)
}

pages, err := subnets.List(networkingClient, listOpts).AllPages()
if err != nil {
return fmt.Errorf("Unable to retrieve subnets: %s", err)
Expand Down Expand Up @@ -205,6 +227,8 @@ func dataSourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{})
d.Set("network_id", subnet.NetworkID)
d.Set("cidr", subnet.CIDR)
d.Set("ip_version", subnet.IPVersion)
d.Set("ipv6_address_mode", subnet.IPv6AddressMode)
d.Set("ipv6_ra_mode", subnet.IPv6RAMode)
d.Set("gateway_ip", subnet.GatewayIP)
d.Set("enable_dhcp", subnet.EnableDHCP)
d.Set("region", GetRegion(d, config))
Expand Down
18 changes: 18 additions & 0 deletions openstack/resource_openstack_networking_subnet_v2.go
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,20 @@ func resourceNetworkingSubnetV2() *schema.Resource {
},
},
},
"ipv6_address_mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validateSubnetV2IPv6Mode,
},
"ipv6_ra_mode": &schema.Schema{
Type: schema.TypeString,
Optional: true,
ForceNew: true,
Computed: true,
ValidateFunc: validateSubnetV2IPv6Mode,
},
"value_specs": &schema.Schema{
Type: schema.TypeMap,
Optional: true,
Expand All @@ -144,6 +158,8 @@ func resourceNetworkingSubnetV2Create(d *schema.ResourceData, meta interface{})
CIDR: d.Get("cidr").(string),
Name: d.Get("name").(string),
TenantID: d.Get("tenant_id").(string),
IPv6AddressMode: d.Get("ipv6_address_mode").(string),
IPv6RAMode: d.Get("ipv6_ra_mode").(string),
AllocationPools: resourceSubnetAllocationPoolsV2(d),
DNSNameservers: resourceSubnetDNSNameserversV2(d),
HostRoutes: resourceSubnetHostRoutesV2(d),
Expand Down Expand Up @@ -216,6 +232,8 @@ func resourceNetworkingSubnetV2Read(d *schema.ResourceData, meta interface{}) er
d.Set("host_routes", s.HostRoutes)
d.Set("enable_dhcp", s.EnableDHCP)
d.Set("network_id", s.NetworkID)
d.Set("ipv6_address_mode", s.IPv6AddressMode)
d.Set("ipv6_ra_mode", s.IPv6RAMode)

// Set the allocation_pools
var allocationPools []map[string]interface{}
Expand Down
9 changes: 9 additions & 0 deletions openstack/util.go
Original file line number Diff line number Diff line change
Expand Up @@ -127,3 +127,12 @@ func suppressEquivilentTimeDiffs(k, old, new string, d *schema.ResourceData) boo

return oldTime.Equal(newTime)
}

func validateSubnetV2IPv6Mode(v interface{}, k string) (ws []string, errors []error) {
value := v.(string)
if value != "slaac" && value != "dhcpv6-stateful" && value != "dhcpv6-stateless" {
err := fmt.Errorf("%s must be one of slaac, dhcpv6-stateful or dhcpv6-stateless", k)
errors = append(errors, err)
}
return
}

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Loading

0 comments on commit 74e9770

Please sign in to comment.