Skip to content

Commit 7caa8c9

Browse files
committed
Improve error message for InstancePrincipal authentication
1 parent fc16965 commit 7caa8c9

File tree

2 files changed

+8
-6
lines changed

2 files changed

+8
-6
lines changed

oci/provider.go

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -600,8 +600,7 @@ func ProviderConfig(d *schema.ResourceData) (clients interface{}, err error) {
600600
case strings.ToLower(authInstancePrincipalSetting):
601601
apiKeyConfigVariablesToUnset, ok := checkIncompatibleAttrsForApiKeyAuth(d)
602602
if !ok {
603-
return nil, fmt.Errorf(`authentication (%s) is set to "%s". To use "%s" authentication user credentials should be removed from the configuration.
604-
The values for the %v are provided now.`, ociVarName(authAttrName), authInstancePrincipalSetting, authInstancePrincipalSetting, apiKeyConfigVariablesToUnset)
603+
return nil, fmt.Errorf(`user credentials %v should be removed from the configuration`, apiKeyConfigVariablesToUnset)
605604
}
606605

607606
region, ok := d.GetOkExists(regionAttrName)
@@ -616,8 +615,7 @@ The values for the %v are provided now.`, ociVarName(authAttrName), authInstance
616615
case strings.ToLower(authInstancePrincipalWithCertsSetting):
617616
apiKeyConfigVariablesToUnset, ok := checkIncompatibleAttrsForApiKeyAuth(d)
618617
if !ok {
619-
return nil, fmt.Errorf(`authentication (%s) is set to "%s". To use "%s" authentication user credentials should be removed from the configuration.
620-
The values for the %v are provided now.`, ociVarName(authAttrName), authInstancePrincipalWithCertsSetting, authInstancePrincipalWithCertsSetting, apiKeyConfigVariablesToUnset)
618+
return nil, fmt.Errorf(`user credentials %v should be removed from the configuration`, apiKeyConfigVariablesToUnset)
621619
}
622620

623621
region, ok := d.GetOkExists(regionAttrName)

oci/provider_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -370,10 +370,14 @@ func providerConfigTest(t *testing.T, disableRetries bool, skipRequiredField boo
370370
return
371371
}
372372
case authInstancePrincipalSetting:
373-
assert.Regexp(t, "authentication .* is set to .* To use .* authentication user credentials should be removed from the configuration.*", err.Error())
373+
apiKeyConfigVariablesToUnset, ok := checkIncompatibleAttrsForApiKeyAuth(d)
374+
assert.False(t, ok)
375+
assert.Equal(t, fmt.Sprintf("user credentials %v should be removed from the configuration", apiKeyConfigVariablesToUnset), err.Error())
374376
return
375377
case authInstancePrincipalWithCertsSetting:
376-
assert.Regexp(t, "authentication .* is set to .* To use .* authentication user credentials should be removed from the configuration.*", err.Error())
378+
apiKeyConfigVariablesToUnset, ok := checkIncompatibleAttrsForApiKeyAuth(d)
379+
assert.False(t, ok)
380+
assert.Equal(t, fmt.Sprintf("user credentials %v should be removed from the configuration", apiKeyConfigVariablesToUnset), err.Error())
377381
return
378382
default:
379383
assert.Error(t, err, fmt.Sprintf("auth must be one of '%s' or '%s' or '%s'", authAPIKeySetting, authInstancePrincipalSetting, authInstancePrincipalWithCertsSetting))

0 commit comments

Comments
 (0)