Skip to content

Commit 3640359

Browse files
authored
Filters in load balancer data sources (#330)
* Filters in load balancer data sources * Add filter test for load balancer shape data source ** make test run=TestAccDatasourceLoadBalancerShapes_basic
1 parent 74dca63 commit 3640359

6 files changed

+36
-2
lines changed

data_source_obmcs_loadbalancer_certificates.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func CertificateDatasource() *schema.Resource {
1515
return &schema.Resource{
1616
Read: readCertificate,
1717
Schema: map[string]*schema.Schema{
18+
"filter": dataSourceFiltersSchema(),
1819
"load_balancer_id": {
1920
Type: schema.TypeString,
2021
Required: true,
@@ -59,6 +60,11 @@ func (s *CertificateDatasourceCrud) SetData() {
5960
}
6061
resources = append(resources, res)
6162
}
63+
64+
if f, fOk := s.D.GetOk("filter"); fOk {
65+
resources = ApplyFilters(f.(*schema.Set), resources)
66+
}
67+
6268
s.D.Set("certificates", resources)
6369
}
6470
return

data_source_obmcs_loadbalancer_loadbalancer_policies.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func LoadBalancerPolicyDatasource() *schema.Resource {
1515
return &schema.Resource{
1616
Read: readPolicies,
1717
Schema: map[string]*schema.Schema{
18+
"filter": dataSourceFiltersSchema(),
1819
"compartment_id": {
1920
Type: schema.TypeString,
2021
Required: true,
@@ -66,6 +67,11 @@ func (s *PoliciesDatasourceCrud) SetData() {
6667
resources = append(resources, res)
6768

6869
}
70+
71+
if f, fOk := s.D.GetOk("filter"); fOk {
72+
resources = ApplyFilters(f.(*schema.Set), resources)
73+
}
74+
6975
s.D.Set("policies", resources)
7076
}
7177
return

data_source_obmcs_loadbalancer_loadbalancer_protocols.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func ProtocolDatasource() *schema.Resource {
1515
return &schema.Resource{
1616
Read: readProtocols,
1717
Schema: map[string]*schema.Schema{
18+
"filter": dataSourceFiltersSchema(),
1819
"compartment_id": {
1920
Type: schema.TypeString,
2021
Required: true,
@@ -66,6 +67,11 @@ func (s *ProtocolDatasourceCrud) SetData() {
6667
resources = append(resources, res)
6768

6869
}
70+
71+
if f, fOk := s.D.GetOk("filter"); fOk {
72+
resources = ApplyFilters(f.(*schema.Set), resources)
73+
}
74+
6975
s.D.Set("protocols", resources)
7076
}
7177
return

data_source_obmcs_loadbalancer_loadbalancer_shapes.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@ func LoadBalancerShapeDatasource() *schema.Resource {
1515
return &schema.Resource{
1616
Read: readLoadBalancerShapes,
1717
Schema: map[string]*schema.Schema{
18+
"filter": dataSourceFiltersSchema(),
1819
"compartment_id": {
1920
Type: schema.TypeString,
2021
Required: true,
@@ -66,6 +67,11 @@ func (s *LoadBalancerShapeDatasourceCrud) SetData() {
6667
resources = append(resources, res)
6768

6869
}
70+
71+
if f, fOk := s.D.GetOk("filter"); fOk {
72+
resources = ApplyFilters(f.(*schema.Set), resources)
73+
}
74+
6975
s.D.Set("shapes", resources)
7076
}
7177
return

data_source_obmcs_loadbalancer_loadbalancer_shapes_test.go

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,10 @@ func TestAccDatasourceLoadBalancerShapes_basic(t *testing.T) {
1313
config := testProviderConfig() + `
1414
data "oci_load_balancer_shapes" "t" {
1515
compartment_id = "${var.compartment_id}"
16+
filter {
17+
name = "name"
18+
values = ["100Mbps"]
19+
}
1620
}`
1721

1822
resourceName := "data.oci_load_balancer_shapes.t"
@@ -26,8 +30,8 @@ func TestAccDatasourceLoadBalancerShapes_basic(t *testing.T) {
2630
ImportStateVerify: true,
2731
Config: config,
2832
Check: resource.ComposeAggregateTestCheckFunc(
29-
resource.TestCheckResourceAttrSet(resourceName, "shapes.#"),
30-
resource.TestCheckResourceAttrSet(resourceName, "shapes.0.name"),
33+
resource.TestCheckResourceAttr(resourceName, "shapes.#", "1"),
34+
resource.TestCheckResourceAttr(resourceName, "shapes.0.name", "100Mbps"),
3135
),
3236
},
3337
},

data_source_obmcs_loadbalancer_loadbalancers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ func LoadBalancerDatasource() *schema.Resource {
1616
return &schema.Resource{
1717
Read: readLoadBalancers,
1818
Schema: map[string]*schema.Schema{
19+
"filter": dataSourceFiltersSchema(),
1920
"compartment_id": {
2021
Type: schema.TypeString,
2122
Required: true,
@@ -73,6 +74,11 @@ func (s *LoadBalancerDatasourceCrud) SetData() {
7374
}
7475

7576
}
77+
78+
if f, fOk := s.D.GetOk("filter"); fOk {
79+
resources = ApplyFilters(f.(*schema.Set), resources)
80+
}
81+
7682
err := s.D.Set("load_balancers", resources)
7783
if err != nil {
7884
log.Printf("[ERROR] Failed to set load_balancers: %v", err)

0 commit comments

Comments
 (0)