Skip to content

Commit

Permalink
add beta version tag
Browse files Browse the repository at this point in the history
  • Loading branch information
akshat-jindal-nit committed Oct 1, 2024
1 parent 3a4a356 commit b72ed38
Show file tree
Hide file tree
Showing 4 changed files with 87 additions and 45 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "google_compute_network" "{{$.PrimaryResourceId}}" {
provider = google-beta
project = "{{index $.TestEnvVars "project"}}"
name = "{{index $.Vars "network_name"}}"
routing_mode = "GLOBAL"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
resource "google_compute_network" "{{$.PrimaryResourceId}}" {
provider = google-beta
project = "{{index $.TestEnvVars "project"}}"
name = "{{index $.Vars "network_name"}}"
routing_mode = "GLOBAL"
Expand Down
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
resource "google_compute_network" "{{$.PrimaryResourceId}}" {
provider = google-beta
project = "{{index $.TestEnvVars "project"}}"
name = "{{index $.Vars "network_name"}}"
routing_mode = "GLOBAL"
bgp_best_path_selection_mode = "STANDARD"
bgp_always_compare_med = true
bgp_inter_region_cost = ADD_COST_TO_MED
bgp_inter_region_cost = "ADD_COST_TO_MED"
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,30 +122,29 @@ func TestAccComputeNetwork_bgpBestPathSelectionModeAndUpdate(t *testing.T) {

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_best_bgp_path_selection_mode(networkName, "LEGACY"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.acc_network_bgp_best_path_selection_mode", &network),
resource.TestCheckResourceAttr(
"google_compute_network.acc_network_bgp_best_path_selection_mode", "RoutingConfig.BgpBestPathSelectionMode", "LEGACY"),
),
},
// Test updating the best bgp path selection field (only updatable field).
{
Config: testAccComputeNetwork_best_bgp_path_selection_mode(networkName, "STANDARD"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.acc_network_bgp_best_path_selection_mode", &network),
resource.TestCheckResourceAttr(
"google_compute_network.acc_network_bgp_best_path_selection_mode", "RoutingConfig.BgpBestPathSelectionMode", "STANDARD"),
),
Config: testAccComputeNetwork_best_bgp_path_selection_mode(networkName, "LEGACY"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.acc_network_bgp_best_path_selection_mode", &network),
testAccCheckComputeNetworkHasBgpBestPathSelectionMode(t, "google_compute_network.acc_network_bgp_best_path_selection_mode", &network, "LEGACY"),
),
},
// Test updating the best bgp path selection field (only updatable field).
{
Config: testAccComputeNetwork_best_bgp_path_selection_mode(networkName, "STANDARD"),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.acc_network_bgp_best_path_selection_mode", &network),
testAccCheckComputeNetworkHasBgpBestPathSelectionMode(t, "google_compute_network.acc_network_bgp_best_path_selection_mode", &network, "STANDARD"),
),
},
},
},
})
)
}


Expand All @@ -158,7 +157,7 @@ func TestAccComputeNetwork_bgpAlwaysCompareMedAndUpdate(t *testing.T) {

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -194,7 +193,7 @@ func TestAccComputeNetwork_bgpInterRegionCostAndUpdate(t *testing.T) {

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -278,30 +277,29 @@ func TestAccComputeNetwork_default_routing_mode(t *testing.T) {

{{ if ne $.TargetVersionName `ga` -}}
func TestAccComputeNetwork_default_bgp_best_path_selection_mode(t *testing.T) {
t.Parallel()
t.Parallel()

var network compute.Network
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-bgp-best-path-selection-default-routes-%s", suffixName)
var network compute.Network
suffixName := acctest.RandString(t, 10)
networkName := fmt.Sprintf("tf-test-bgp-best-path-selection-default-routes-%s", suffixName)

expectedBgpBestPathSelection := "LEGACY"
expectedBgpBestPathSelection := "LEGACY"

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeNetwork_basic(networkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.bar", &network),
resource.TestCheckResourceAttr(
"google_compute_network.acc_network_bgp_best_path_selection_mode", "RoutingConfig.BgpBestPathSelectionMode", expectedBgpBestPathSelection),
),
},
},
})
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeBetaNetwork_basic(networkName),
Check: resource.ComposeTestCheckFunc(
testAccCheckComputeNetworkExists(
t, "google_compute_network.bar", &network),
testAccCheckComputeNetworkHasBgpBestPathSelectionMode(t, "google_compute_network.bar", &network, expectedBgpBestPathSelection),
),
},
},
})
}


