Skip to content

Commit

Permalink
enhancement(profiles): added support for vcpu manufacturer(vsi, dh)
Browse files Browse the repository at this point in the history
  • Loading branch information
ujjwal-ibm authored and hkantare committed Jun 20, 2023
1 parent bc0f53f commit 15f4b01
Show file tree
Hide file tree
Showing 27 changed files with 294 additions and 9 deletions.
4 changes: 2 additions & 2 deletions ibm/acctest/acctest.go
Original file line number Diff line number Diff line change
Expand Up @@ -611,8 +611,8 @@ func init() {
IsWinImage = os.Getenv("IS_WIN_IMAGE")
if IsWinImage == "" {
//IsWinImage = "a7a0626c-f97e-4180-afbe-0331ec62f32a" // classic windows machine: ibm-windows-server-2012-full-standard-amd64-1
IsWinImage = "r006-5f9568ae-792e-47e1-a710-5538b2bdfca7" // next gen windows machine: ibm-windows-server-2012-full-standard-amd64-3
fmt.Println("[INFO] Set the environment variable IS_WIN_IMAGE for testing ibm_is_instance data source else it is set to default value 'r006-5f9568ae-792e-47e1-a710-5538b2bdfca7'")
IsWinImage = "r006-d2e0d0e9-0a4f-4c45-afd7-cab787030776" // next gen windows machine: ibm-windows-server-2022-full-standard-amd64-8
fmt.Println("[INFO] Set the environment variable IS_WIN_IMAGE for testing ibm_is_instance data source else it is set to default value 'r006-d2e0d0e9-0a4f-4c45-afd7-cab787030776'")
}

IsCosBucketName = os.Getenv("IS_COS_BUCKET_NAME")
Expand Down
22 changes: 20 additions & 2 deletions ibm/service/vpc/data_source_ibm_is_dedicated_host.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,12 @@ func DataSourceIbmIsDedicatedHost() *schema.Resource {
Computed: true,
Description: "The VCPU architecture.",
},
"count": {
"manufacturer": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The VCPU manufacturer.",
},
"count": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The number of VCPUs assigned.",
Expand Down Expand Up @@ -314,7 +319,12 @@ func DataSourceIbmIsDedicatedHost() *schema.Resource {
Computed: true,
Description: "The VCPU architecture.",
},
"count": {
"manufacturer": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The VCPU manufacturer.",
},
"count": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The number of VCPUs assigned.",
Expand Down Expand Up @@ -493,6 +503,10 @@ func dataSourceDedicatedHostAvailableVcpuToMap(availableVcpuItem vpcv1.Vcpu) (av
if availableVcpuItem.Architecture != nil {
availableVcpuMap["architecture"] = availableVcpuItem.Architecture
}
// Added AMD Support for the manufacturer.
if availableVcpuItem.Manufacturer != nil {
availableVcpuMap["manufacturer"] = availableVcpuItem.Manufacturer
}
if availableVcpuItem.Count != nil {
availableVcpuMap["count"] = availableVcpuItem.Count
}
Expand Down Expand Up @@ -645,6 +659,10 @@ func dataSourceDedicatedHostVcpuToMap(vcpuItem vpcv1.Vcpu) (vcpuMap map[string]i
if vcpuItem.Architecture != nil {
vcpuMap["architecture"] = vcpuItem.Architecture
}
// Added AMD Support for the manufacturer.
if vcpuItem.Manufacturer != nil {
vcpuMap["manufacturer"] = vcpuItem.Manufacturer
}
if vcpuItem.Count != nil {
vcpuMap["count"] = vcpuItem.Count
}
Expand Down
49 changes: 49 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_dedicated_host_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -302,6 +302,24 @@ func DataSourceIbmIsDedicatedHostProfile() *schema.Resource {
},
},
},
"vcpu_manufacturer": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The VCPU manufacturer for a dedicated host with this profile.",
},
},
},
},
},
}
}
Expand Down Expand Up @@ -379,6 +397,14 @@ func dataSourceIbmIsDedicatedHostProfileRead(context context.Context, d *schema.
}
}

