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 Sep 28, 2023
1 parent 03c5fe6 commit d80ee43
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 1 deletion.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,11 @@ nav_order: 1

# Changelog


## [3.13.3] - 2023-09-28

- Fix `aiven_project_user` 409 error handling

## [3.13.2] - 2023-06-01

- Improve Kafka Topic 404 error handling
Expand Down
2 changes: 2 additions & 0 deletions internal/service/kafka/kafka_topic_cache_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,8 @@ func TestGetTopicCache(t *testing.T) {
&kafkaTopicCache{
internal: make(map[string]map[string]aiven.KafkaTopic),
inQueue: make(map[string][]string),
missing: make(map[string][]string),
v1list: make(map[string][]string),
},
},
}
Expand Down
12 changes: 11 additions & 1 deletion internal/service/project/project_user.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,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 @@ -58,7 +68,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 d80ee43

Please sign in to comment.