Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_express_route_circuit - de-provision and re-provision circuit when changing bandwidth reduction (#3983) #6601

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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