Skip to content

Commit d542a4a

Browse files
authored
[DataSource] [Resource] Add Software Tier support for data sources and resources (IBM-Cloud#6321)
* [DataSource] [Resource] Add Software Tier support for data sources and resources * Update Attr_SupportedSoftwareTiers name
1 parent 3f1ffd4 commit d542a4a

18 files changed

+624
-101
lines changed

ibm/provider/provider.go

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -758,6 +758,7 @@ func Provider() *schema.Provider {
758758
"ibm_pi_sap_profiles": power.DataSourceIBMPISAPProfiles(),
759759
"ibm_pi_shared_processor_pool": power.DataSourceIBMPISharedProcessorPool(),
760760
"ibm_pi_shared_processor_pools": power.DataSourceIBMPISharedProcessorPools(),
761+
"ibm_pi_software_tiers": power.DataSourceIBMPISoftwareTiers(),
761762
"ibm_pi_spp_placement_group": power.DataSourceIBMPISPPPlacementGroup(),
762763
"ibm_pi_spp_placement_groups": power.DataSourceIBMPISPPPlacementGroups(),
763764
"ibm_pi_storage_pool_capacity": power.DataSourceIBMPIStoragePoolCapacity(),

ibm/service/power/data_source_ibm_pi_instance.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -262,6 +262,11 @@ func DataSourceIBMPIInstance() *schema.Resource {
262262
Description: "Virtual serial number.",
263263
Type: schema.TypeString,
264264
},
265+
Attr_SoftwareTier: {
266+
Computed: true,
267+
Description: "Software tier.",
268+
Type: schema.TypeString,
269+
},
265270
},
266271
},
267272
Type: schema.TypeList,

ibm/service/power/data_source_ibm_pi_instances.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,11 @@ func DataSourceIBMPIInstances() *schema.Resource {
243243
Description: "Virtual serial number.",
244244
Type: schema.TypeString,
245245
},
246+
Attr_SoftwareTier: {
247+
Computed: true,
248+
Description: "Software tier.",
249+
Type: schema.TypeString,
250+
},
246251
},
247252
},
248253
Type: schema.TypeList,
Lines changed: 86 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,86 @@
1+
// Copyright IBM Corp. 2025 All Rights Reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package power
5+
6+
import (
7+
"context"
8+
9+
"github.com/IBM-Cloud/power-go-client/clients/instance"
10+
"github.com/IBM-Cloud/power-go-client/power/models"
11+
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
12+
"github.com/hashicorp/go-uuid"
13+
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
14+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
15+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/validation"
16+
)
17+
18+
func DataSourceIBMPISoftwareTiers() *schema.Resource {
19+
return &schema.Resource{
20+
ReadContext: dataSourceIBMPISoftwareTiersRead,
21+
Schema: map[string]*schema.Schema{
22+
// Arguments
23+
Arg_CloudInstanceID: {
24+
Description: "The GUID of the service instance associated with an account.",
25+
Required: true,
26+
Type: schema.TypeString,
27+
ValidateFunc: validation.NoZeroValues,
28+
},
29+
30+
// Attributes
31+
Attr_SupportedSoftwareTiers: {
32+
Computed: true,
33+
Description: "List of supported software tiers (IBMi licensing).",
34+
Elem: &schema.Resource{
35+
Schema: map[string]*schema.Schema{
36+
Attr_SupportedSystems: {
37+
Computed: true,
38+
Description: "List of supported systems.",
39+
Elem: schema.TypeString,
40+
Type: schema.TypeList,
41+
},
42+
Attr_SoftwareTier: {
43+
Computed: true,
44+
Description: "Software tier.",
45+
Type: schema.TypeString,
46+
},
47+
},
48+
},
49+
Type: schema.TypeList,
50+
},
51+
},
52+
}
53+
}
54+
55+
func dataSourceIBMPISoftwareTiersRead(ctx context.Context, d *schema.ResourceData, meta interface{}) diag.Diagnostics {
56+
sess, err := meta.(conns.ClientSession).IBMPISession()
57+
if err != nil {
58+
return diag.FromErr(err)
59+
}
60+
61+
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
62+
63+
client := instance.NewIBMPIVSNClient(ctx, sess, cloudInstanceID)
64+
tiers, err := client.GetAllSoftwareTiers()
65+
if err != nil {
66+
return diag.Errorf("error on GET of virtual serial number software tiers: %v", err)
67+
}
68+
69+
var genID, _ = uuid.GenerateUUID()
70+
d.SetId(genID)
71+
d.Set(Attr_SupportedSoftwareTiers, flattenSoftwareTiers(tiers))
72+
73+
return nil
74+
}
75+
76+
func flattenSoftwareTiers(tiers models.SupportedSoftwareTierList) []map[string]interface{} {
77+
result := []map[string]interface{}{}
78+
for _, tier := range tiers {
79+
t := map[string]interface{}{
80+
Attr_SupportedSystems: tier.SupportedSystems,
81+
Attr_SoftwareTier: tier.Tier,
82+
}
83+
result = append(result, t)
84+
}
85+
return result
86+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// Copyright IBM Corp. 2022 All Rights Reserved.
2+
// Licensed under the Mozilla Public License v2.0
3+
4+
package power_test
5+
6+
import (
7+
"fmt"
8+
"testing"
9+
10+
acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"
11+
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
12+
)
13+
14+
func TestAccIBMPISoftwareTiersDataSourceBasic(t *testing.T) {
15+
resource.Test(t, resource.TestCase{
16+
PreCheck: func() { acc.TestAccPreCheck(t) },
17+
Providers: acc.TestAccProviders,
18+
Steps: []resource.TestStep{
19+
{
20+
Config: testAccCheckIBMPISoftwareTiersDataSourceConfig(),
21+
Check: resource.ComposeTestCheckFunc(
22+
resource.TestCheckResourceAttrSet("data.ibm_pi_software_tiers.test", "id"),
23+
),
24+
},
25+
},
26+
})
27+
}
28+
29+
func testAccCheckIBMPISoftwareTiersDataSourceConfig() string {
30+
return fmt.Sprintf(`
31+
data "ibm_pi_software_tiers" "test" {
32+
pi_cloud_instance_id = "%s"
33+
}`, acc.Pi_cloud_instance_id)
34+
}

ibm/service/power/data_source_ibm_pi_virtual_serial_number.go

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,11 @@ func DataSourceIBMPIVirtualSerialNumber() *schema.Resource {
4343
Description: "ID of PVM instance virtual serial number is attached to.",
4444
Type: schema.TypeString,
4545
},
46+
Attr_SoftwareTier: {
47+
Computed: true,
48+
Description: "Software tier for virtual serial number.",
49+
Type: schema.TypeString,
50+
},
4651
},
4752
}
4853
}
@@ -68,6 +73,9 @@ func dataSourceIBMPIVirtualSerialNumberRead(ctx context.Context, d *schema.Resou
6873
if virtualSerialNumberData.PvmInstanceID != nil {
6974
d.Set(Attr_InstanceID, virtualSerialNumberData.PvmInstanceID)
7075
}
76+
if virtualSerialNumberData.SoftwareTier != "" {
77+
d.Set(Attr_SoftwareTier, virtualSerialNumberData.SoftwareTier)
78+
}
7179

7280
return nil
7381
}

