Skip to content

Commit

Permalink
Add support ipv6 configuration in azurerm_express_route_circuit_peeri…
Browse files Browse the repository at this point in the history
…ng (#9235)

Co-authored-by: xuzhang3 <Zhangxu894765>
Co-authored-by: jackofallops <[email protected]>
  • Loading branch information
xuzhang3 and jackofallops authored Nov 23, 2020
1 parent 5d83cf5 commit b7ebd5b
Show file tree
Hide file tree
Showing 4 changed files with 429 additions and 12 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -94,11 +94,13 @@ func resourceArmExpressRouteCircuitPeering() *schema.Resource {
Required: true,
Elem: &schema.Schema{Type: schema.TypeString},
},

"customer_asn": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},

"routing_registry_name": {
Type: schema.TypeString,
Optional: true,
Expand All @@ -108,6 +110,63 @@ func resourceArmExpressRouteCircuitPeering() *schema.Resource {
},
},

"ipv6": {
Type: schema.TypeList,
Optional: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"microsoft_peering": {
Type: schema.TypeList,
Required: true,
MaxItems: 1,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"advertised_public_prefixes": {
Type: schema.TypeList,
MinItems: 1,
Optional: true,
Elem: &schema.Schema{
Type: schema.TypeString,
ValidateFunc: validation.IsCIDR,
},
},

"customer_asn": {
Type: schema.TypeInt,
Optional: true,
Default: 0,
},

"routing_registry_name": {
Type: schema.TypeString,
Optional: true,
Default: "NONE",
ValidateFunc: validation.StringIsNotEmpty,
},
},
},
},

"primary_peer_address_prefix": {
Type: schema.TypeString,
Required: true,
},

"secondary_peer_address_prefix": {
Type: schema.TypeString,
Required: true,
},

"route_filter_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
},
},
},
},

"azure_asn": {
Type: schema.TypeInt,
Computed: true,
Expand Down Expand Up @@ -193,8 +252,22 @@ func resourceArmExpressRouteCircuitPeeringCreateUpdate(d *schema.ResourceData, m
ID: utils.String(route_filter_id),
}
}
} else if route_filter_id != "" {
return fmt.Errorf("`route_filter_id` may only be specified when `peering_type` is set to `MicrosoftPeering`")

ipv6Peering := d.Get("ipv6").([]interface{})
ipv6PeeringConfig, err := expandExpressRouteCircuitIpv6PeeringConfig(ipv6Peering)
if err != nil {
return err
}
parameters.ExpressRouteCircuitPeeringPropertiesFormat.Ipv6PeeringConfig = ipv6PeeringConfig
} else {
if route_filter_id != "" {
return fmt.Errorf("`route_filter_id` may only be specified when `peering_type` is set to `MicrosoftPeering`")
}

ipv6Peering := d.Get("ipv6").([]interface{})
if len(ipv6Peering) != 0 {
return fmt.Errorf("`ipv6` may only be specified when `peering_type` is set to `MicrosoftPeering`")
}
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, circuitName, peeringType, parameters)
Expand Down Expand Up @@ -259,7 +332,10 @@ func resourceArmExpressRouteCircuitPeeringRead(d *schema.ResourceData, meta inte

config := flattenExpressRouteCircuitPeeringMicrosoftConfig(props.MicrosoftPeeringConfig)
if err := d.Set("microsoft_peering_config", config); err != nil {
return fmt.Errorf("Error setting `microsoft_peering_config`: %+v", err)
return fmt.Errorf("setting `microsoft_peering_config`: %+v", err)
}
if err := d.Set("ipv6", flattenExpressRouteCircuitIpv6PeeringConfig(props.Ipv6PeeringConfig)); err != nil {
return fmt.Errorf("setting `ipv6`: %+v", err)
}
}

Expand Down Expand Up @@ -302,6 +378,9 @@ func resourceArmExpressRouteCircuitPeeringDelete(d *schema.ResourceData, meta in
}

func expandExpressRouteCircuitPeeringMicrosoftConfig(input []interface{}) *network.ExpressRouteCircuitPeeringConfig {
if len(input) == 0 {
return nil
}
peering := input[0].(map[string]interface{})

prefixes := make([]string, 0)
Expand All @@ -320,6 +399,29 @@ func expandExpressRouteCircuitPeeringMicrosoftConfig(input []interface{}) *netwo
}
}

func expandExpressRouteCircuitIpv6PeeringConfig(input []interface{}) (*network.Ipv6ExpressRouteCircuitPeeringConfig, error) {
if len(input) == 0 {
return nil, nil
}

v := input[0].(map[string]interface{})
peeringConfig := network.Ipv6ExpressRouteCircuitPeeringConfig{
PrimaryPeerAddressPrefix: utils.String(v["primary_peer_address_prefix"].(string)),
SecondaryPeerAddressPrefix: utils.String(v["secondary_peer_address_prefix"].(string)),
MicrosoftPeeringConfig: expandExpressRouteCircuitPeeringMicrosoftConfig(v["microsoft_peering"].([]interface{})),
}
routeFilterId := v["route_filter_id"].(string)
if routeFilterId != "" {
if _, err := ParseRouteFilterID(routeFilterId); err != nil {
return nil, err
}
peeringConfig.RouteFilter = &network.SubResource{
ID: utils.String(routeFilterId),
}
}
return &peeringConfig, nil
}

func flattenExpressRouteCircuitPeeringMicrosoftConfig(input *network.ExpressRouteCircuitPeeringConfig) interface{} {
if input == nil {
return []interface{}{}
Expand All @@ -340,3 +442,30 @@ func flattenExpressRouteCircuitPeeringMicrosoftConfig(input *network.ExpressRout

return []interface{}{config}
}

func flattenExpressRouteCircuitIpv6PeeringConfig(input *network.Ipv6ExpressRouteCircuitPeeringConfig) []interface{} {
if input == nil {
return make([]interface{}, 0)
}

var primaryPeerAddressPrefix string
if input.PrimaryPeerAddressPrefix != nil {
primaryPeerAddressPrefix = *input.PrimaryPeerAddressPrefix
}
var secondaryPeerAddressPrefix string
if input.SecondaryPeerAddressPrefix != nil {
secondaryPeerAddressPrefix = *input.SecondaryPeerAddressPrefix
}
routeFilterId := ""
if input.RouteFilter != nil && input.RouteFilter.ID != nil {
routeFilterId = *input.RouteFilter.ID
}
return []interface{}{
map[string]interface{}{
"microsoft_peering": flattenExpressRouteCircuitPeeringMicrosoftConfig(input.MicrosoftPeeringConfig),
"primary_peer_address_prefix": primaryPeerAddressPrefix,
"secondary_peer_address_prefix": secondaryPeerAddressPrefix,
"route_filter_id": routeFilterId,
},
}
}
Loading

0 comments on commit b7ebd5b

Please sign in to comment.