-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathresource_serviceendpoint_aws_test.go
232 lines (210 loc) · 9.2 KB
/
resource_serviceendpoint_aws_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
//go:build (all || resource_serviceendpoint_aws) && !exclude_serviceendpoints
// +build all resource_serviceendpoint_aws
// +build !exclude_serviceendpoints
package acceptancetests
import (
"fmt"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)
func TestAccServiceEndpointAws_basic(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_aws"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointAwsResource(projectName, serviceEndpointName),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
resource.TestCheckResourceAttr(tfSvcEpNode, "access_key_id", "0000"),
resource.TestCheckResourceAttr(tfSvcEpNode, "secret_access_key", "secretkey"),
resource.TestCheckResourceAttr(tfSvcEpNode, "use_oidc", "false"),
),
},
},
})
}
func TestAccServiceEndpointAws_complete(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
description := testutils.GenerateResourceName()
sessionToken := "foobar"
rta := "rta"
rsn := "rsn"
externalId := "external_id"
resourceType := "azuredevops_serviceendpoint_aws"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointAwsResourceComplete(projectName, serviceEndpointName, description, sessionToken, rta, rsn, externalId),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
resource.TestCheckResourceAttr(tfSvcEpNode, "access_key_id", "0000"),
resource.TestCheckResourceAttr(tfSvcEpNode, "secret_access_key", "secretkey"),
resource.TestCheckResourceAttr(tfSvcEpNode, "description", description),
resource.TestCheckResourceAttr(tfSvcEpNode, "session_token", "foobar"),
resource.TestCheckResourceAttr(tfSvcEpNode, "role_to_assume", rta),
resource.TestCheckResourceAttr(tfSvcEpNode, "role_session_name", rsn),
resource.TestCheckResourceAttr(tfSvcEpNode, "external_id", externalId),
resource.TestCheckResourceAttr(tfSvcEpNode, "use_oidc", "false"),
),
},
},
})
}
func TestAccServiceEndpointAws_update(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointNameFirst := testutils.GenerateResourceName()
description := testutils.GenerateResourceName()
serviceEndpointNameSecond := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_aws"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointAwsResource(projectName, serviceEndpointNameFirst),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameFirst), resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameFirst),
),
},
{
Config: hclSvcEndpointAwsResourceUpdate(projectName, serviceEndpointNameSecond, description),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameSecond),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameSecond),
resource.TestCheckResourceAttr(tfSvcEpNode, "description", description),
),
},
},
})
}
func TestAccServiceEndpointAws_oidc(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_aws"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointAwsResourceOidc(projectName, serviceEndpointName),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
resource.TestCheckResourceAttr(tfSvcEpNode, "access_key_id", "0000"),
resource.TestCheckResourceAttr(tfSvcEpNode, "secret_access_key", "secretkey"),
resource.TestCheckResourceAttr(tfSvcEpNode, "use_oidc", "true"),
),
},
},
})
}
func TestAccServiceEndpointAws_requiresImportErrorStep(t *testing.T) {
projectName := testutils.GenerateResourceName()
serviceEndpointName := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_aws"
tfSvcEpNode := resourceType + ".test"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
CheckDestroy: testutils.CheckServiceEndpointDestroyed(resourceType),
Steps: []resource.TestStep{
{
Config: hclSvcEndpointAwsResource(projectName, serviceEndpointName),
Check: resource.ComposeTestCheckFunc(
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointName),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointName),
),
},
{
Config: hclSvcEndpointAwsResourceRequiresImport(projectName, serviceEndpointName),
ExpectError: testutils.RequiresImportError(serviceEndpointName),
},
},
})
}
func hclSvcEndpointAwsResource(projectName string, serviceEndpointName string) string {
return hclSvcEndpointAwsResourceUpdate(projectName, serviceEndpointName, "description")
}
func hclSvcEndpointAwsResourceUpdate(projectName string, serviceEndpointName string, description string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "project" {
name = "%s"
}
resource "azuredevops_serviceendpoint_aws" "test" {
project_id = azuredevops_project.project.id
access_key_id = "0000"
secret_access_key = "secretkey"
service_endpoint_name = "%s"
description = "%s"
use_oidc = false
}`, projectName, serviceEndpointName, description)
}
func hclSvcEndpointAwsResourceComplete(projectName string, serviceEndpointName string, description string, sessionToken string, rta string, rsn string, externalId string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "project" {
name = "%s"
}
resource "azuredevops_serviceendpoint_aws" "test" {
project_id = azuredevops_project.project.id
access_key_id = "0000"
secret_access_key = "secretkey"
service_endpoint_name = "%s"
description = "%s"
session_token = "%s"
role_to_assume = "%s"
role_session_name = "%s"
external_id = "%s"
use_oidc = false
}`, projectName, serviceEndpointName, description, sessionToken, rta, rsn, externalId)
}
func hclSvcEndpointAwsResourceOidc(projectName, serviceEndpointName string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "project" {
name = "%s"
}
resource "azuredevops_serviceendpoint_aws" "test" {
project_id = azuredevops_project.project.id
access_key_id = "0000"
secret_access_key = "secretkey"
service_endpoint_name = "%s"
use_oidc = true
}`, projectName, serviceEndpointName)
}
func hclSvcEndpointAwsResourceRequiresImport(projectName string, serviceEndpointName string) string {
template := hclSvcEndpointAwsResource(projectName, serviceEndpointName)
return fmt.Sprintf(`
%s
resource "azuredevops_serviceendpoint_aws" "import" {
project_id = azuredevops_serviceendpoint_aws.test.project_id
access_key_id = "0000"
secret_access_key = "secretkey"
service_endpoint_name = azuredevops_serviceendpoint_aws.test.service_endpoint_name
description = azuredevops_serviceendpoint_aws.test.description
use_oidc = azuredevops_serviceendpoint_aws.test.use_oidc
}
`, template)
}