forked from hashicorp/terraform-provider-google
-
Notifications
You must be signed in to change notification settings - Fork 0
/
resource_vpc_access_connector_generated_test.go
141 lines (121 loc) · 3.88 KB
/
resource_vpc_access_connector_generated_test.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
// ----------------------------------------------------------------------------
//
// *** AUTO GENERATED CODE *** Type: MMv1 ***
//
// ----------------------------------------------------------------------------
//
// This file is automatically generated by Magic Modules and manual
// changes will be clobbered when the file is regenerated.
//
// Please read more about how to change this file in
// .github/CONTRIBUTING.md.
//
// ----------------------------------------------------------------------------
package google
import (
"fmt"
"strings"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)
func TestAccVPCAccessConnector_vpcAccessConnectorExample(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"random_suffix": randString(t, 10),
}
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVPCAccessConnectorDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccVPCAccessConnector_vpcAccessConnectorExample(context),
},
{
ResourceName: "google_vpc_access_connector.connector",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"self_link", "region"},
},
},
})
}
func testAccVPCAccessConnector_vpcAccessConnectorExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_vpc_access_connector" "connector" {
name = "tf-test-vpc-con%{random_suffix}"
ip_cidr_range = "10.8.0.0/28"
network = "default"
}
`, context)
}
func TestAccVPCAccessConnector_vpcAccessConnectorSharedVPCExample(t *testing.T) {
t.Parallel()
context := map[string]interface{}{
"random_suffix": randString(t, 10),
}
vcrTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckVPCAccessConnectorDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccVPCAccessConnector_vpcAccessConnectorSharedVPCExample(context),
},
{
ResourceName: "google_vpc_access_connector.connector",
ImportState: true,
ImportStateVerify: true,
ImportStateVerifyIgnore: []string{"self_link", "region"},
},
},
})
}
func testAccVPCAccessConnector_vpcAccessConnectorSharedVPCExample(context map[string]interface{}) string {
return Nprintf(`
resource "google_vpc_access_connector" "connector" {
name = "tf-test-vpc-con%{random_suffix}"
subnet {
name = google_compute_subnetwork.custom_test.name
}
machine_type = "e2-standard-4"
}
resource "google_compute_subnetwork" "custom_test" {
name = "tf-test-vpc-con%{random_suffix}"
ip_cidr_range = "10.2.0.0/28"
region = "us-central1"
network = google_compute_network.custom_test.id
}
resource "google_compute_network" "custom_test" {
name = "tf-test-vpc-con%{random_suffix}"
auto_create_subnetworks = false
}
`, context)
}
func testAccCheckVPCAccessConnectorDestroyProducer(t *testing.T) func(s *terraform.State) error {
return func(s *terraform.State) error {
for name, rs := range s.RootModule().Resources {
if rs.Type != "google_vpc_access_connector" {
continue
}
if strings.HasPrefix(name, "data.") {
continue
}
config := googleProviderConfig(t)
url, err := replaceVarsForTest(config, rs, "{{VPCAccessBasePath}}projects/{{project}}/locations/{{region}}/connectors/{{name}}")
if err != nil {
return err
}
billingProject := ""
if config.BillingProject != "" {
billingProject = config.BillingProject
}
_, err = sendRequest(config, "GET", billingProject, url, config.userAgent, nil)
if err == nil {
return fmt.Errorf("VPCAccessConnector still exists at %s", url)
}
}
return nil
}
}