-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathdata_serviceendpoint_azurerm_test.go
111 lines (99 loc) · 5.09 KB
/
data_serviceendpoint_azurerm_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
//go:build (all || data_sources || data_serviceendpoint_azurerm) && (!exclude_data_sources || !exclude_data_serviceendpoint_azurerm)
// +build all data_sources data_serviceendpoint_azurerm
// +build !exclude_data_sources !exclude_data_serviceendpoint_azurerm
package acceptancetests
import (
"fmt"
"net/url"
"os"
"path"
"regexp"
"testing"
"github.com/google/uuid"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)
func TestAccServiceEndpointAzureRM_dataSource_with_serviceEndpointID(t *testing.T) {
serviceEndpointAzureRMName := testutils.GenerateResourceName()
serviceprincipalid := uuid.New().String()
serviceprincipalkey := uuid.New().String()
projectName := testutils.GenerateResourceName()
serviceEndpointAuthenticationScheme := "ServicePrincipal"
createServiceEndpointAzureRMWithServiceEndpointIDData := fmt.Sprintf("%s\n%s",
testutils.HclServiceEndpointAzureRMResource(projectName, serviceEndpointAzureRMName, serviceprincipalid, serviceprincipalkey, serviceEndpointAuthenticationScheme),
testutils.HclServiceEndpointAzureRMDataSourceWithServiceEndpointID(),
)
tfNode := "data.azuredevops_serviceendpoint_azurerm.serviceendpointrm"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: createServiceEndpointAzureRMWithServiceEndpointIDData,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointAzureRMName),
resource.TestCheckResourceAttrSet(tfNode, "service_endpoint_id"),
resource.TestCheckResourceAttr(tfNode, "service_endpoint_authentication_scheme", serviceEndpointAuthenticationScheme),
),
},
},
})
}
func TestAccServiceEndpointAzureRM_dataSource_with_serviceEndpointName(t *testing.T) {
serviceEndpointAzureRMName := testutils.GenerateResourceName()
projectName := testutils.GenerateResourceName()
serviceprincipalid := uuid.New().String()
serviceprincipalkey := uuid.New().String()
serviceEndpointAuthenticationScheme := "ServicePrincipal"
createServiceEndpointAzureRMWithServiceEndpointNameData := fmt.Sprintf("%s\n%s",
testutils.HclServiceEndpointAzureRMResource(projectName, serviceEndpointAzureRMName, serviceprincipalid, serviceprincipalkey, serviceEndpointAuthenticationScheme),
testutils.HclServiceEndpointAzureRMDataSourceWithServiceEndpointName(serviceEndpointAzureRMName),
)
tfNode := "data.azuredevops_serviceendpoint_azurerm.serviceendpointrm"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: createServiceEndpointAzureRMWithServiceEndpointNameData,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointAzureRMName),
resource.TestCheckResourceAttrSet(tfNode, "service_endpoint_id"),
resource.TestCheckResourceAttr(tfNode, "service_endpoint_authentication_scheme", serviceEndpointAuthenticationScheme),
),
},
},
})
}
func TestAccServiceEndpointAzureRM_dataSource_with_WorkloadIdentityFederation(t *testing.T) {
serviceEndpointAzureRMName := testutils.GenerateResourceName()
projectName := testutils.GenerateResourceName()
serviceprincipalid := uuid.New().String()
serviceEndpointAuthenticationScheme := "WorkloadIdentityFederation"
azureDevOpsOrgName := "terraform-provider-azuredevops"
if os.Getenv("AZDO_ORG_SERVICE_URL") != "" {
azureDevOpsOrgUrl, _ := url.Parse(os.Getenv("AZDO_ORG_SERVICE_URL"))
azureDevOpsOrgName = path.Base(azureDevOpsOrgUrl.Path)
}
createServiceEndpointAzureRMWithServiceEndpointNameData := fmt.Sprintf("%s\n%s",
testutils.HclServiceEndpointAzureRMNoKeyResource(projectName, serviceEndpointAzureRMName, serviceprincipalid, serviceEndpointAuthenticationScheme),
testutils.HclServiceEndpointAzureRMDataSourceWithServiceEndpointName(serviceEndpointAzureRMName),
)
tfNode := "data.azuredevops_serviceendpoint_azurerm.serviceendpointrm"
resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testutils.PreCheck(t, nil) },
Providers: testutils.GetProviders(),
Steps: []resource.TestStep{
{
Config: createServiceEndpointAzureRMWithServiceEndpointNameData,
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(tfNode, "service_endpoint_name", serviceEndpointAzureRMName),
resource.TestCheckResourceAttrSet(tfNode, "service_endpoint_id"),
resource.TestCheckResourceAttr(tfNode, "service_endpoint_authentication_scheme", serviceEndpointAuthenticationScheme),
resource.TestMatchResourceAttr(tfNode, "workload_identity_federation_issuer", regexp.MustCompile("^https://vstoken.dev.azure.com/[a-fA-F0-9]{8}-[a-fA-F0-9]{4}-4[a-fA-F0-9]{3}-[8|9|aA|bB][a-fA-F0-9]{3}-[a-fA-F0-9]{12}$")),
resource.TestCheckResourceAttr(tfNode, "workload_identity_federation_subject", fmt.Sprintf("sc://%s/%s/%s", azureDevOpsOrgName, projectName, serviceEndpointAzureRMName)),
),
},
},
})
}