Skip to content

Commit

Permalink
Adding route_filter_id for azurerm_express_route_circuit_peering
Browse files Browse the repository at this point in the history
Last update for hashicorp#1083.  The tests are all set to lowercase.  Assuming it is an expense issue.
The test was run successfully for TestAccAzureRMExpressRouteCircuitPeering_microsoftPeeringWithRouteFilter.

=== RUN   TestAccAzureRMExpressRouteCircuitPeering_microsoftPeeringWithRouteFilter
--- PASS: TestAccAzureRMExpressRouteCircuitPeering_microsoftPeeringWithRouteFilter (372.94s)
PASS
ok      github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/network/tests       375.315
  • Loading branch information
Christian Pearce committed Apr 2, 2020
1 parent 179f642 commit cbd15ac
Show file tree
Hide file tree
Showing 3 changed files with 101 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,12 @@ func resourceArmExpressRouteCircuitPeering() *schema.Resource {
Type: schema.TypeString,
Computed: true,
},

"route_filter_id": {
Type: schema.TypeString,
Optional: true,
ValidateFunc: azure.ValidateResourceID,
},
},
}
}
Expand Down Expand Up @@ -150,6 +156,7 @@ func resourceArmExpressRouteCircuitPeeringCreateUpdate(d *schema.ResourceData, m
vlanId := d.Get("vlan_id").(int)
azureASN := d.Get("azure_asn").(int)
peerASN := d.Get("peer_asn").(int)
route_filter_id := d.Get("route_filter_id").(string)

parameters := network.ExpressRouteCircuitPeering{
ExpressRouteCircuitPeeringPropertiesFormat: &network.ExpressRouteCircuitPeeringPropertiesFormat{
Expand All @@ -171,6 +178,16 @@ func resourceArmExpressRouteCircuitPeeringCreateUpdate(d *schema.ResourceData, m

peeringConfig := expandExpressRouteCircuitPeeringMicrosoftConfig(peerings)
parameters.ExpressRouteCircuitPeeringPropertiesFormat.MicrosoftPeeringConfig = peeringConfig

if route_filter_id != "" {
parameters.ExpressRouteCircuitPeeringPropertiesFormat.RouteFilter = &network.SubResource{
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`")
}
}

future, err := client.CreateOrUpdate(ctx, resourceGroup, circuitName, peeringType, parameters)
Expand Down Expand Up @@ -226,6 +243,7 @@ func resourceArmExpressRouteCircuitPeeringRead(d *schema.ResourceData, meta inte
d.Set("primary_peer_address_prefix", props.PrimaryPeerAddressPrefix)
d.Set("secondary_peer_address_prefix", props.SecondaryPeerAddressPrefix)
d.Set("vlan_id", props.VlanID)
d.Set("route_filter_id", props.RouteFilter.ID)

config := flattenExpressRouteCircuitPeeringMicrosoftConfig(props.MicrosoftPeeringConfig)
if err := d.Set("microsoft_peering_config", config); err != nil {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,28 @@ func testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeeringWithCircuitUpda
})
}

func testAccAzureRMExpressRouteCircuitPeering_microsoftPeeringWithRouteFilter(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit_peering", "test")

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMExpressRouteCircuitPeeringDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMExpressRouteCircuitPeering_msPeeringWithRouteFilter(data),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMExpressRouteCircuitPeeringExists(data.ResourceName),
resource.TestCheckResourceAttr(data.ResourceName, "peering_type", "MicrosoftPeering"),
resource.TestCheckResourceAttr(data.ResourceName, "microsoft_peering_config.#", "1"),
resource.TestCheckResourceAttrSet(data.ResourceName, "route_filter_id"),
),
},
data.ImportStep(),
},
})
}

func testCheckAzureRMExpressRouteCircuitPeeringExists(resourceName string) resource.TestCheckFunc {
return func(s *terraform.State) error {
client := acceptance.AzureProvider.Meta().(*clients.Client).Network.ExpressRoutePeeringsClient
Expand Down Expand Up @@ -314,3 +336,63 @@ resource "azurerm_express_route_circuit_peering" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger)
}

func testAccAzureRMExpressRouteCircuitPeering_msPeeringWithRouteFilter(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
resource "azurerm_route_filter" "test" {
name = "acctestrf%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
rule {
name = "acctestrule%d"
access = "Allow"
rule_type = "Community"
communities = ["12076:52005","12076:52006"]
}
}
resource "azurerm_express_route_circuit" "test" {
name = "acctest-erc-%d"
location = azurerm_resource_group.test.location
resource_group_name = azurerm_resource_group.test.name
service_provider_name = "Equinix"
peering_location = "Silicon Valley"
bandwidth_in_mbps = 50
sku {
tier = "Premium"
family = "MeteredData"
}
tags = {
Environment = "production"
Purpose = "AcceptanceTests"
}
}
resource "azurerm_express_route_circuit_peering" "test" {
peering_type = "MicrosoftPeering"
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"
vlan_id = 300
route_filter_id = azurerm_route_filter.test.id
microsoft_peering_config {
advertised_public_prefixes = ["123.1.0.0/24"]
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger, data.RandomInteger)
}
1 change: 1 addition & 0 deletions website/docs/r/express_route_circuit_peering.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ The following arguments are supported:
* `shared_key` - (Optional) The shared key. Can be a maximum of 25 characters.
* `peer_asn` - (Optional) The Either a 16-bit or a 32-bit ASN. Can either be public or private..
* `microsoft_peering_config` - (Optional) A `microsoft_peering_config` block as defined below. Required when `peering_type` is set to `MicrosoftPeering`.
* `route_filter_id` - (Optional) The ID of the Route Filter. Only available when `peering_type` is set to `MicrosoftPeering`.

---

Expand Down

0 comments on commit cbd15ac

Please sign in to comment.