ibm/service/power/data_source_ibm_pi_virtual_serial_numbers.go

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,11 @@ func DataSourceIBMPIVirtualSerialNumbers() *schema.Resource {
5252
Description: "Virtual Serial Number.",
5353
Type: schema.TypeString,
5454
},
55+
Attr_SoftwareTier: {
56+
Computed: true,
57+
Description: "Software tier for virtual serial number.",
58+
Type: schema.TypeString,
59+
},
5560
},
5661
},
5762
Type: schema.TypeList,
@@ -86,6 +91,7 @@ func dataSourceIBMPIVirtualSerialNumbersRead(ctx context.Context, d *schema.Reso
8691
v[Attr_Description] = vsn.Description
8792
v[Attr_InstanceID] = vsn.PvmInstanceID
8893
v[Attr_Serial] = vsn.Serial
94+
v[Attr_SoftwareTier] = vsn.SoftwareTier
8995
vsnMapList = append(vsnMapList, v)
9096
}
9197

ibm/service/power/ibm_pi_constants.go

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -137,6 +137,7 @@ const (
137137
Arg_SnapshotID = "pi_snapshot_id"
138138
Arg_SnapShotName = "pi_snap_shot_name"
139139
Arg_SnapshotName = "pi_snapshot_name"
140+
Arg_SoftwareTier = "pi_software_tier"
140141
Arg_SourceCRN = "pi_source_crn"
141142
Arg_SourcePort = "pi_source_port"
142143
Arg_SourcePorts = "pi_source_ports"
@@ -435,6 +436,7 @@ const (
435436
Attr_SharedProcessorPools = "shared_processor_pools"
436437
Attr_Size = "size"
437438
Attr_SnapshotID = "snapshot_id"
439+
Attr_SoftwareTier = "software_tier"
438440
Attr_Source = "source"
439441
Attr_SourceChecksum = "source_checksum"
440442
Attr_SourceIP = "source_ip"
@@ -462,6 +464,7 @@ const (
462464
Attr_StoragePoolsCapacity = "storage_pools_capacity"
463465
Attr_StorageType = "storage_type"
464466
Attr_StorageTypesCapacity = "storage_types_capacity"
467+
Attr_SupportedSoftwareTiers = "supported_software_tiers"
465468
Attr_SupportedSystems = "supported_systems"
466469
Attr_Synchronized = "synchronized"
467470
Attr_SynchronousReplication = "synchronous_replication"

0 commit comments

Comments
 (0)