Skip to content

Commit

Permalink
Fix for ER bandwidth reduction issue #3983
Browse files Browse the repository at this point in the history
Reduction in bandwidth forces new resource, utilizing CustomizeDiff
  • Loading branch information
Christian Pearce authored and tombuildsstuff committed May 7, 2020
1 parent e451b11 commit 594a8fa
Show file tree
Hide file tree
Showing 9 changed files with 308 additions and 0 deletions.
Expand Up @@ -6,6 +6,7 @@ import (
"time"

"github.com/Azure/azure-sdk-for-go/services/network/mgmt/2019-09-01/network"
"github.com/hashicorp/terraform-plugin-sdk/helper/customdiff"
"github.com/hashicorp/terraform-plugin-sdk/helper/schema"
"github.com/hashicorp/terraform-plugin-sdk/helper/validation"
"github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure"
Expand All @@ -31,6 +32,13 @@ func resourceArmExpressRouteCircuit() *schema.Resource {
State: schema.ImportStatePassthrough,
},

CustomizeDiff: customdiff.Sequence(
// If bandwidth is reduced force a new resource
customdiff.ForceNewIfChange("bandwidth_in_mbps", func(old, new, meta interface{}) bool {
return new.(int) < old.(int)
}),
),

Timeouts: &schema.ResourceTimeout{
Create: schema.DefaultTimeout(30 * time.Minute),
Read: schema.DefaultTimeout(5 * time.Minute),
Expand Down
Expand Up @@ -28,6 +28,7 @@ func TestAccAzureRMExpressRouteCircuit(t *testing.T) {
"allowClassicOperationsUpdate": testAccAzureRMExpressRouteCircuit_allowClassicOperationsUpdate,
"requiresImport": testAccAzureRMExpressRouteCircuit_requiresImport,
"data_basic": testAccDataSourceAzureRMExpressRoute_basicMetered,
"bandwidthReduction": testAccAzureRMExpressRouteCircuit_bandwidthReduction,
},
"PrivatePeering": {
"azurePrivatePeering": testAccAzureRMExpressRouteCircuitPeering_azurePrivatePeering,
Expand Down Expand Up @@ -273,6 +274,33 @@ func testAccAzureRMExpressRouteCircuit_allowClassicOperationsUpdate(t *testing.T
})
}

func testAccAzureRMExpressRouteCircuit_bandwidthReduction(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_express_route_circuit", "test")
var erc network.ExpressRouteCircuit

resource.Test(t, resource.TestCase{
PreCheck: func() { acceptance.PreCheck(t) },
Providers: acceptance.SupportedProviders,
CheckDestroy: testCheckAzureRMExpressRouteCircuitDestroy,
Steps: []resource.TestStep{
{
Config: testAccAzureRMExpressRouteCircuit_bandwidthReductionConfig(data, "100"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc),
resource.TestCheckResourceAttr(data.ResourceName, "bandwidth_in_mbps", "100"),
),
},
{
Config: testAccAzureRMExpressRouteCircuit_bandwidthReductionConfig(data, "50"),
Check: resource.ComposeTestCheckFunc(
testCheckAzureRMExpressRouteCircuitExists("azurerm_express_route_circuit.test", &erc),
resource.TestCheckResourceAttr(data.ResourceName, "bandwidth_in_mbps", "50"),
),
},
},
})
}

func testCheckAzureRMExpressRouteCircuitExists(resourceName string, erc *network.ExpressRouteCircuit) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[resourceName]
Expand Down Expand Up @@ -528,3 +556,37 @@ resource "azurerm_express_route_circuit" "test" {
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, allowClassicOperations)
}

func testAccAzureRMExpressRouteCircuit_bandwidthReductionConfig(data acceptance.TestData, bandwidth string) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-%d"
location = "%s"
}
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 = %s
sku {
tier = "Standard"
family = "MeteredData"
}
allow_classic_operations = false
tags = {
Environment = "production"
Purpose = "AcceptanceTests"
}
}
`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, bandwidth)
}

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

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

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

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

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

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

1 change: 1 addition & 0 deletions vendor/modules.txt
Expand Up @@ -246,6 +246,7 @@ github.com/hashicorp/logutils
github.com/hashicorp/terraform-config-inspect/tfconfig
# github.com/hashicorp/terraform-plugin-sdk v1.6.0
github.com/hashicorp/terraform-plugin-sdk/helper/acctest
github.com/hashicorp/terraform-plugin-sdk/helper/customdiff
github.com/hashicorp/terraform-plugin-sdk/helper/hashcode
github.com/hashicorp/terraform-plugin-sdk/helper/logging
github.com/hashicorp/terraform-plugin-sdk/helper/mutexkv
Expand Down

0 comments on commit 594a8fa

Please sign in to comment.