-
Notifications
You must be signed in to change notification settings - Fork 288
/
Copy pathresource_serviceendpoint_azurecr_test.go
131 lines (120 loc) · 5.62 KB
/
resource_serviceendpoint_azurecr_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
//go:build (all || resource_serviceendpoint_azurecr) && !exclude_serviceendpoints
// +build all resource_serviceendpoint_azurecr
// +build !exclude_serviceendpoints
package acceptancetests
import (
"fmt"
"os"
"testing"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/microsoft/terraform-provider-azuredevops/azuredevops/internal/acceptancetests/testutils"
)
func TestAccServiceEndpointAzureCR_spn_basic(t *testing.T) {
if os.Getenv("TEST_ARM_SUBSCRIPTION_ID") == "" || os.Getenv("TEST_ARM_SUBSCRIPTION_NAME") == "" ||
os.Getenv("TEST_ARM_TENANT_ID") == "" || os.Getenv("TEST_ARM_RESOURCE_GROUP") == "" || os.Getenv("TEST_ARM_ACR_NAME") == "" {
t.Skip("Skip test as `TEST_ARM_SUBSCRIPTION_ID` or `TEST_ARM_SUBSCRIPTION_NAME` or `TEST_ARM_TENANT_ID` or `TEST_ARM_RESOURCE_GROUP` or `TEST_ARM_ACR_NAME` is not set")
}
projectName := testutils.GenerateResourceName()
serviceEndpointNameFirst := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_azurecr"
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: hclAzureCRSpn(projectName, serviceEndpointNameFirst),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_spn_tenantid"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_subscription_id"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_subscription_name"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameFirst),
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameFirst),
),
}, {
ResourceName: tfSvcEpNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(tfSvcEpNode),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func TestAccServiceEndpointAzureCR_spn_update(t *testing.T) {
if os.Getenv("TEST_ARM_SUBSCRIPTION_ID") == "" || os.Getenv("TEST_ARM_SUBSCRIPTION_NAME") == "" ||
os.Getenv("TEST_ARM_TENANT_ID") == "" || os.Getenv("TEST_ARM_RESOURCE_GROUP") == "" || os.Getenv("TEST_ARM_ACR_NAME") == "" {
t.Skip("Skip test as `TEST_ARM_SUBSCRIPTION_ID` or `TEST_ARM_SUBSCRIPTION_NAME` or `TEST_ARM_TENANT_ID` or `TEST_ARM_RESOURCE_GROUP` or `TEST_ARM_ACR_NAME` is not set")
}
projectName := testutils.GenerateResourceName()
serviceEndpointNameFirst := testutils.GenerateResourceName()
serviceEndpointNameSecond := testutils.GenerateResourceName()
resourceType := "azuredevops_serviceendpoint_azurecr"
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: hclAzureCRSpn(projectName, serviceEndpointNameFirst),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_spn_tenantid"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_subscription_id"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_subscription_name"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameFirst),
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameFirst),
),
}, {
ResourceName: tfSvcEpNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(tfSvcEpNode),
ImportState: true,
ImportStateVerify: true,
},
{
Config: hclAzureCRSpn(projectName, serviceEndpointNameSecond),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(tfSvcEpNode, "project_id"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_spn_tenantid"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_subscription_id"),
resource.TestCheckResourceAttrSet(tfSvcEpNode, "azurecr_subscription_name"),
resource.TestCheckResourceAttr(tfSvcEpNode, "service_endpoint_name", serviceEndpointNameSecond),
testutils.CheckServiceEndpointExistsWithName(tfSvcEpNode, serviceEndpointNameSecond),
),
}, {
ResourceName: tfSvcEpNode,
ImportStateIdFunc: testutils.ComputeProjectQualifiedResourceImportID(tfSvcEpNode),
ImportState: true,
ImportStateVerify: true,
},
},
})
}
func hclAzureCRSpn(projectName, serviceConnectionName string) string {
return fmt.Sprintf(`
resource "azuredevops_project" "test" {
name = "%[1]s"
description = "description"
visibility = "private"
version_control = "Git"
work_item_template = "Agile"
}
resource "azuredevops_serviceendpoint_azurecr" "test" {
project_id = azuredevops_project.test.id
service_endpoint_authentication_scheme = "ServicePrincipal"
service_endpoint_name = "%s"
azurecr_spn_tenantid = "%s"
azurecr_subscription_id = "%s"
azurecr_subscription_name = "%s"
resource_group = "%s"
azurecr_name = "%s"
}
`, projectName, serviceConnectionName, os.Getenv("TEST_ARM_TENANT_ID"), os.Getenv("TEST_ARM_SUBSCRIPTION_ID"),
os.Getenv("TEST_ARM_SUBSCRIPTION_NAME"), os.Getenv("TEST_ARM_RESOURCE_GROUP"), os.Getenv("TEST_ARM_ACR_NAME"))
}