Skip to content

Commit d8164d9

Browse files
Monitobremyleone
andauthored
fix(rdb): check user exist (#1720)
Co-authored-by: Rémy Léone <[email protected]>
1 parent fc8ba95 commit d8164d9

File tree

2 files changed

+7
-1
lines changed

2 files changed

+7
-1
lines changed

docs/resources/rdb_user.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ resource "random_password" "db_password" {
2121
2222
resource "scaleway_rdb_user" "db_admin" {
2323
instance_id = scaleway_rdb_instance.main.id
24-
name = "titi"
24+
name = "devtools"
2525
password = random_password.db_password.result
2626
is_admin = true
2727
}

scaleway/resource_rdb_user.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@ import (
55
"fmt"
66
"strings"
77

8+
"github.com/hashicorp/terraform-plugin-log/tflog"
89
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
910
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
1011
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
@@ -137,6 +138,11 @@ func resourceScalewayRdbUserRead(ctx context.Context, d *schema.ResourceData, me
137138
}
138139
return diag.FromErr(err)
139140
}
141+
if len(res.Users) == 0 {
142+
tflog.Warn(ctx, fmt.Sprintf("couldn'd find user with name: [%s]", userName))
143+
d.SetId("")
144+
return nil
145+
}
140146

141147
user := res.Users[0]
142148
_ = d.Set("instance_id", newRegionalID(region, instanceID).String())

0 commit comments

Comments
 (0)