forked from hashicorp/terraform-provider-google-beta
-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathresource_compute_resource_policy_test.go
123 lines (107 loc) · 3.09 KB
/
resource_compute_resource_policy_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
// Copyright (c) HashiCorp, Inc.
// SPDX-License-Identifier: MPL-2.0
package compute_test
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-testing/helper/resource"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/acctest"
"github.com/hashicorp/terraform-provider-google-beta/google-beta/services/compute"
)
// Value returned from the API will always be in format "HH:MM", so we need the suppress only on new values
func TestHourlyFormatSuppressDiff(t *testing.T) {
cases := map[string]struct {
Old, New string
ExpectDiffSuppress bool
}{
"Same value": {
Old: "01:00",
New: "01:00",
ExpectDiffSuppress: false,
},
"Same value but different format": {
Old: "01:00",
New: "1:00",
ExpectDiffSuppress: true,
},
"Changed value": {
Old: "01:00",
New: "02:00",
ExpectDiffSuppress: false,
},
"Changed value but different format": {
Old: "01:00",
New: "2:00",
ExpectDiffSuppress: false,
},
"Check interference with unaffected values": {
Old: "11:00",
New: "22:00",
ExpectDiffSuppress: false,
},
}
for tn, tc := range cases {
if compute.HourlyFormatSuppressDiff("", tc.Old, tc.New, nil) != tc.ExpectDiffSuppress {
t.Errorf("bad: %s, %q => %q expect DiffSuppress to return %t", tn, tc.Old, tc.New, tc.ExpectDiffSuppress)
}
}
}
func TestAccComputeResourcePolicy_attached(t *testing.T) {
t.Parallel()
acctest.VcrTest(t, resource.TestCase{
PreCheck: func() { acctest.AccTestPreCheck(t) },
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories(t),
CheckDestroy: testAccCheckComputeResourcePolicyDestroyProducer(t),
Steps: []resource.TestStep{
{
Config: testAccComputeResourcePolicy_attached(acctest.RandString(t, 10)),
},
{
ResourceName: "google_compute_resource_policy.foo",
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func testAccComputeResourcePolicy_attached(suffix string) string {
return fmt.Sprintf(`
data "google_compute_image" "my_image" {
family = "debian-11"
project = "debian-cloud"
}
resource "google_compute_instance" "foobar" {
name = "tf-test-%s"
machine_type = "e2-medium"
zone = "us-central1-a"
can_ip_forward = false
tags = ["foo", "bar"]
//deletion_protection = false is implicit in this config due to default value
boot_disk {
initialize_params {
image = data.google_compute_image.my_image.self_link
}
}
network_interface {
network = "default"
}
metadata = {
foo = "bar"
baz = "qux"
startup-script = "echo Hello"
}
labels = {
my_key = "my_value"
my_other_key = "my_other_value"
}
resource_policies = [google_compute_resource_policy.foo.self_link]
}
resource "google_compute_resource_policy" "foo" {
name = "tf-test-policy-%s"
region = "us-central1"
group_placement_policy {
availability_domain_count = 2
}
}
`, suffix, suffix)
}