Skip to content

Commit b41b44c

Browse files
[Datasource] Sap profile filtering (#6324)
Co-authored-by: Alexander Kita <[email protected]>
1 parent ed1de63 commit b41b44c

File tree

4 files changed

+49
-1
lines changed

4 files changed

+49
-1
lines changed

ibm/service/power/data_source_ibm_pi_sap_profiles.go

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,18 @@ func DataSourceIBMPISAPProfiles() *schema.Resource {
2626
Type: schema.TypeString,
2727
ValidateFunc: validation.NoZeroValues,
2828
},
29+
Arg_FamilyFilter: {
30+
Description: "SAP profile family filter.",
31+
Optional: true,
32+
Type: schema.TypeString,
33+
ValidateFunc: validation.StringInSlice([]string{"balanced", "compute", "memory", "sap-rise", "sap-rise-app", "small", "ultra-memory"}, false),
34+
},
35+
Arg_PrefixFilter: {
36+
Description: "SAP profile prefix filter.",
37+
Optional: true,
38+
Type: schema.TypeString,
39+
ValidateFunc: validation.StringInSlice([]string{"bh1", "bh2", "ch1", "ch2", "mh1", "mh2", "umh", "ush1", "sh2", "sr2"}, false),
40+
},
2941

3042
// Attributes
3143
Attr_Profiles: {
@@ -106,7 +118,15 @@ func dataSourceIBMPISAPProfilesRead(ctx context.Context, d *schema.ResourceData,
106118
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
107119

108120
client := instance.NewIBMPISAPInstanceClient(ctx, sess, cloudInstanceID)
109-
sapProfiles, err := client.GetAllSAPProfiles(cloudInstanceID)
121+
filters := map[string]string{}
122+
if v, ok := d.GetOk(Arg_FamilyFilter); ok {
123+
filters[Arg_FamilyFilter] = v.(string)
124+
}
125+
if v, ok := d.GetOk(Arg_PrefixFilter); ok {
126+
filters[Arg_PrefixFilter] = v.(string)
127+
}
128+
129+
sapProfiles, err := client.GetAllSAPProfilesWithFilters(cloudInstanceID, filters)
110130
if err != nil {
111131
log.Printf("[DEBUG] get all sap profiles failed %v", err)
112132
return diag.FromErr(err)

ibm/service/power/data_source_ibm_pi_sap_profiles_test.go

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -33,3 +33,27 @@ func testAccCheckIBMPISAPProfilesDataSourceConfig() string {
3333
pi_cloud_instance_id = "%s"
3434
}`, acc.Pi_cloud_instance_id)
3535
}
36+
37+
func TestAccIBMPISAPProfilesDataSourceFilters(t *testing.T) {
38+
resource.Test(t, resource.TestCase{
39+
PreCheck: func() { acc.TestAccPreCheck(t) },
40+
Providers: acc.TestAccProviders,
41+
Steps: []resource.TestStep{
42+
{
43+
Config: testAccCheckIBMPISAPProfilesDataSourceFiltersConfig(),
44+
Check: resource.ComposeTestCheckFunc(
45+
resource.TestCheckResourceAttrSet("data.ibm_pi_sap_profiles.test", "id"),
46+
),
47+
},
48+
},
49+
})
50+
}
51+
52+
func testAccCheckIBMPISAPProfilesDataSourceFiltersConfig() string {
53+
return fmt.Sprintf(`
54+
data "ibm_pi_sap_profiles" "test" {
55+
pi_cloud_instance_id = "%s"
56+
pi_family_filter = "balanced"
57+
pi_prefix_filter = "bh1"
58+
}`, acc.Pi_cloud_instance_id)
59+
}

ibm/service/power/ibm_pi_constants.go

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -49,6 +49,7 @@ const (
4949
Arg_DNS = "pi_dns"
5050
Arg_DnsServer = "pi_dns_server"
5151
Arg_EndingIPAddress = "pi_ending_ip_address"
52+
Arg_FamilyFilter = "pi_family_filter"
5253
Arg_Gateway = "pi_gateway"
5354
Arg_HealthStatus = "pi_health_status"
5455
Arg_Host = "pi_host"
@@ -100,6 +101,7 @@ const (
100101
Arg_PlacementGroupName = "pi_placement_group_name"
101102
Arg_PlacementGroupPolicy = "pi_placement_group_policy"
102103
Arg_Plan = "pi_plan"
104+
Arg_PrefixFilter = "pi_prefix_filter"
103105
Arg_Processors = "pi_processors"
104106
Arg_ProcType = "pi_proc_type"
105107
Arg_Protocol = "pi_protocol"

website/docs/d/pi_sap_profiles.html.markdown

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Example usage:
3939
Review the argument references that you can specify for your data source.
4040

4141
- `pi_cloud_instance_id` - (Required, String) The GUID of the service instance associated with an account.
42+
- `pi_family_filter` - (Optional, String) SAP profile family filter. Allowed values are: ["balanced", "compute", "memory", "sap-rise", "sap-rise-app", "small", "ultra-memory"].
43+
- `pi_prefix_filter` - (Optional, String) SAP profile prefix filter. Allowed values are: ["bh1", "bh2", "ch1", "ch2", "mh1", "mh2", "umh", "ush1", "sh2", "sr2"].
4244

4345
## Attribute Reference
4446

0 commit comments

Comments
 (0)