Skip to content

Commit

Permalink
fix(project_user): invite error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
ivan-savciuc committed Oct 2, 2023
1 parent 913aed9 commit 64e1fc4
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
12 changes: 11 additions & 1 deletion internal/sdkprovider/service/project/project_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand All @@ -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)
}

Expand Down

0 comments on commit 64e1fc4

Please sign in to comment.