// Changes for the AMD Support, manufacturer information.
if dedicatedHostProfile.VcpuManufacturer != nil {
err = d.Set("vcpu_manufacturer", dataSourceDedicatedHostProfileFlattenVcpuManufacturer(*dedicatedHostProfile.VcpuManufacturer))
if err != nil {
return diag.FromErr(fmt.Errorf("Error setting vcpu_architecture %s", err))
}
}

return nil

}
Expand Down Expand Up @@ -502,6 +528,29 @@ func dataSourceDedicatedHostProfileVcpuArchitectureToMap(vcpuArchitectureItem vp
return vcpuArchitectureMap
}

// Changes for AMD Support, manufacturer details.
func dataSourceDedicatedHostProfileFlattenVcpuManufacturer(result vpcv1.DedicatedHostProfileVcpuManufacturer) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceDedicatedHostProfileVcpuManufacturerToMap(result)
finalList = append(finalList, finalMap)

return finalList
}

// AMD Support for manufacturer
func dataSourceDedicatedHostProfileVcpuManufacturerToMap(vcpuManufacturerItem vpcv1.DedicatedHostProfileVcpuManufacturer) (vcpuManufacturerMap map[string]interface{}) {
vcpuManufacturerMap = map[string]interface{}{}

if vcpuManufacturerItem.Type != nil {
vcpuManufacturerMap["type"] = vcpuManufacturerItem.Type
}
if vcpuManufacturerItem.Value != nil {
vcpuManufacturerMap["value"] = vcpuManufacturerItem.Value
}

return vcpuManufacturerMap
}

func dataSourceDedicatedHostProfileFlattenVcpuCount(result vpcv1.DedicatedHostProfileVcpu) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceDedicatedHostProfileVcpuCountToMap(result)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccIbmIsDedicatedHostProfileDataSourceBasic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "name", acc.DedicatedHostProfileName),
resource.TestCheckResourceAttrSet(resName, "class"),
resource.TestCheckResourceAttrSet(resName, "family"),
resource.TestCheckResourceAttrSet(resName, "vcpu_manufacturer.#"),
),
},
},
Expand Down
40 changes: 40 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_dedicated_host_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -311,6 +311,25 @@ func DataSourceIbmIsDedicatedHostProfiles() *schema.Resource {
},
},
},
"vcpu_manufacturer": &schema.Schema{
Type: schema.TypeList,

Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "TThe VCPU manufacturer for a dedicated host with this profile.",
},
},
},
},
},
},
},
Expand Down Expand Up @@ -467,6 +486,13 @@ func dataSourceDedicatedHostProfileCollectionProfilesToMap(profilesItem vpcv1.De
vcpuCountList = append(vcpuCountList, vcpuCountMap)
profilesMap["vcpu_count"] = vcpuCountList
}
// AMD Support, changes for manufacturer details.
if profilesItem.VcpuManufacturer != nil {
vcpuManufacturerList := []map[string]interface{}{}
vcpuManufacturerMap := dataSourceDedicatedHostProfileCollectionProfilesVcpuManufacturerToMap(*profilesItem.VcpuManufacturer)
vcpuManufacturerList = append(vcpuManufacturerList, vcpuManufacturerMap)
profilesMap["vcpu_manufacturer"] = vcpuManufacturerList
}

return profilesMap
}
Expand Down Expand Up @@ -553,6 +579,20 @@ func dataSourceDedicatedHostProfileCollectionProfilesVcpuArchitectureToMap(vcpuA
return vcpuArchitectureMap
}

// AMD Changes, manufacturer details added.
func dataSourceDedicatedHostProfileCollectionProfilesVcpuManufacturerToMap(vcpuManufacturerItem vpcv1.DedicatedHostProfileVcpuManufacturer) (vcpuManufacturerMap map[string]interface{}) {
vcpuManufacturerMap = map[string]interface{}{}

if vcpuManufacturerItem.Type != nil {
vcpuManufacturerMap["type"] = vcpuManufacturerItem.Type
}
if vcpuManufacturerItem.Value != nil {
vcpuManufacturerMap["value"] = vcpuManufacturerItem.Value
}

return vcpuManufacturerMap
}

