@@ -14,6 +14,8 @@ import (
14
14
"github.com/hashicorp/terraform-provider-vault/testutil"
15
15
)
16
16
17
+ // TestAccDataSourceAzureAccessCredentials_basic tests the creation of dynamic
18
+ // service principals
17
19
func TestAccDataSourceAzureAccessCredentials_basic (t * testing.T ) {
18
20
// This test takes a while because it's testing a loop that
19
21
// retries real credentials until they're eventually consistent.
@@ -38,6 +40,68 @@ func TestAccDataSourceAzureAccessCredentials_basic(t *testing.T) {
38
40
})
39
41
}
40
42
43
+ // TestAccDataSourceAzureAccessCredentials_basic tests the credential
44
+ // generation for existing service principals
45
+ func TestAccDataSourceAzureAccessCredentials_ExistingSP (t * testing.T ) {
46
+ // This test takes a while because it's testing a loop that
47
+ // retries real credentials until they're eventually consistent.
48
+ if testing .Short () {
49
+ t .SkipNow ()
50
+ }
51
+ mountPath := acctest .RandomWithPrefix ("tf-test-azure" )
52
+ conf := testutil .GetTestAzureConfExistingSP (t )
53
+ resource .Test (t , resource.TestCase {
54
+ ProviderFactories : providerFactories ,
55
+ PreCheck : func () { testutil .TestAccPreCheck (t ) },
56
+ Steps : []resource.TestStep {
57
+ {
58
+ Config : testAccDataSourceAzureAccessCredentialsConfig_existingSP (mountPath , conf , 60 ),
59
+ Check : resource .ComposeTestCheckFunc (
60
+ resource .TestCheckResourceAttrSet ("data.vault_azure_access_credentials.test" , "client_id" ),
61
+ resource .TestCheckResourceAttrSet ("data.vault_azure_access_credentials.test" , "client_secret" ),
62
+ resource .TestCheckResourceAttrSet ("data.vault_azure_access_credentials.test" , "lease_id" ),
63
+ ),
64
+ },
65
+ },
66
+ })
67
+ }
68
+
69
+ func testAccDataSourceAzureAccessCredentialsConfig_existingSP (mountPath string , conf * testutil.AzureTestConf , maxSecs int ) string {
70
+ template := `
71
+ resource "vault_azure_secret_backend" "test" {
72
+ path = "{{mountPath}}"
73
+ subscription_id = "{{subscriptionID}}"
74
+ tenant_id = "{{tenantID}}"
75
+ client_id = "{{clientID}}"
76
+ client_secret = "{{clientSecret}}"
77
+ }
78
+
79
+ resource "vault_azure_secret_backend_role" "test" {
80
+ backend = vault_azure_secret_backend.test.path
81
+ role = "my-role"
82
+ application_object_id = "{{appObjectID}}"
83
+ ttl = 300
84
+ max_ttl = 600
85
+ }
86
+
87
+ data "vault_azure_access_credentials" "test" {
88
+ backend = vault_azure_secret_backend.test.path
89
+ role = vault_azure_secret_backend_role.test.role
90
+ validate_creds = true
91
+ num_seconds_between_tests = 1
92
+ max_cred_validation_seconds = {{maxCredValidationSeconds}}
93
+ }`
94
+
95
+ parsed := strings .Replace (template , "{{mountPath}}" , mountPath , - 1 )
96
+ parsed = strings .Replace (parsed , "{{subscriptionID}}" , conf .SubscriptionID , - 1 )
97
+ parsed = strings .Replace (parsed , "{{tenantID}}" , conf .TenantID , - 1 )
98
+ parsed = strings .Replace (parsed , "{{clientID}}" , conf .ClientID , - 1 )
99
+ parsed = strings .Replace (parsed , "{{clientSecret}}" , conf .ClientSecret , - 1 )
100
+ parsed = strings .Replace (parsed , "{{appObjectID}}" , conf .AppObjectID , - 1 )
101
+ parsed = strings .Replace (parsed , "{{maxCredValidationSeconds}}" , strconv .Itoa (maxSecs ), - 1 )
102
+ return parsed
103
+ }
104
+
41
105
func testAccDataSourceAzureAccessCredentialsConfigBasic (mountPath string , conf * testutil.AzureTestConf , maxSecs int ) string {
42
106
template := `
43
107
resource "vault_azure_secret_backend" "test" {
0 commit comments