diff --git a/CHANGELOG.md b/CHANGELOG.md index 6ab3b413..8522475d 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,12 @@ Canonical reference for changes, improvements, and bugfixes for the Boundary Ter * Add support for setting mapping overrides for vault credential libraries ([PR](https://github.com/hashicorp/terraform-provider-boundary/pull/287)). + +### Bug Fixes + +* Improve error message when authenticating to boundary. + ([PR](https://github.com/hashicorp/terraform-provider-boundary/pull/290)). + ## 1.1.1 (October 12, 2022) ### Bug Fixes diff --git a/internal/provider/provider.go b/internal/provider/provider.go index 481c8094..1887d2b6 100644 --- a/internal/provider/provider.go +++ b/internal/provider/provider.go @@ -4,6 +4,7 @@ import ( "context" "errors" "fmt" + "net/http" "strings" "github.com/hashicorp/boundary/api" @@ -176,6 +177,15 @@ func providerAuthenticate(ctx context.Context, d *schema.ResourceData, md *metaD at, err := am.Authenticate(ctx, authMethodId.(string), "login", credentials) if err != nil { + if apiErr := api.AsServerError(err); apiErr != nil { + statusCode := apiErr.Response().StatusCode() + if statusCode == http.StatusNotFound { + return fmt.Errorf("unknown auth_method_id: %s", err.Error()) + } + if statusCode == http.StatusUnauthorized { + return fmt.Errorf("invalid login name or password: %s", err.Error()) + } + } return err } md.client.SetToken(at.Attributes["token"].(string))