Skip to content

Commit

Permalink
azurerm_express_route_circuit_peering - support for bandwidth_in_gbps…
Browse files Browse the repository at this point in the history
…, express_route_port_id (#12289)

Co-authored-by: neil-yechenwei <[email protected]>
Co-authored-by: xuzhang3 <Zhangxu894765>
  • Loading branch information
xuzhang3 and neil-yechenwei authored Jun 24, 2021
1 parent 27835db commit a3cbbbc
Show file tree
Hide file tree
Showing 5 changed files with 238 additions and 86 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func testAccExpressRouteCircuitAuthorization_basic(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_authorization", "test")
r := ExpressRouteCircuitAuthorizationResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basicConfig(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -36,7 +36,7 @@ func testAccExpressRouteCircuitAuthorization_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_authorization", "test")
r := ExpressRouteCircuitAuthorizationResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.basicConfig(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -56,7 +56,7 @@ func testAccExpressRouteCircuitAuthorization_multiple(t *testing.T) {
r := ExpressRouteCircuitAuthorizationResource{}
secondResourceName := "azurerm_express_route_circuit_authorization.test2"

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.multipleConfig(data),
Check: acceptance.ComposeTestCheckFunc(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ func testAccExpressRouteCircuitPeering_azurePrivatePeering(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.privatePeering(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -37,7 +37,7 @@ func testAccExpressRouteCircuitPeering_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.privatePeering(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -52,7 +52,7 @@ func testAccExpressRouteCircuitPeering_microsoftPeering(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.msPeering(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -69,7 +69,7 @@ func testAccExpressRouteCircuitPeering_microsoftPeeringIpv6(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.msPeeringIpv6(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -84,7 +84,7 @@ func testAccExpressRouteCircuitPeering_microsoftPeeringIpv6CustomerRouting(t *te
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.msPeeringIpv6CustomerRouting(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -99,7 +99,7 @@ func testAccExpressRouteCircuitPeering_microsoftPeeringIpv6WithRouteFilter(t *te
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.msPeeringIpv6WithRouteFilter(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -114,7 +114,7 @@ func testAccExpressRouteCircuitPeering_microsoftPeeringCustomerRouting(t *testin
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.msPeeringCustomerRouting(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -133,7 +133,7 @@ func testAccExpressRouteCircuitPeering_azurePrivatePeeringWithCircuitUpdate(t *t
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.privatePeering(data),
Check: acceptance.ComposeTestCheckFunc(
Expand All @@ -158,7 +158,7 @@ func testAccExpressRouteCircuitPeering_microsoftPeeringWithRouteFilter(t *testin
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")
r := ExpressRouteCircuitPeeringResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
data.ResourceSequentialTest(t, r, []acceptance.TestStep{
{
Config: r.msPeeringWithRouteFilter(data),
Check: acceptance.ComposeTestCheckFunc(
Expand Down Expand Up @@ -330,17 +330,17 @@ resource "azurerm_express_route_circuit_peering" "test" {
express_route_circuit_name = azurerm_express_route_circuit.test.name
resource_group_name = azurerm_resource_group.test.name
peer_asn = 100
primary_peer_address_prefix = "192.168.3.0/30"
secondary_peer_address_prefix = "192.168.4.0/30"
primary_peer_address_prefix = "192.168.7.0/30"
secondary_peer_address_prefix = "192.168.8.0/30"
vlan_id = 300
microsoft_peering_config {
advertised_public_prefixes = ["123.2.0.0/24"]
advertised_public_prefixes = ["123.4.0.0/24"]
}
ipv6 {
primary_peer_address_prefix = "2002:db01::/126"
secondary_peer_address_prefix = "2003:db01::/126"
primary_peer_address_prefix = "2002:db03::/126"
secondary_peer_address_prefix = "2003:db03::/126"
microsoft_peering {
advertised_public_prefixes = ["2002:db01::/126"]
Expand Down Expand Up @@ -385,19 +385,19 @@ resource "azurerm_express_route_circuit_peering" "test" {
express_route_circuit_name = azurerm_express_route_circuit.test.name
resource_group_name = azurerm_resource_group.test.name
peer_asn = 100
primary_peer_address_prefix = "192.168.3.0/30"
secondary_peer_address_prefix = "192.168.4.0/30"
primary_peer_address_prefix = "192.168.9.0/30"
secondary_peer_address_prefix = "192.168.10.0/30"
vlan_id = 300
microsoft_peering_config {
advertised_public_prefixes = ["123.2.0.0/24"]
advertised_public_prefixes = ["123.5.0.0/24"]
}
ipv6 {
primary_peer_address_prefix = "2002:db01::/126"
secondary_peer_address_prefix = "2003:db01::/126"
primary_peer_address_prefix = "2002:db05::/126"
secondary_peer_address_prefix = "2003:db05::/126"
microsoft_peering {
advertised_public_prefixes = ["2002:db01::/126"]
advertised_public_prefixes = ["2002:db05::/126"]
customer_asn = 64511
routing_registry_name = "ARIN"
}
Expand Down Expand Up @@ -454,18 +454,18 @@ resource "azurerm_express_route_circuit_peering" "test" {
express_route_circuit_name = azurerm_express_route_circuit.test.name
resource_group_name = azurerm_resource_group.test.name
peer_asn = 100
primary_peer_address_prefix = "192.168.3.0/30"
secondary_peer_address_prefix = "192.168.4.0/30"
primary_peer_address_prefix = "192.168.11.0/30"
secondary_peer_address_prefix = "192.168.12.0/30"
vlan_id = 300
route_filter_id = azurerm_route_filter.test.id
microsoft_peering_config {
advertised_public_prefixes = ["123.2.0.0/24"]
advertised_public_prefixes = ["123.3.0.0/24"]
}
ipv6 {
primary_peer_address_prefix = "2002:db01::/126"
secondary_peer_address_prefix = "2003:db01::/126"
primary_peer_address_prefix = "2002:db02::/126"
secondary_peer_address_prefix = "2003:db02::/126"
route_filter_id = azurerm_route_filter.test.id
microsoft_peering {
Expand Down Expand Up @@ -513,12 +513,12 @@ resource "azurerm_express_route_circuit_peering" "test" {
express_route_circuit_name = azurerm_express_route_circuit.test.name
resource_group_name = azurerm_resource_group.test.name
peer_asn = 100
primary_peer_address_prefix = "192.168.1.0/30"
secondary_peer_address_prefix = "192.168.2.0/30"
primary_peer_address_prefix = "192.168.3.0/30"
secondary_peer_address_prefix = "192.168.4.0/30"
vlan_id = 300
microsoft_peering_config {
advertised_public_prefixes = ["123.1.0.0/24"]
advertised_public_prefixes = ["123.2.0.0/24"]
// https://tools.ietf.org/html/rfc5398
customer_asn = 64511
routing_registry_name = "ARIN"
Expand Down Expand Up @@ -618,8 +618,8 @@ resource "azurerm_express_route_circuit_peering" "test" {
express_route_circuit_name = azurerm_express_route_circuit.test.name
resource_group_name = azurerm_resource_group.test.name
peer_asn = 100
primary_peer_address_prefix = "192.168.1.0/30"
secondary_peer_address_prefix = "192.168.2.0/30"
primary_peer_address_prefix = "192.168.5.0/30"
secondary_peer_address_prefix = "192.168.6.0/30"
vlan_id = 300
route_filter_id = azurerm_route_filter.test.id
Expand Down
109 changes: 73 additions & 36 deletions azurerm/internal/services/network/express_route_circuit_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@ import (
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/locks"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/parse"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/validate"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tags"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/suppress"
Expand Down Expand Up @@ -55,25 +57,6 @@ func resourceExpressRouteCircuit() *pluginsdk.Resource {

"location": azure.SchemaLocation(),

"service_provider_name": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
},

"peering_location": {
Type: pluginsdk.TypeString,
Required: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
},

"bandwidth_in_mbps": {
Type: pluginsdk.TypeInt,
Required: true,
},

"sku": {
Type: pluginsdk.TypeList,
Required: true,
Expand Down Expand Up @@ -111,6 +94,47 @@ func resourceExpressRouteCircuit() *pluginsdk.Resource {
Default: false,
},

"service_provider_name": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
RequiredWith: []string{"bandwidth_in_mbps", "peering_location"},
ConflictsWith: []string{"bandwidth_in_gbps", "express_route_port_id"},
},

"peering_location": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
DiffSuppressFunc: suppress.CaseDifference,
RequiredWith: []string{"bandwidth_in_mbps", "service_provider_name"},
ConflictsWith: []string{"bandwidth_in_gbps", "express_route_port_id"},
},

"bandwidth_in_mbps": {
Type: pluginsdk.TypeInt,
Optional: true,
RequiredWith: []string{"peering_location", "service_provider_name"},
ConflictsWith: []string{"bandwidth_in_gbps", "express_route_port_id"},
},

"bandwidth_in_gbps": {
Type: pluginsdk.TypeFloat,
Optional: true,
RequiredWith: []string{"express_route_port_id"},
ConflictsWith: []string{"bandwidth_in_mbps", "peering_location", "service_provider_name"},
},

"express_route_port_id": {
Type: pluginsdk.TypeString,
Optional: true,
ForceNew: true,
RequiredWith: []string{"bandwidth_in_gbps"},
ConflictsWith: []string{"bandwidth_in_mbps", "peering_location", "service_provider_name"},
ValidateFunc: validate.ExpressRoutePortID,
},

"service_provider_provisioning_state": {
Type: pluginsdk.TypeString,
Computed: true,
Expand Down Expand Up @@ -154,12 +178,9 @@ func resourceExpressRouteCircuitCreateUpdate(d *pluginsdk.ResourceData, meta int
}

location := azure.NormalizeLocation(d.Get("location").(string))
serviceProviderName := d.Get("service_provider_name").(string)
peeringLocation := d.Get("peering_location").(string)
bandwidthInMbps := int32(d.Get("bandwidth_in_mbps").(int))
sku := expandExpressRouteCircuitSku(d)
allowRdfeOps := d.Get("allow_classic_operations").(bool)
t := d.Get("tags").(map[string]interface{})
allowRdfeOps := d.Get("allow_classic_operations").(bool)
expandedTags := tags.Expand(t)

// There is the potential for the express route circuit to become out of sync when the service provider updates
Expand Down Expand Up @@ -191,24 +212,28 @@ func resourceExpressRouteCircuitCreateUpdate(d *pluginsdk.ResourceData, meta int
erc.Sku = sku
erc.Tags = expandedTags

if erc.ExpressRouteCircuitPropertiesFormat != nil {
if !d.IsNewResource() {
erc.ExpressRouteCircuitPropertiesFormat.AllowClassicOperations = &allowRdfeOps
if erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties != nil {
erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties.ServiceProviderName = &serviceProviderName
erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties.PeeringLocation = &peeringLocation
erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties.BandwidthInMbps = &bandwidthInMbps
}
} else {
erc.ExpressRouteCircuitPropertiesFormat = &network.ExpressRouteCircuitPropertiesFormat{
AllowClassicOperations: &allowRdfeOps,
ServiceProviderProperties: &network.ExpressRouteCircuitServiceProviderProperties{
ServiceProviderName: &serviceProviderName,
PeeringLocation: &peeringLocation,
BandwidthInMbps: &bandwidthInMbps,
},
erc.ExpressRouteCircuitPropertiesFormat = &network.ExpressRouteCircuitPropertiesFormat{}

// ServiceProviderProperties and expressRoutePorts/bandwidthInGbps properties are mutually exclusive
if _, ok := d.GetOk("express_route_port_id"); ok {
erc.ExpressRouteCircuitPropertiesFormat.ExpressRoutePort = &network.SubResource{}
} else {
erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties = &network.ExpressRouteCircuitServiceProviderProperties{}
}
}

if erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties != nil {
erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties.ServiceProviderName = utils.String(d.Get("service_provider_name").(string))
erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties.PeeringLocation = utils.String(d.Get("peering_location").(string))
erc.ExpressRouteCircuitPropertiesFormat.ServiceProviderProperties.BandwidthInMbps = utils.Int32(int32(d.Get("bandwidth_in_mbps").(int)))
} else {
erc.ExpressRouteCircuitPropertiesFormat.ExpressRoutePort.ID = utils.String(d.Get("express_route_port_id").(string))
erc.ExpressRouteCircuitPropertiesFormat.BandwidthInGbps = utils.Float(d.Get("bandwidth_in_gbps").(float64))
}

future, err := client.CreateOrUpdate(ctx, resGroup, name, erc)
if err != nil {
return fmt.Errorf("Error Creating/Updating ExpressRouteCircuit %q (Resource Group %q): %+v", name, resGroup, err)
Expand Down Expand Up @@ -283,6 +308,18 @@ func resourceExpressRouteCircuitRead(d *pluginsdk.ResourceData, meta interface{}
}
}

if resp.ExpressRoutePort != nil {
d.Set("bandwidth_in_gbps", resp.BandwidthInGbps)

if resp.ExpressRoutePort.ID != nil {
portID, err := parse.ExpressRoutePortID(*resp.ExpressRoutePort.ID)
if err != nil {
return err
}
d.Set("express_route_port_id", portID.ID())
}
}

if props := resp.ServiceProviderProperties; props != nil {
d.Set("service_provider_name", props.ServiceProviderName)
d.Set("peering_location", props.PeeringLocation)
Expand Down
Loading

0 comments on commit a3cbbbc

Please sign in to comment.