|
1 | 1 | package google |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "fmt" |
5 | | - "strings" |
6 | 4 | "testing" |
7 | 5 |
|
8 | 6 | "github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource" |
9 | 7 | ) |
10 | 8 |
|
11 | | -// List of prefixes used for test resource names |
12 | | -var testResourcePrefixes = []string{ |
13 | | - // tf-test and tf_test are automatically prepended to resource ids in examples that |
14 | | - // include a "-" or "_" respectively, and they are the preferred prefix for our test resources to use |
15 | | - "tf-test", |
16 | | - "tf_test", |
17 | | - "tfgen", |
18 | | - "gke-us-central1-tf", // composer-created disks which are abandoned by design (https://cloud.google.com/composer/pricing) |
19 | | - "gcs-bucket-tf-test-", // https://github.com/hashicorp/terraform-provider-google/issues/8909 |
20 | | - "df-", // https://github.com/hashicorp/terraform-provider-google/issues/8909 |
21 | | - "resourcegroup-", // https://github.com/hashicorp/terraform-provider-google/issues/8924 |
22 | | - "cluster-", // https://github.com/hashicorp/terraform-provider-google/issues/8924 |
23 | | - "k8s-fw-", // firewall rules are getting created and not cleaned up by k8 resources using this prefix |
24 | | -} |
25 | | - |
26 | 9 | func TestMain(m *testing.M) { |
27 | 10 | resource.TestMain(m) |
28 | 11 | } |
29 | | - |
30 | | -// SharedConfigForRegion returns a common config setup needed for the sweeper |
31 | | -// functions for a given region |
32 | | -func SharedConfigForRegion(region string) (*Config, error) { |
33 | | - project := GetTestProjectFromEnv() |
34 | | - if project == "" { |
35 | | - return nil, fmt.Errorf("set project using any of these env variables %v", ProjectEnvVars) |
36 | | - } |
37 | | - |
38 | | - if v := MultiEnvSearch(CredsEnvVars); v == "" { |
39 | | - return nil, fmt.Errorf("set credentials using any of these env variables %v", CredsEnvVars) |
40 | | - } |
41 | | - |
42 | | - conf := &Config{ |
43 | | - Credentials: GetTestCredsFromEnv(), |
44 | | - Region: region, |
45 | | - Project: project, |
46 | | - } |
47 | | - |
48 | | - ConfigureBasePaths(conf) |
49 | | - |
50 | | - return conf, nil |
51 | | -} |
52 | | - |
53 | | -func IsSweepableTestResource(resourceName string) bool { |
54 | | - for _, p := range testResourcePrefixes { |
55 | | - if strings.HasPrefix(resourceName, p) { |
56 | | - return true |
57 | | - } |
58 | | - } |
59 | | - return false |
60 | | -} |
0 commit comments