Skip to content

Commit 699167d

Browse files
Move files to the sweeper and envvar packages (#8198) (#5824)
* Move files to the package sweep and envvar * Replace function calls * Rename sweeper package * Fix rebasing error Signed-off-by: Modular Magician <[email protected]>
1 parent 36dd494 commit 699167d

File tree

690 files changed

+3583
-2920
lines changed

Some content is hidden

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

690 files changed

+3583
-2920
lines changed

.changelog/8198.txt

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
```release-note:none
2+
3+
```

google-beta/acctest/gcp_sweeper.go

Lines changed: 8 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -3,55 +3,21 @@
33
package acctest
44

55
import (
6-
"fmt"
7-
"strings"
8-
6+
"github.com/hashicorp/terraform-provider-google-beta/google-beta/sweeper"
97
transport_tpg "github.com/hashicorp/terraform-provider-google-beta/google-beta/transport"
108
)
119

12-
// List of prefixes used for test resource names
13-
var testResourcePrefixes = []string{
14-
// tf-test and tf_test are automatically prepended to resource ids in examples that
15-
// include a "-" or "_" respectively, and they are the preferred prefix for our test resources to use
16-
"tf-test",
17-
"tf_test",
18-
"tfgen",
19-
"gke-us-central1-tf", // composer-created disks which are abandoned by design (https://cloud.google.com/composer/pricing)
20-
"gcs-bucket-tf-test-", // https://github.com/hashicorp/terraform-provider-google/issues/8909
21-
"df-", // https://github.com/hashicorp/terraform-provider-google/issues/8909
22-
"resourcegroup-", // https://github.com/hashicorp/terraform-provider-google/issues/8924
23-
"cluster-", // https://github.com/hashicorp/terraform-provider-google/issues/8924
24-
"k8s-fw-", // firewall rules are getting created and not cleaned up by k8 resources using this prefix
25-
}
26-
2710
// SharedConfigForRegion returns a common config setup needed for the sweeper
2811
// functions for a given region
12+
//
13+
// Deprecated: For backward compatibility SharedConfigForRegion is still working,
14+
// but all new code should use SharedConfigForRegion in the sweeper package instead.
2915
func SharedConfigForRegion(region string) (*transport_tpg.Config, error) {
30-
project := GetTestProjectFromEnv()
31-
if project == "" {
32-
return nil, fmt.Errorf("set project using any of these env variables %v", ProjectEnvVars)
33-
}
34-
35-
if v := transport_tpg.MultiEnvSearch(CredsEnvVars); v == "" {
36-
return nil, fmt.Errorf("set credentials using any of these env variables %v", CredsEnvVars)
37-
}
38-
39-
conf := &transport_tpg.Config{
40-
Credentials: GetTestCredsFromEnv(),
41-
Region: region,
42-
Project: project,
43-
}
44-
45-
transport_tpg.ConfigureBasePaths(conf)
46-
47-
return conf, nil
16+
return sweeper.SharedConfigForRegion(region)
4817
}
4918

19+
// Deprecated: For backward compatibility IsSweepableTestResource is still working,
20+
// but all new code should use IsSweepableTestResource in the sweeper package instead.
5021
func IsSweepableTestResource(resourceName string) bool {
51-
for _, p := range testResourcePrefixes {
52-
if strings.HasPrefix(resourceName, p) {
53-
return true
54-
}
55-
}
56-
return false
22+
return sweeper.IsSweepableTestResource(resourceName)
5723
}

0 commit comments

Comments
 (0)