Expand All @@ -316,7 +314,7 @@ func TestAccComputeNetwork_default_bgp_always_compare_med(t *testing.T) {

acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
ProtoV5ProviderFactories: acctest.ProtoV5ProviderBetaFactories(t),
CheckDestroy: testAccCheckComputeNetworkDestroyProducer(t),
Steps: []resource.TestStep{
{
Expand Down Expand Up @@ -539,6 +537,35 @@ func testAccCheckComputeNetworkHasRoutingMode(t *testing.T, n string, network *c
}

{{ if ne $.TargetVersionName `ga` -}}
func testAccCheckComputeNetworkHasBgpBestPathSelectionMode(t *testing.T, n string, network *compute.Network, bgpBestPathSelectionMode string) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)

rs, ok := s.RootModule().Resources[n]
if !ok {
return fmt.Errorf("Not found: %s", n)
}

if rs.Primary.Attributes["bgp_always_compare_med"] == "" {
return fmt.Errorf("BGP always compare med not found on resource")
}

found, err := config.NewComputeClient(config.UserAgent).Networks.Get(
config.Project, network.Name).Do()
if err != nil {
return err
}

foundBgpBestPathSelectionMode := found.RoutingConfig.BgpBestPathSelectionMode

if bgpBestPathSelectionMode != foundBgpBestPathSelectionMode {
return fmt.Errorf("Expected BGP always compare med %s to match actual BGP always compare med %s", bgpBestPathSelectionMode, foundBgpBestPathSelectionMode)
}

return nil
}
}

func testAccCheckComputeNetworkHasBgpAlwaysCompareMed(t *testing.T, n string, network *compute.Network, bgpAlwaysCompareMed bool) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)
Expand Down Expand Up @@ -568,7 +595,6 @@ func testAccCheckComputeNetworkHasBgpAlwaysCompareMed(t *testing.T, n string, ne
}
}


func testAccCheckComputeNetworkHasBgpInterRegionCost(t *testing.T, n string, network *compute.Network, bgpInterRegionCost string) resource.TestCheckFunc {
return func(s *terraform.State) error {
config := acctest.GoogleProviderConfig(t)
Expand Down Expand Up @@ -665,9 +691,20 @@ resource "google_compute_network" "acc_network_routing_mode" {
}

{{ if ne $.TargetVersionName `ga` -}}
func testAccComputeBetaNetwork_basic(networkName string) string {
return fmt.Sprintf(`
resource "google_compute_network" "bar" {
provider = google-beta
name = "%s"
auto_create_subnetworks = true
}
`, networkName)
}

func testAccComputeNetwork_best_bgp_path_selection_mode(networkName, bgpBestPathSelection string) string {
return fmt.Sprintf(`
resource "google_compute_network" "acc_network_bgp_best_path_selection_mode" {
provider = google-beta
name = "%s"
routing_mode = "GLOBAL"
bgp_best_path_selection_mode = "%s"
Expand All @@ -678,6 +715,7 @@ resource "google_compute_network" "acc_network_bgp_best_path_selection_mode" {
func testAccComputeNetwork_bgp_always_compare_med(networkName string, bgpAlwaysComapreMed bool) string {
return fmt.Sprintf(`
resource "google_compute_network" "acc_network_bgp_always_compare_med" {
provider = google-beta
name = "%s"
routing_mode = "GLOBAL"
bgp_best_path_selection_mode = "STANDARD"
Expand All @@ -689,6 +727,7 @@ resource "google_compute_network" "acc_network_bgp_always_compare_med" {
func testAccComputeNetwork_bgp_inter_region_cost(networkName, bgpInterRegionCost string) string {
return fmt.Sprintf(`
resource "google_compute_network" "acc_network_bgp_inter_region_cost" {
provider = google-beta
name = "%s"
routing_mode = "GLOBAL"
bgp_best_path_selection_mode = "STANDARD"
Expand Down

0 comments on commit b72ed38

Please sign in to comment.