diff --git a/CHANGELOG.md b/CHANGELOG.md index 4f7c9dfe3..fc7682638 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -9,6 +9,7 @@ nav_order: 1 ## [MAJOR.MINOR.PATCH] - YYYY-MM-DD - Allow to modify `pg_user` replication settings +- Fix `aiven_project_user` 409 error handling ## [4.9.0] - 2023-09-18 diff --git a/internal/sdkprovider/service/project/project_user.go b/internal/sdkprovider/service/project/project_user.go index f339547d3..683b0448b 100644 --- a/internal/sdkprovider/service/project/project_user.go +++ b/internal/sdkprovider/service/project/project_user.go @@ -48,6 +48,16 @@ func ResourceProjectUser() *schema.Resource { } } +// isProjectUserAlreadyInvited return true if user already been invited to the project +func isProjectUserAlreadyInvited(err error) bool { + if e, ok := err.(aiven.Error); ok { + if strings.Contains(e.Message, "already been invited to this project") && e.Status == 409 { + return true + } + } + return false +} + func resourceProjectUserCreate(ctx context.Context, d *schema.ResourceData, m interface{}) diag.Diagnostics { client := m.(*aiven.Client) projectName := d.Get("project").(string) @@ -60,7 +70,7 @@ func resourceProjectUserCreate(ctx context.Context, d *schema.ResourceData, m in MemberType: d.Get("member_type").(string), }, ) - if err != nil { + if err != nil && !isProjectUserAlreadyInvited(err) { return diag.FromErr(err) }