Skip to content

Commit de3222a

Browse files
jvasseurMonitob
andauthored
Fix scaleway_rdb_instance using name as a pattern instead of an exact match (#1862)
* fix: rdb_instance using name as a pattern instead of an exact match * Empty commit --------- Co-authored-by: jaime Bernabe <[email protected]>
1 parent 4eeb28c commit de3222a

File tree

1 file changed

+9
-5
lines changed

1 file changed

+9
-5
lines changed

scaleway/data_source_rdb_instance.go

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -46,13 +46,17 @@ func dataSourceScalewayRDBInstanceRead(ctx context.Context, d *schema.ResourceDa
4646
if err != nil {
4747
return diag.FromErr(err)
4848
}
49-
if len(res.Instances) == 0 {
50-
return diag.FromErr(fmt.Errorf("no instances found with the name %s", d.Get("name")))
49+
for _, instance := range res.Instances {
50+
if instance.Name == d.Get("name").(string) {
51+
if instanceID != "" {
52+
return diag.FromErr(fmt.Errorf("more than 1 instance found with the same name %s", d.Get("name")))
53+
}
54+
instanceID = instance.ID
55+
}
5156
}
52-
if len(res.Instances) > 1 {
53-
return diag.FromErr(fmt.Errorf("%d instances found with the same name %s", len(res.Instances), d.Get("name")))
57+
if instanceID == "" {
58+
return diag.FromErr(fmt.Errorf("no instance found with the name %s", d.Get("name")))
5459
}
55-
instanceID = res.Instances[0].ID
5660
}
5761

5862
regionalID := datasourceNewRegionalizedID(instanceID, region)

0 commit comments

Comments
 (0)