Skip to content

Commit 62f53ea

Browse files
modular-magiciannat-henderson
authored andcommitted
Autogenerate {{Resource}}Destroy in tests. (#2317)
1 parent db811e1 commit 62f53ea

File tree

47 files changed

+573
-464
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

47 files changed

+573
-464
lines changed

google/resource_compute_address_generated_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/hashicorp/terraform/helper/acctest"
2222
"github.com/hashicorp/terraform/helper/resource"
23+
"github.com/hashicorp/terraform/terraform"
2324
)
2425

2526
func TestAccComputeAddress_addressBasicExample(t *testing.T) {
@@ -147,3 +148,25 @@ resource "google_compute_instance" "instance_with_ip" {
147148
`, val, val,
148149
)
149150
}
151+
152+
func testAccCheckComputeAddressDestroy(s *terraform.State) error {
153+
for _, rs := range s.RootModule().Resources {
154+
if rs.Type != "google_compute_address" {
155+
continue
156+
}
157+
158+
config := testAccProvider.Meta().(*Config)
159+
160+
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/addresses/{{name}}")
161+
if err != nil {
162+
return err
163+
}
164+
165+
_, err = sendRequest(config, "GET", url, nil)
166+
if err == nil {
167+
return fmt.Errorf("ComputeAddress still exists at %s", url)
168+
}
169+
}
170+
171+
return nil
172+
}

google/resource_compute_address_test.go

-21
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/hashicorp/terraform/helper/acctest"
88
"github.com/hashicorp/terraform/helper/resource"
9-
"github.com/hashicorp/terraform/terraform"
109
)
1110

1211
func TestAccComputeAddress_basic(t *testing.T) {
@@ -79,26 +78,6 @@ func TestAccComputeAddress_internal(t *testing.T) {
7978
})
8079
}
8180

82-
func testAccCheckComputeAddressDestroy(s *terraform.State) error {
83-
config := testAccProvider.Meta().(*Config)
84-
85-
for _, rs := range s.RootModule().Resources {
86-
if rs.Type != "google_compute_address" {
87-
continue
88-
}
89-
90-
addressId, err := parseComputeAddressId(rs.Primary.ID, config)
91-
92-
_, err = config.clientCompute.Addresses.Get(
93-
config.Project, addressId.Region, addressId.Name).Do()
94-
if err == nil {
95-
return fmt.Errorf("Address still exists")
96-
}
97-
}
98-
99-
return nil
100-
}
101-
10281
func testAccComputeAddress_basic(i string) string {
10382
return fmt.Sprintf(`
10483
resource "google_compute_address" "foobar" {

google/resource_compute_autoscaler_generated_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/hashicorp/terraform/helper/acctest"
2222
"github.com/hashicorp/terraform/helper/resource"
23+
"github.com/hashicorp/terraform/terraform"
2324
)
2425

2526
func TestAccComputeAutoscaler_autoscalerBasicExample(t *testing.T) {
@@ -104,3 +105,25 @@ data "google_compute_image" "debian_9" {
104105
`, val, val, val, val,
105106
)
106107
}
108+
109+
func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error {
110+
for _, rs := range s.RootModule().Resources {
111+
if rs.Type != "google_compute_autoscaler" {
112+
continue
113+
}
114+
115+
config := testAccProvider.Meta().(*Config)
116+
117+
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/zones/{{zone}}/autoscalers/{{name}}")
118+
if err != nil {
119+
return err
120+
}
121+
122+
_, err = sendRequest(config, "GET", url, nil)
123+
if err == nil {
124+
return fmt.Errorf("ComputeAutoscaler still exists at %s", url)
125+
}
126+
}
127+
128+
return nil
129+
}

google/resource_compute_autoscaler_test.go

-20
Original file line numberDiff line numberDiff line change
@@ -104,26 +104,6 @@ func TestAccComputeAutoscaler_multicondition(t *testing.T) {
104104
})
105105
}
106106

107-
func testAccCheckComputeAutoscalerDestroy(s *terraform.State) error {
108-
config := testAccProvider.Meta().(*Config)
109-
110-
for _, rs := range s.RootModule().Resources {
111-
if rs.Type != "google_compute_autoscaler" {
112-
continue
113-
}
114-
115-
idParts := strings.Split(rs.Primary.ID, "/")
116-
zone, name := idParts[0], idParts[1]
117-
_, err := config.clientCompute.Autoscalers.Get(
118-
config.Project, zone, name).Do()
119-
if err == nil {
120-
return fmt.Errorf("Autoscaler still exists")
121-
}
122-
}
123-
124-
return nil
125-
}
126-
127107
func testAccCheckComputeAutoscalerExists(n string, ascaler *compute.Autoscaler) resource.TestCheckFunc {
128108
return func(s *terraform.State) error {
129109
rs, ok := s.RootModule().Resources[n]

google/resource_compute_backend_bucket_generated_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/hashicorp/terraform/helper/acctest"
2222
"github.com/hashicorp/terraform/helper/resource"
23+
"github.com/hashicorp/terraform/terraform"
2324
)
2425

2526
func TestAccComputeBackendBucket_backendBucketBasicExample(t *testing.T) {
@@ -58,3 +59,25 @@ resource "google_storage_bucket" "image_bucket" {
5859
`, val, val,
5960
)
6061
}
62+
63+
func testAccCheckComputeBackendBucketDestroy(s *terraform.State) error {
64+
for _, rs := range s.RootModule().Resources {
65+
if rs.Type != "google_compute_backend_bucket" {
66+
continue
67+
}
68+
69+
config := testAccProvider.Meta().(*Config)
70+
71+
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/backendBuckets/{{name}}")
72+
if err != nil {
73+
return err
74+
}
75+
76+
_, err = sendRequest(config, "GET", url, nil)
77+
if err == nil {
78+
return fmt.Errorf("ComputeBackendBucket still exists at %s", url)
79+
}
80+
}
81+
82+
return nil
83+
}

google/resource_compute_backend_bucket_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -78,24 +78,6 @@ func TestAccComputeBackendBucket_basicModified(t *testing.T) {
7878
}
7979
}
8080

81-
func testAccCheckComputeBackendBucketDestroy(s *terraform.State) error {
82-
config := testAccProvider.Meta().(*Config)
83-
84-
for _, rs := range s.RootModule().Resources {
85-
if rs.Type != "google_compute_backend_bucket" {
86-
continue
87-
}
88-
89-
_, err := config.clientCompute.BackendBuckets.Get(
90-
config.Project, rs.Primary.ID).Do()
91-
if err == nil {
92-
return fmt.Errorf("Backend bucket %s still exists", rs.Primary.ID)
93-
}
94-
}
95-
96-
return nil
97-
}
98-
9981
func testAccCheckComputeBackendBucketExists(n string, svc *compute.BackendBucket) resource.TestCheckFunc {
10082
return func(s *terraform.State) error {
10183
rs, ok := s.RootModule().Resources[n]

google/resource_compute_firewall_generated_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/hashicorp/terraform/helper/acctest"
2222
"github.com/hashicorp/terraform/helper/resource"
23+
"github.com/hashicorp/terraform/terraform"
2324
)
2425

2526
func TestAccComputeFirewall_firewallBasicExample(t *testing.T) {
@@ -66,3 +67,25 @@ resource "google_compute_network" "default" {
6667
`, val, val,
6768
)
6869
}
70+
71+
func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
72+
for _, rs := range s.RootModule().Resources {
73+
if rs.Type != "google_compute_firewall" {
74+
continue
75+
}
76+
77+
config := testAccProvider.Meta().(*Config)
78+
79+
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/firewalls/{{name}}")
80+
if err != nil {
81+
return err
82+
}
83+
84+
_, err = sendRequest(config, "GET", url, nil)
85+
if err == nil {
86+
return fmt.Errorf("ComputeFirewall still exists at %s", url)
87+
}
88+
}
89+
90+
return nil
91+
}

google/resource_compute_firewall_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -283,24 +283,6 @@ func TestAccComputeFirewall_disabled(t *testing.T) {
283283
})
284284
}
285285

286-
func testAccCheckComputeFirewallDestroy(s *terraform.State) error {
287-
config := testAccProvider.Meta().(*Config)
288-
289-
for _, rs := range s.RootModule().Resources {
290-
if rs.Type != "google_compute_firewall" {
291-
continue
292-
}
293-
294-
_, err := config.clientCompute.Firewalls.Get(
295-
config.Project, rs.Primary.ID).Do()
296-
if err == nil {
297-
return fmt.Errorf("Firewall still exists")
298-
}
299-
}
300-
301-
return nil
302-
}
303-
304286
func testAccCheckComputeFirewallExists(n string, firewall *compute.Firewall) resource.TestCheckFunc {
305287
return func(s *terraform.State) error {
306288
rs, ok := s.RootModule().Resources[n]

google/resource_compute_forwarding_rule_generated_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/hashicorp/terraform/helper/acctest"
2222
"github.com/hashicorp/terraform/helper/resource"
23+
"github.com/hashicorp/terraform/terraform"
2324
)
2425

2526
func TestAccComputeForwardingRule_forwardingRuleBasicExample(t *testing.T) {
@@ -56,3 +57,25 @@ resource "google_compute_target_pool" "default" {
5657
`, val, val,
5758
)
5859
}
60+
61+
func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error {
62+
for _, rs := range s.RootModule().Resources {
63+
if rs.Type != "google_compute_forwarding_rule" {
64+
continue
65+
}
66+
67+
config := testAccProvider.Meta().(*Config)
68+
69+
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/regions/{{region}}/forwardingRules/{{name}}")
70+
if err != nil {
71+
return err
72+
}
73+
74+
_, err = sendRequest(config, "GET", url, nil)
75+
if err == nil {
76+
return fmt.Errorf("ComputeForwardingRule still exists at %s", url)
77+
}
78+
}
79+
80+
return nil
81+
}

google/resource_compute_forwarding_rule_test.go

-19
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@ import (
66

77
"github.com/hashicorp/terraform/helper/acctest"
88
"github.com/hashicorp/terraform/helper/resource"
9-
"github.com/hashicorp/terraform/terraform"
109
)
1110

1211
func TestAccComputeForwardingRule_update(t *testing.T) {
@@ -142,24 +141,6 @@ func TestAccComputeForwardingRule_networkTier(t *testing.T) {
142141
})
143142
}
144143

145-
func testAccCheckComputeForwardingRuleDestroy(s *terraform.State) error {
146-
config := testAccProvider.Meta().(*Config)
147-
148-
for _, rs := range s.RootModule().Resources {
149-
if rs.Type != "google_compute_forwarding_rule" {
150-
continue
151-
}
152-
153-
_, err := config.clientCompute.ForwardingRules.Get(
154-
config.Project, config.Region, rs.Primary.ID).Do()
155-
if err == nil {
156-
return fmt.Errorf("ForwardingRule still exists")
157-
}
158-
}
159-
160-
return nil
161-
}
162-
163144
func testAccComputeForwardingRule_basic(poolName, ruleName string) string {
164145
return fmt.Sprintf(`
165146
resource "google_compute_target_pool" "foo-tp" {

google/resource_compute_global_address_generated_test.go

+23
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@ import (
2020

2121
"github.com/hashicorp/terraform/helper/acctest"
2222
"github.com/hashicorp/terraform/helper/resource"
23+
"github.com/hashicorp/terraform/terraform"
2324
)
2425

2526
func TestAccComputeGlobalAddress_globalAddressBasicExample(t *testing.T) {
@@ -50,3 +51,25 @@ resource "google_compute_global_address" "default" {
5051
`, val,
5152
)
5253
}
54+
55+
func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error {
56+
for _, rs := range s.RootModule().Resources {
57+
if rs.Type != "google_compute_global_address" {
58+
continue
59+
}
60+
61+
config := testAccProvider.Meta().(*Config)
62+
63+
url, err := replaceVarsForTest(rs, "https://www.googleapis.com/compute/v1/projects/{{project}}/global/addresses/{{name}}")
64+
if err != nil {
65+
return err
66+
}
67+
68+
_, err = sendRequest(config, "GET", url, nil)
69+
if err == nil {
70+
return fmt.Errorf("ComputeGlobalAddress still exists at %s", url)
71+
}
72+
}
73+
74+
return nil
75+
}

google/resource_compute_global_address_test.go

-18
Original file line numberDiff line numberDiff line change
@@ -87,24 +87,6 @@ func TestAccComputeGlobalAddress_internal(t *testing.T) {
8787
})
8888
}
8989

90-
func testAccCheckComputeGlobalAddressDestroy(s *terraform.State) error {
91-
config := testAccProvider.Meta().(*Config)
92-
93-
for _, rs := range s.RootModule().Resources {
94-
if rs.Type != "google_compute_global_address" {
95-
continue
96-
}
97-
98-
_, err := config.clientCompute.GlobalAddresses.Get(
99-
config.Project, rs.Primary.ID).Do()
100-
if err == nil {
101-
return fmt.Errorf("Address still exists")
102-
}
103-
}
104-
105-
return nil
106-
}
107-
10890
func testAccCheckComputeGlobalAddressExists(n string, addr *compute.Address) resource.TestCheckFunc {
10991
return func(s *terraform.State) error {
11092
rs, ok := s.RootModule().Resources[n]

0 commit comments

Comments
 (0)