func dataSourceDedicatedHostProfileCollectionProfilesVcpuCountToMap(vcpuCountItem vpcv1.DedicatedHostProfileVcpu) (vcpuCountMap map[string]interface{}) {
vcpuCountMap = map[string]interface{}{}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,7 @@ func TestAccIbmIsDedicatedHostProfilesDataSourceBasic(t *testing.T) {
resource.TestCheckResourceAttrSet(resName, "profiles.0.name"),
resource.TestCheckResourceAttrSet(resName, "profiles.0.class"),
resource.TestCheckResourceAttrSet(resName, "profiles.0.family"),
resource.TestCheckResourceAttrSet(resName, "profiles.0.vcpu_manufacturer.#"),
),
},
},
Expand Down
1 change: 1 addition & 0 deletions ibm/service/vpc/data_source_ibm_is_dedicated_host_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ func TestAccIbmIsDedicatedHostDSBasic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "disks.#", "2"),
resource.TestCheckResourceAttrSet(resName, "disks.0.name"),
resource.TestCheckResourceAttrSet(resName, "disks.0.size"),
resource.TestCheckResourceAttrSet(resName, "vcpu.0.manufacturer"),
),
},
},
Expand Down
22 changes: 20 additions & 2 deletions ibm/service/vpc/data_source_ibm_is_dedicated_hosts.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,12 @@ func DataSourceIbmIsDedicatedHosts() *schema.Resource {
Computed: true,
Description: "The VCPU architecture.",
},
"count": {
"manufacturer": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The VCPU manufacturer.",
},
"count": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The number of VCPUs assigned.",
Expand Down Expand Up @@ -344,7 +349,12 @@ func DataSourceIbmIsDedicatedHosts() *schema.Resource {
Computed: true,
Description: "The VCPU architecture.",
},
"count": {
"manufacturer": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The VCPU manufacturer.",
},
"count": &schema.Schema{
Type: schema.TypeInt,
Computed: true,
Description: "The number of VCPUs assigned.",
Expand Down Expand Up @@ -552,6 +562,10 @@ func dataSourceDedicatedHostCollectionDedicatedHostsAvailableVcpuToMap(available
if availableVcpuItem.Architecture != nil {
availableVcpuMap["architecture"] = availableVcpuItem.Architecture
}
// Added AMD Support for the manufacturer.
if availableVcpuItem.Manufacturer != nil {
availableVcpuMap["manufacturer"] = availableVcpuItem.Manufacturer
}
if availableVcpuItem.Count != nil {
availableVcpuMap["count"] = availableVcpuItem.Count
}
Expand Down Expand Up @@ -664,6 +678,10 @@ func dataSourceDedicatedHostCollectionDedicatedHostsVcpuToMap(vcpuItem vpcv1.Vcp
if vcpuItem.Architecture != nil {
vcpuMap["architecture"] = vcpuItem.Architecture
}
// Added AMD Support for the manufacturer.
if vcpuItem.Manufacturer != nil {
vcpuMap["manufacturer"] = vcpuItem.Manufacturer
}
if vcpuItem.Count != nil {
vcpuMap["count"] = vcpuItem.Count
}
Expand Down
1 change: 1 addition & 0 deletions ibm/service/vpc/data_source_ibm_is_dedicated_hosts_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ func TestAccIbmIsDedicatedHostsDSBasic(t *testing.T) {
resource.TestCheckResourceAttrSet(resName, "dedicated_hosts.0.memory"),
resource.TestCheckResourceAttrSet(resName, "dedicated_hosts.0.host_group"),
resource.TestCheckResourceAttrSet(resName, "dedicated_hosts.0.zone"),
resource.TestCheckResourceAttrSet(resName, "dedicated_hosts.0.vcpu.0.manufacturer"),
),
},
},
Expand Down
7 changes: 7 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,12 @@ func DataSourceIBMISInstance() *schema.Resource {
Computed: true,
Description: "Instance vCPU count",
},
// Added for AMD support, manufacturer details.
isInstanceCPUManufacturer: {
Type: schema.TypeString,
Computed: true,
Description: "Instance vCPU Manufacturer",
},
},
},
},
Expand Down Expand Up @@ -762,6 +768,7 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er
currentCPU := map[string]interface{}{}
currentCPU[isInstanceCPUArch] = *instance.Vcpu.Architecture
currentCPU[isInstanceCPUCount] = *instance.Vcpu.Count
currentCPU[isInstanceCPUManufacturer] = *instance.Vcpu.Manufacturer // Added for AMD support, manufacturer details.
cpuList = append(cpuList, currentCPU)
}
d.Set(isInstanceCPU, cpuList)
Expand Down
64 changes: 61 additions & 3 deletions ibm/service/vpc/data_source_ibm_is_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,8 @@ const (
isInstanceProfileName = "name"
isInstanceProfileFamily = "family"
isInstanceProfileArchitecture = "architecture"
isInstanceVCPUArchitecture = "vcpu_architecture"
isInstanceVCPUManufacturer = "vcpu_manufacturer"
)

