Skip to content

Commit a1cf4d7

Browse files
authored
feat(lb): filter LBs with tags on datasource (#2473)
* bump sdk go * feat(lb): filter LBs with tags on datasource
1 parent f629237 commit a1cf4d7

File tree

4 files changed

+787
-583
lines changed

4 files changed

+787
-583
lines changed

docs/data-sources/lbs.md

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,19 @@ data "scaleway_lbs" "my_key" {
2020
name = "foobar"
2121
zone = "fr-par-2"
2222
}
23+
24+
# Find LBs that share the same tags
25+
data "scaleway_lbs" "lbs_by_tags" {
26+
tags = [ "a tag" ]
27+
}
2328
```
2429

2530
## Argument Reference
2631

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

34+
- `tags` - (Optional) List of tags used as filter. LBs with these exact tags are listed.
35+
2936
- `zone` - (Defaults to [provider](../index.md#zone) `zone`) The [zone](../guides/regions_and_zones.md#zones) in which LBs exist.
3037

3138
## Attributes Reference

scaleway/data_source_lbs.go

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,14 @@ func DataSourceScalewayLbs() *schema.Resource {
2020
Optional: true,
2121
Description: "LBs with a name like it are listed.",
2222
},
23+
"tags": {
24+
Type: schema.TypeList,
25+
Elem: &schema.Schema{
26+
Type: schema.TypeString,
27+
},
28+
Optional: true,
29+
Description: "LBs with these exact tags are listed",
30+
},
2331
"lbs": {
2432
Type: schema.TypeList,
2533
Computed: true,
@@ -162,6 +170,7 @@ func dataSourceScalewayLbsRead(ctx context.Context, d *schema.ResourceData, m in
162170
Zone: zone,
163171
Name: types.ExpandStringPtr(d.Get("name")),
164172
ProjectID: types.ExpandStringPtr(d.Get("project_id")),
173+
Tags: types.ExpandStrings(d.Get("tags")),
165174
}, scw.WithContext(ctx))
166175
if err != nil {
167176
return diag.FromErr(err)

scaleway/data_source_lbs_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
3636
name = "tf-lb-datasource0"
3737
description = "a description"
3838
type = "LB-S"
39+
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
3940
}
4041
`,
4142
},
@@ -52,13 +53,15 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
5253
name = "tf-lb-datasource0"
5354
description = "a description"
5455
type = "LB-S"
56+
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
5557
}
5658
5759
resource scaleway_lb lb2 {
5860
ip_id = scaleway_lb_ip.ip2.id
5961
name = "tf-lb-datasource1"
6062
description = "a description"
6163
type = "LB-S"
64+
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
6265
}
6366
`,
6467
},
@@ -75,20 +78,27 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
7578
name = "tf-lb-datasource0"
7679
description = "a description"
7780
type = "LB-S"
81+
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
7882
}
7983
8084
resource scaleway_lb lb2 {
8185
ip_id = scaleway_lb_ip.ip2.id
8286
name = "tf-lb-datasource1"
8387
description = "a description"
8488
type = "LB-S"
89+
tags = [ "terraform-test", "data_scaleway_lbs", "basic" ]
8590
}
8691
8792
data "scaleway_lbs" "lbs_by_name" {
8893
name = "tf-lb-datasource"
8994
depends_on = [scaleway_lb.lb1, scaleway_lb.lb2]
9095
}
9196
97+
data "scaleway_lbs" "lbs_by_tags" {
98+
tags = [ "terraform-test", "data_scaleway_lbs" ]
99+
depends_on = [scaleway_lb.lb1, scaleway_lb.lb2]
100+
}
101+
92102
data "scaleway_lbs" "lbs_by_name_other_zone" {
93103
name = "tf-lb-datasource"
94104
zone = "fr-par-2"
@@ -101,6 +111,9 @@ func TestAccScalewayDataSourceLbs_Basic(t *testing.T) {
101111
resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_name", "lbs.0.name"),
102112
resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_name", "lbs.1.name"),
103113

114+
resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_tags", "lbs.0.id"),
115+
resource.TestCheckResourceAttrSet("data.scaleway_lbs.lbs_by_tags", "lbs.1.id"),
116+
104117
resource.TestCheckNoResourceAttr("data.scaleway_lbs.lbs_by_name_other_zone", "lbs.0.id"),
105118
),
106119
},

0 commit comments

Comments
 (0)