generated from hashicorp/terraform-provider-scaffolding
-
Notifications
You must be signed in to change notification settings - Fork 4
/
resource_credentials_test.go
340 lines (308 loc) · 13.1 KB
/
resource_credentials_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
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
package provider
import (
"regexp"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/healx/terraform-provider-nftower/internal/template"
)
func TestAccResourceCredentialsAWS(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
ResourceName: "nftower_credentials",
Config: template.ParseRandName(testAccResourceCredentialsAWS),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "name", "tf-acceptance-credentials-aws"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "description", "tf acceptance testing aws credentials"),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "date_created", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "last_updated", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "aws.0.access_key", "foo"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "aws.0.secret_key", "bar"),
),
},
},
})
}
const testAccResourceCredentialsAWS = `
resource "nftower_workspace" "foo" {
name = "tf-acceptance-{{.randName}}"
full_name = "tf acceptance testing credentials"
description = "Created by the nftower terraform provider acceptance tests. Will be deleted shortly"
visibility = "PRIVATE"
}
resource "nftower_credentials" "foo" {
name = "tf-acceptance-credentials-aws"
description = "tf acceptance testing aws credentials"
workspace_id = nftower_workspace.foo.id
aws {
access_key = "foo"
secret_key = "bar"
assume_role_arn = "baz"
}
}
`
// TestAccResourceCredentialsContainerRegistry cannot be run withouth real credentials for accessing the container registry.
// Seqera Platform test registry connection during the creation of the credentials.
// For AWS ECR would be username: AWS_ACCESS_KEY_ID), password: AWS_SECRET_ACCESS_KEY, registry_server: AWS_ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com
func TestAccResourceCredentialsContainerRegistry(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
ResourceName: "nftower_credentials",
Config: template.ParseRandName(testAccResourceCredentialsContainerRegistry),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "name", "tf-acceptance-credentials-container-registry"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "description", "tf acceptance testing container registry credentials"),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "date_created", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "last_updated", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "container_registry.0.username", "<<AWS_ACCESS_KEY_ID>>"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "container_registry.0.password", "<<AWS_SECRET_ACCESS_KEY>>"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "container_registry.0.registry_server", "<<AWS_ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com>>"),
),
},
},
})
}
const testAccResourceCredentialsContainerRegistry = `
resource "nftower_workspace" "foo" {
name = "tf-acceptance-{{.randName}}"
full_name = "tf acceptance testing credentials"
description = "Created by the nftower terraform provider acceptance tests. Will be deleted shortly"
visibility = "PRIVATE"
}
resource "nftower_credentials" "foo" {
name = "tf-acceptance-credentials-container-registry"
description = "tf acceptance testing container registry credentials"
workspace_id = nftower_workspace.foo.id
container_registry {
username = "<<AWS_ACCESS_KEY_ID>>"
password = "<<AWS_SECRET_ACCESS_KEY"
registry_server = "<<AWS_ACCOUNT_ID.dkr.ecr.AWS_REGION.amazonaws.com>>"
}
}
`
func TestAccResourceCredentialsGithub(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
ResourceName: "nftower_credentials",
Config: template.ParseRandName(testAccResourceCredentialsGithub),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "name", "tf-acceptance-credentials-github"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "description", "tf acceptance testing github credentials"),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "date_created", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "last_updated", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "github.0.username", "foo"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "github.0.access_token", "bar"),
),
},
},
})
}
const testAccResourceCredentialsGithub = `
resource "nftower_workspace" "foo" {
name = "tf-acceptance-{{.randName}}"
full_name = "tf acceptance testing credentials"
description = "Created by the nftower terraform provider acceptance tests. Will be deleted shortly"
visibility = "PRIVATE"
}
resource "nftower_credentials" "foo" {
name = "tf-acceptance-credentials-github"
description = "tf acceptance testing github credentials"
workspace_id = nftower_workspace.foo.id
github {
username = "foo"
access_token = "bar"
}
}
`
func TestAccResourceCredentialsGitlab(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
ResourceName: "nftower_credentials",
Config: template.ParseRandName(testAccResourceCredentialsGitlab),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "name", "tf-acceptance-credentials-gitlab"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "description", "tf acceptance testing gitlab credentials"),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "date_created", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "last_updated", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "gitlab.0.username", "foo"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "gitlab.0.password", "bar"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "gitlab.0.token", "baz"),
),
},
},
})
}
const testAccResourceCredentialsGitlab = `
resource "nftower_workspace" "foo" {
name = "tf-acceptance-{{.randName}}"
full_name = "tf acceptance testing credentials"
description = "Created by the nftower terraform provider acceptance tests. Will be deleted shortly"
visibility = "PRIVATE"
}
resource "nftower_credentials" "foo" {
name = "tf-acceptance-credentials-gitlab"
description = "tf acceptance testing gitlab credentials"
workspace_id = nftower_workspace.foo.id
gitlab {
username = "foo"
password = "bar"
token = "baz"
}
}
`
func TestAccResourceCredentialsSSH(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
ResourceName: "nftower_credentials",
Config: template.ParseRandName(testAccResourceCredentialsSSH),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "name", "tf-acceptance-credentials-ssh"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "description", "tf acceptance testing ssh credentials"),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "date_created", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "last_updated", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "ssh.0.private_key", regexp.MustCompile("BEGIN OPENSSH PRIVATE KEY")),
),
},
},
})
}
const testAccResourceCredentialsSSH = `
resource "nftower_workspace" "foo" {
name = "tf-acceptance-{{.randName}}"
full_name = "tf acceptance testing credentials"
description = "Created by the nftower terraform provider acceptance tests. Will be deleted shortly"
visibility = "PRIVATE"
}
resource "nftower_credentials" "foo" {
name = "tf-acceptance-credentials-ssh"
description = "tf acceptance testing ssh credentials"
workspace_id = nftower_workspace.foo.id
ssh {
private_key = <<EOF
-----BEGIN OPENSSH PRIVATE KEY-----
b3BlbnNzaC1rZXktdjEAAAAABG5vbmUAAAAEbm9uZQAAAAAAAAABAAABlwAAAAdzc2gtcn
NhAAAAAwEAAQAAAYEA1Ui6IQY+FdeCgGPxiK1kz1Smet1uiydviL4pSGzZkJamhIw3Zf/i
ccUcH81Oas21fi/sSGKXyMEr1P3qPk3bs25MUpVqS8Mc/2u3grkjL+5BJin5DVpeX+Slzl
xyrDTCV0PU+jb0vCGoo1Fuiea5/15IEswfWw+lEjJI05qvYNkX2hQA471FaZmQlbYokStQ
OtJaDjLrbxCjNdjTz4vlRzPdpG8jvlSjT4LiP8M9gtPFRPf/MgXXx+fZUx+b/Ki8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AABx0aW1yaWNoYXJkc29uQEdFTC1DSjc0RDJYOU1GAQIDBAU=
-----END OPENSSH PRIVATE KEY-----
EOF
}
}
`
func TestAccResourceCredentials_basic(t *testing.T) {
resource.UnitTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
ProviderFactories: providerFactories,
Steps: []resource.TestStep{
{
ResourceName: "nftower_credentials",
Config: template.ParseRandName(testAccResourceCredentials_basic),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "name", "tf-acceptance-credentials-github"),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "date_created", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestMatchResourceAttr(
"nftower_credentials.foo", "last_updated", regexp.MustCompile("^[0-9-:TZ]+")),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "github.0.username", "foo"),
resource.TestCheckResourceAttr(
"nftower_credentials.foo", "github.0.access_token", "bar"),
),
},
},
})
}
const testAccResourceCredentials_basic = `
resource "nftower_workspace" "foo" {
name = "tf-acceptance-{{.randName}}"
full_name = "tf acceptance testing credentials"
description = "Created by the nftower terraform provider acceptance tests. Will be deleted shortly"
visibility = "PRIVATE"
}
resource "nftower_credentials" "foo" {
name = "tf-acceptance-credentials-github"
workspace_id = nftower_workspace.foo.id
github {
username = "foo"
access_token = "bar"
}
}
`