@@ -26,19 +26,19 @@ var azurermTestServiceEndpointAzureRMID = uuid.New()
26
26
var azurermRandomServiceEndpointAzureRMProjectID = uuid .New ().String ()
27
27
var azurermTestServiceEndpointAzureRMProjectID = & azurermRandomServiceEndpointAzureRMProjectID
28
28
29
- var azurermTestServiceEndpointsAzureRM = [] serviceendpoint.ServiceEndpoint {
30
- {
29
+ func getManualAuthServiceEndpoint () serviceendpoint.ServiceEndpoint {
30
+ return serviceendpoint. ServiceEndpoint {
31
31
Authorization : & serviceendpoint.EndpointAuthorization {
32
32
Parameters : & map [string ]string {
33
33
"authenticationType" : "spnKey" ,
34
- "serviceprincipalid" : "" ,
35
- "serviceprincipalkey" : "" ,
34
+ "serviceprincipalid" : "e31eaaac-47da-4156-b433-9b0538c94b7e" , //fake value
35
+ "serviceprincipalkey" : "d96d8515-20b2-4413-8879-27c5d040cbc2" , //fake value
36
36
"tenantid" : "aba07645-051c-44b4-b806-c34d33f3dcd1" , //fake value
37
37
},
38
38
Scheme : converter .String ("ServicePrincipal" ),
39
39
},
40
40
Data : & map [string ]string {
41
- "creationMode" : "Automatic " ,
41
+ "creationMode" : "Manual " ,
42
42
"environment" : "AzureCloud" ,
43
43
"scopeLevel" : "Subscription" ,
44
44
"subscriptionId" : "42125daf-72fd-417c-9ea7-080690625ad3" , //fake value
@@ -50,19 +50,23 @@ var azurermTestServiceEndpointsAzureRM = []serviceendpoint.ServiceEndpoint{
50
50
Owner : converter .String ("library" ), // Supported values are "library", "agentcloud"
51
51
Type : converter .String ("azurerm" ),
52
52
Url : converter .String ("https://management.azure.com/" ),
53
- },
53
+ }
54
+ }
55
+
56
+ var azurermTestServiceEndpointsAzureRM = []serviceendpoint.ServiceEndpoint {
57
+ getManualAuthServiceEndpoint (),
54
58
{
55
59
Authorization : & serviceendpoint.EndpointAuthorization {
56
60
Parameters : & map [string ]string {
57
61
"authenticationType" : "spnKey" ,
58
- "serviceprincipalid" : "e31eaaac-47da-4156-b433-9b0538c94b7e" , //fake value
59
- "serviceprincipalkey" : "d96d8515-20b2-4413-8879-27c5d040cbc2" , //fake value
62
+ "serviceprincipalid" : "" ,
63
+ "serviceprincipalkey" : "" ,
60
64
"tenantid" : "aba07645-051c-44b4-b806-c34d33f3dcd1" , //fake value
61
65
},
62
66
Scheme : converter .String ("ServicePrincipal" ),
63
67
},
64
68
Data : & map [string ]string {
65
- "creationMode" : "Manual " ,
69
+ "creationMode" : "Automatic " ,
66
70
"environment" : "AzureCloud" ,
67
71
"scopeLevel" : "Subscription" ,
68
72
"subscriptionId" : "42125daf-72fd-417c-9ea7-080690625ad3" , //fake value
@@ -224,6 +228,41 @@ func TestAzureDevOpsServiceEndpointAzureRM_Update_DoesNotSwallowError(t *testing
224
228
}
225
229
}
226
230
231
+ func TestAzureDevOpsServiceEndpointAzureRM_ExpandCredentials (t * testing.T ) {
232
+ spnKeyExistsWithValue := map [string ]interface {}{"serviceprincipalkey" : "fake-spn-key" }
233
+ spnKeyExistsWithEmptyValue := map [string ]interface {}{"serviceprincipalkey" : "" }
234
+ spnKeyDoesNotExists := map [string ]interface {}{}
235
+
236
+ require .Equal (t , expandSpnKey (spnKeyExistsWithValue ), "fake-spn-key" )
237
+ require .Equal (t , expandSpnKey (spnKeyExistsWithEmptyValue ), "null" )
238
+ require .Equal (t , expandSpnKey (spnKeyDoesNotExists ), "null" )
239
+ }
240
+
241
+ // This is a little different than most. The steps done, along with the motivation behind each, are as follows:
242
+ // (1) The service endpoint is configured. The `serviceprincipalkey` is set to `""`, which matches
243
+ // the Azure DevOps API behavior. The service will intentionally hide the value of
244
+ // `serviceprincipalkey` because it is a secret value
245
+ // (2) The resource is flattened/expanded
246
+ // (3) The `serviceprincipalkey` field is inspected and asserted to equal `"null"`. This special
247
+ // value, which is unfortunately not documented in the REST API, will be interpreted by the
248
+ // Azure DevOps API as an indicator to "not update" the field. The resulting behavior is that
249
+ // this Terraform Resource will be able to update the Service Endpoint without needing to
250
+ // pass the password along in each request.
251
+ func TestAzureDevOpsServiceEndpointAzureRM_ExpandHandlesMissingSpnKeyInAPIResponse (t * testing.T ) {
252
+ // step (1)
253
+ endpoint := getManualAuthServiceEndpoint ()
254
+ resourceData := getResourceData (t , endpoint )
255
+ (* endpoint .Authorization .Parameters )["serviceprincipalkey" ] = ""
256
+
257
+ // step (2)
258
+ flattenServiceEndpointAzureRM (resourceData , & endpoint , azurermTestServiceEndpointAzureRMProjectID )
259
+ expandedEndpoint , _ := expandServiceEndpointAzureRM (resourceData )
260
+
261
+ // step (3)
262
+ spnKeyProperty := (* expandedEndpoint .Authorization .Parameters )["serviceprincipalkey" ]
263
+ require .Equal (t , "null" , spnKeyProperty )
264
+ }
265
+
227
266
/**
228
267
* Begin acceptance tests
229
268
*/
0 commit comments