From d80ee430e8c1f816c1d76ab110e80bde9d35b951 Mon Sep 17 00:00:00 2001 From: Ivan Savciuc Date: Thu, 28 Sep 2023 10:16:39 +0300 Subject: [PATCH] fix(project_user): invite error handling --- CHANGELOG.md | 5 +++++ internal/service/kafka/kafka_topic_cache_test.go | 2 ++ internal/service/project/project_user.go | 12 +++++++++++- 3 files changed, 18 insertions(+), 1 deletion(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index d8473e3c5..0e889ebef 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -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 diff --git a/internal/service/kafka/kafka_topic_cache_test.go b/internal/service/kafka/kafka_topic_cache_test.go index 6b166888f..74cba56ce 100644 --- a/internal/service/kafka/kafka_topic_cache_test.go +++ b/internal/service/kafka/kafka_topic_cache_test.go @@ -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), }, }, } diff --git a/internal/service/project/project_user.go b/internal/service/project/project_user.go index 41caa1eb2..0168ccae3 100644 --- a/internal/service/project/project_user.go +++ b/internal/service/project/project_user.go @@ -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) @@ -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) }