generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 3
/
tunnel_test.go
173 lines (160 loc) · 4.43 KB
/
tunnel_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
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
package acc_tests
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
)
func TestAccResourceTunnel(t *testing.T) {
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("tunnel", "v1/tunnels"),
Steps: []resource.TestStep{
{
Config: testAccTunnelStep1,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"pfptmeta_tunnel.tunnel", "id", regexp.MustCompile("^tun-.+$"),
),
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "name", "tunnel name1",
),
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "description", "tunnel description1",
),
),
},
{
Config: testAccTunnelStep2,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "name", "tunnel name2",
),
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "description", "tunnel description2",
),
),
},
{
Config: testAccTunnelStep3,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "name", "tunnel name3",
),
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "description", "tunnel description3",
),
),
},
{
Config: testAccTunnelStep4,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "name", "tunnel name4",
),
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "description", "tunnel description4",
),
),
},
{
Config: testAccTunnelStep5,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "name", "tunnel name5",
),
resource.TestCheckResourceAttr(
"pfptmeta_tunnel.tunnel", "description", "tunnel description5",
),
),
},
},
})
}
func TestAccDataSourceTunnel(t *testing.T) {
resource.Test(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
CheckDestroy: validateResourceDestroyed("tunnel", "v1/tunnels"),
Steps: []resource.TestStep{
{
Config: testAccTunnelStep1 + testAccTunnelByIDDataSource,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.pfptmeta_tunnel.tunnel2", "id", regexp.MustCompile("^tun-.+$"),
),
resource.TestCheckResourceAttr(
"data.pfptmeta_tunnel.tunnel2", "name", "tunnel name1",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_tunnel.tunnel2", "description", "tunnel description1",
),
),
},
{
Config: testAccTunnelStep1 + testAccTunnelByNameDataSource,
Check: resource.ComposeTestCheckFunc(
resource.TestMatchResourceAttr(
"data.pfptmeta_tunnel.tunnel3", "id", regexp.MustCompile("^tun-.+$"),
),
resource.TestCheckResourceAttr(
"data.pfptmeta_tunnel.tunnel3", "name", "tunnel name1",
),
resource.TestCheckResourceAttr(
"data.pfptmeta_tunnel.tunnel3", "description", "tunnel description1",
),
),
},
},
})
}
const testAccTunnelStep1 = `
resource "pfptmeta_tunnel" "tunnel" {
name = "tunnel name1"
description = "tunnel description1"
gre_config {
source_ips = ["1.2.3.4", "2.3.4.5"]
}
}
`
const testAccTunnelStep2 = `
resource "pfptmeta_tunnel" "tunnel" {
name = "tunnel name2"
description = "tunnel description2"
gre_config {
source_ips = ["1.2.3.4"]
}
}
`
const testAccTunnelStep3 = `
resource "pfptmeta_tunnel" "tunnel" {
name = "tunnel name3"
description = "tunnel description3"
gre_config {
source_ips = ["1.2.3.4", "3.4.5.6"]
}
}
`
const testAccTunnelStep4 = `
resource "pfptmeta_tunnel" "tunnel" {
name = "tunnel name4"
description = "tunnel description4"
gre_config {
source_ips = ["4.5.6.7"]
}
}
`
const testAccTunnelStep5 = `
resource "pfptmeta_tunnel" "tunnel" {
name = "tunnel name5"
description = "tunnel description5"
}
`
const testAccTunnelByIDDataSource = `
data "pfptmeta_tunnel" "tunnel2" {
id = pfptmeta_tunnel.tunnel.id
}`
const testAccTunnelByNameDataSource = `
data "pfptmeta_tunnel" "tunnel3" {
name = "tunnel name1"
}`