func DataSourceIBMISInstanceProfile() *schema.Resource {
Expand Down Expand Up @@ -502,7 +504,7 @@ func DataSourceIBMISInstanceProfile() *schema.Resource {
},
},
},
"vcpu_architecture": {
isInstanceVCPUArchitecture: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Expand All @@ -525,7 +527,30 @@ func DataSourceIBMISInstanceProfile() *schema.Resource {
},
},
},
"vcpu_count": {
isInstanceVCPUManufacturer: &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The default VCPU manufacturer for an instance with this profile.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"value": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The VCPU manufacturer for an instance with this profile.",
},
},
},
},
"vcpu_count": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Expand Down Expand Up @@ -679,7 +704,15 @@ func instanceProfileGet(d *schema.ResourceData, meta interface{}, name string) e
}

if profile.VcpuArchitecture != nil {
err = d.Set("vcpu_architecture", dataSourceInstanceProfileFlattenVcpuArchitecture(*profile.VcpuArchitecture))
err = d.Set(isInstanceVCPUArchitecture, dataSourceInstanceProfileFlattenVcpuArchitecture(*profile.VcpuArchitecture))
if err != nil {
return err
}
}

// Manufacturer details added.
if profile.VcpuManufacturer != nil {
err = d.Set(isInstanceVCPUManufacturer, dataSourceInstanceProfileFlattenVcpuManufacture(*profile.VcpuManufacturer))
if err != nil {
return err
}
Expand Down Expand Up @@ -948,6 +981,31 @@ func dataSourceInstanceProfileVcpuArchitectureToMap(vcpuArchitectureItem vpcv1.I
return vcpuArchitectureMap
}

/* Changes for the AMD Support VCPU Manufacturer */
func dataSourceInstanceProfileFlattenVcpuManufacture(result vpcv1.InstanceProfileVcpuManufacturer) (fl []map[string]interface{}) {
fl = []map[string]interface{}{}
finalMap := dataSourceInstanceProfileVcpuManufacturerToMap(result)
fl = append(fl, finalMap)

return fl
}

func dataSourceInstanceProfileVcpuManufacturerToMap(vcpuManufacutererItem vpcv1.InstanceProfileVcpuManufacturer) (vcpuManufacturerMap map[string]interface{}) {
vcpuManufacturerMap = map[string]interface{}{}

if vcpuManufacutererItem.Default != nil {
vcpuManufacturerMap["default"] = vcpuManufacutererItem.Default
}
if vcpuManufacutererItem.Type != nil {
vcpuManufacturerMap["type"] = vcpuManufacutererItem.Type
}
if vcpuManufacutererItem.Value != nil {
vcpuManufacturerMap["value"] = vcpuManufacutererItem.Value
}

return vcpuManufacturerMap
}

func dataSourceInstanceProfileFlattenVcpuCount(result vpcv1.InstanceProfileVcpu) (finalList []map[string]interface{}) {
finalList = []map[string]interface{}{}
finalMap := dataSourceInstanceProfileVcpuCountToMap(result)
Expand Down
Loading

0 comments on commit 15f4b01

Please sign in to comment.