|
| 1 | +// ---------------------------------------------------------------------------- |
| 2 | +// |
| 3 | +// *** AUTO GENERATED CODE *** AUTO GENERATED CODE *** |
| 4 | +// |
| 5 | +// ---------------------------------------------------------------------------- |
| 6 | +// |
| 7 | +// This file is automatically generated by Magic Modules and manual |
| 8 | +// changes will be clobbered when the file is regenerated. |
| 9 | +// |
| 10 | +// Please read more about how to change this file in |
| 11 | +// .github/CONTRIBUTING.md. |
| 12 | +// |
| 13 | +// ---------------------------------------------------------------------------- |
| 14 | + |
| 15 | +package google |
| 16 | + |
| 17 | +import ( |
| 18 | + "fmt" |
| 19 | + "strings" |
| 20 | + "testing" |
| 21 | + |
| 22 | + "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
| 23 | + "github.com/hashicorp/terraform-plugin-sdk/v2/terraform" |
| 24 | +) |
| 25 | + |
| 26 | +func TestAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(t *testing.T) { |
| 27 | + t.Parallel() |
| 28 | + |
| 29 | + context := map[string]interface{}{ |
| 30 | + "random_suffix": randString(t, 10), |
| 31 | + } |
| 32 | + |
| 33 | + vcrTest(t, resource.TestCase{ |
| 34 | + PreCheck: func() { testAccPreCheck(t) }, |
| 35 | + Providers: testAccProviders, |
| 36 | + ExternalProviders: map[string]resource.ExternalProvider{ |
| 37 | + "random": {}, |
| 38 | + }, |
| 39 | + CheckDestroy: testAccCheckComputeInterconnectAttachmentDestroyProducer(t), |
| 40 | + Steps: []resource.TestStep{ |
| 41 | + { |
| 42 | + Config: testAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(context), |
| 43 | + }, |
| 44 | + { |
| 45 | + ResourceName: "google_compute_interconnect_attachment.on_prem", |
| 46 | + ImportState: true, |
| 47 | + ImportStateVerify: true, |
| 48 | + ImportStateVerifyIgnore: []string{"router", "candidate_subnets", "region"}, |
| 49 | + }, |
| 50 | + }, |
| 51 | + }) |
| 52 | +} |
| 53 | + |
| 54 | +func testAccComputeInterconnectAttachment_interconnectAttachmentBasicExample(context map[string]interface{}) string { |
| 55 | + return Nprintf(` |
| 56 | +resource "google_compute_interconnect_attachment" "on_prem" { |
| 57 | + name = "tf-test-on-prem-attachment%{random_suffix}" |
| 58 | + edge_availability_domain = "AVAILABILITY_DOMAIN_1" |
| 59 | + type = "PARTNER" |
| 60 | + router = google_compute_router.foobar.id |
| 61 | + mtu = 1500 |
| 62 | +} |
| 63 | +
|
| 64 | +resource "google_compute_router" "foobar" { |
| 65 | + name = "router%{random_suffix}" |
| 66 | + network = google_compute_network.foobar.name |
| 67 | + bgp { |
| 68 | + asn = 16550 |
| 69 | + } |
| 70 | +} |
| 71 | +
|
| 72 | +resource "google_compute_network" "foobar" { |
| 73 | + name = "network%{random_suffix}" |
| 74 | + auto_create_subnetworks = false |
| 75 | +} |
| 76 | +`, context) |
| 77 | +} |
| 78 | + |
| 79 | +func testAccCheckComputeInterconnectAttachmentDestroyProducer(t *testing.T) func(s *terraform.State) error { |
| 80 | + return func(s *terraform.State) error { |
| 81 | + for name, rs := range s.RootModule().Resources { |
| 82 | + if rs.Type != "google_compute_interconnect_attachment" { |
| 83 | + continue |
| 84 | + } |
| 85 | + if strings.HasPrefix(name, "data.") { |
| 86 | + continue |
| 87 | + } |
| 88 | + |
| 89 | + config := googleProviderConfig(t) |
| 90 | + |
| 91 | + url, err := replaceVarsForTest(config, rs, "{{ComputeBasePath}}projects/{{project}}/regions/{{region}}/interconnectAttachments/{{name}}") |
| 92 | + if err != nil { |
| 93 | + return err |
| 94 | + } |
| 95 | + |
| 96 | + billingProject := "" |
| 97 | + |
| 98 | + if config.BillingProject != "" { |
| 99 | + billingProject = config.BillingProject |
| 100 | + } |
| 101 | + |
| 102 | + _, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil) |
| 103 | + if err == nil { |
| 104 | + return fmt.Errorf("ComputeInterconnectAttachment still exists at %s", url) |
| 105 | + } |
| 106 | + } |
| 107 | + |
| 108 | + return nil |
| 109 | + } |
| 110 | +} |
0 commit comments