Skip to content

Commit a8e6fc5

Browse files
authored
feat(rdb_instance): add project_id filter to datasource (#2316)
1 parent 1eb5747 commit a8e6fc5

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

docs/data-sources/rdb_instance.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,8 @@ output "load_balancer_ip_addr" {
3636
- `instance_id` - (Optional) The RDB instance ID.
3737
Only one of `name` and `instance_id` should be specified.
3838

39+
- `project_id` - (Optional) The ID of the project the RDB instance is in. Can be used to filter instances when using `name`.
40+
3941
- `region` - (Defaults to [provider](../index.md#region) `region`) The [region](../guides/regions_and_zones.md#zones) in which the RDB instance exists.
4042

4143
- `organization_id` - (Defaults to [provider](../index.md#organization_id) `organization_id`) The ID of the organization the RDB instance is in.

scaleway/data_source_rdb_instance.go

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ func dataSourceScalewayRDBInstance() *schema.Resource {
2323
ConflictsWith: []string{"name"},
2424
ValidateFunc: validationUUIDorUUIDWithLocality(),
2525
}
26+
dsSchema["project_id"].Optional = true
2627

2728
return &schema.Resource{
2829
ReadContext: dataSourceScalewayRDBInstanceRead,
@@ -38,10 +39,16 @@ func dataSourceScalewayRDBInstanceRead(ctx context.Context, d *schema.ResourceDa
3839

3940
instanceID, ok := d.GetOk("instance_id")
4041
if !ok { // Get instance by region and name.
42+
var projectID *string
43+
if projectIDRaw, filterByProject := d.GetOk("project_id"); filterByProject {
44+
projectID = scw.StringPtr(projectIDRaw.(string))
45+
}
46+
4147
instanceName := d.Get("name").(string)
4248
res, err := api.ListInstances(&rdb.ListInstancesRequest{
43-
Region: region,
44-
Name: scw.StringPtr(instanceName),
49+
Region: region,
50+
Name: scw.StringPtr(instanceName),
51+
ProjectID: projectID,
4552
}, scw.WithContext(ctx))
4653
if err != nil {
4754
return diag.FromErr(err)

0 commit comments

Comments
 (0)