Skip to content

Commit

Permalink
feat(lb): filter LBs with tags on datasource (#2473)
Browse files Browse the repository at this point in the history
* bump sdk go

* feat(lb): filter LBs with tags on datasource
  • Loading branch information
yfodil committed Mar 26, 2024
1 parent f629237 commit a1cf4d7
Show file tree
Hide file tree
Showing 4 changed files with 787 additions and 583 deletions.
7 changes: 7 additions & 0 deletions docs/data-sources/lbs.md
Expand Up @@ -20,12 +20,19 @@ data "scaleway_lbs" "my_key" {
name = "foobar"
zone = "fr-par-2"
}
# Find LBs that share the same tags
data "scaleway_lbs" "lbs_by_tags" {
tags = [ "a tag" ]
}
```

## Argument Reference

- `name` - (Optional) The load balancer name used as a filter. LBs with a name like it are listed.

- `tags` - (Optional) List of tags used as filter. LBs with these exact tags are listed.

- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which LBs exist.

## Attributes Reference
Expand Down
9 changes: 9 additions & 0 deletions scaleway/data_source_lbs.go
Expand Up @@ -20,6 +20,14 @@ func DataSourceScalewayLbs() *schema.Resource {
Optional: true,
Description: "LBs with a name like it are listed.",
},
"tags": {
Type: schema.TypeList,
Elem: &schema.Schema{
Type: schema.TypeString,
},
Optional: true,
Description: "LBs with these exact tags are listed",
},
"lbs": {
Type: schema.TypeList,
Computed: true,
Expand Down Expand Up @@ -162,6 +170,7 @@ func dataSourceScalewayLbsRead(ctx context.Context, d *schema.ResourceData, m in
Zone: zone,
Name: types.ExpandStringPtr(d.Get("name")),
ProjectID: types.ExpandStringPtr(d.Get("project_id")),
Tags: types.ExpandStrings(d.Get("tags")),
}, scw.WithContext(ctx))
if err != nil {
return diag.FromErr(err)
Expand Down
13 changes: 13 additions & 0 deletions scaleway/data_source_lbs_test.go
Expand Up @@ -36,6 +36,7 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
name = "tf-lb-datasource0"
description = "a description"
type = "LB-S"
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
}
`,
},
Expand All @@ -52,13 +53,15 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
name = "tf-lb-datasource0"
description = "a description"
type = "LB-S"
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
}
resource scaleway_lb lb2 {
ip_id = scaleway_lb_ip.ip2.id
name = "tf-lb-datasource1"
description = "a description"
type = "LB-S"
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
}
`,
},
Expand All @@ -75,20 +78,27 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
name = "tf-lb-datasource0"
description = "a description"
type = "LB-S"
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
}
resource scaleway_lb lb2 {
ip_id = scaleway_lb_ip.ip2.id
name = "tf-lb-datasource1"
description = "a description"
type = "LB-S"
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
}
data "scaleway_lbs" "lbs_by_name" {
name = "tf-lb-datasource"
depends_on = [scaleway_lb.lb1, scaleway_lb.lb2]
}
data "scaleway_lbs" "lbs_by_tags" {
tags = [ "terraform-test", "data_scaleway_lbs" ]
depends_on = [scaleway_lb.lb1, scaleway_lb.lb2]
}
data "scaleway_lbs" "lbs_by_name_other_zone" {
name = "tf-lb-datasource"
zone = "fr-par-2"
Expand All @@ -101,6 +111,9 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_name", "lbs.0.name"),
resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_name", "lbs.1.name"),

resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_tags", "lbs.0.id"),
resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_tags", "lbs.1.id"),

resource.TestCheckNoResourceAttr("data.scaleway_lbs.lbs_by_name_other_zone", "lbs.0.id"),
),
},
Expand Down

0 comments on commit a1cf4d7

Please sign in to comment.