Skip to content

Commit

Permalink
Support for confidential compute profiles in instance and instance te…
Browse files Browse the repository at this point in the history
…mplate
  • Loading branch information
ujjwal-ibm committed Jun 18, 2024
1 parent 8bf6bfb commit f3b00ca
Show file tree
Hide file tree
Showing 26 changed files with 919 additions and 17 deletions.
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ require (
github.com/IBM/schematics-go-sdk v0.2.3
github.com/IBM/secrets-manager-go-sdk/v2 v2.0.4
github.com/IBM/vpc-beta-go-sdk v0.6.0
github.com/IBM/vpc-go-sdk v0.51.0
github.com/IBM/vpc-go-sdk v0.52.0
github.com/ScaleFT/sshkeys v0.0.0-20200327173127-6142f742bca5
github.com/akamai/AkamaiOPEN-edgegrid-golang v1.2.2
github.com/akamai/AkamaiOPEN-edgegrid-golang/v5 v5.0.0
Expand Down
5 changes: 3 additions & 2 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ github.com/IBM/vmware-go-sdk v0.1.2 h1:5lKWFyInWz9e2hwGsoFTEoLa1jYkD30SReN0fQ10w
github.com/IBM/vmware-go-sdk v0.1.2/go.mod h1:2UGPBJju3jiv5VKKBBm9a5L6bzF/aJdKOKAzJ7HaOjA=
github.com/IBM/vpc-beta-go-sdk v0.6.0 h1:wfM3AcW3zOM3xsRtZ+EA6+sESlGUjQ6Yf4n5QQyz4uc=
github.com/IBM/vpc-beta-go-sdk v0.6.0/go.mod h1:fzHDAQIqH/5yJmYsKodKHLcqxMDT+yfH6vZjdiw8CQA=
github.com/IBM/vpc-go-sdk v0.51.0 h1:JfeE/TnPm/NFU59UctiPzjxEhHtmBqXxG6zHH5eTI8I=
github.com/IBM/vpc-go-sdk v0.51.0/go.mod h1:3+zQ0dqiv46ALjRXXVrser+dCdAVXOHVwlYkCCX4bNU=
github.com/IBM/vpc-go-sdk v0.52.0 h1:XZh28TQ0QXHZcHj6i269x/1fVfgJnv3B5e38fyr5aZo=
github.com/IBM/vpc-go-sdk v0.52.0/go.mod h1:FoZljso53oB/A2mW7ExsfHXZ3T3XWV7c7R5JSgS4QfY=
github.com/Jeffail/gabs v1.1.1 h1:V0uzR08Hj22EX8+8QMhyI9sX2hwRu+/RJhJUmnwda/E=
github.com/Jeffail/gabs v1.1.1/go.mod h1:6xMvQMK4k33lb7GUUpaAPh6nKMmemQeg5d4gn7/bOXc=
github.com/Logicalis/asn1 v0.0.0-20190312173541-d60463189a56 h1:vuquMR410psHNax14XKNWa0Ae/kYgWJcXi0IFuX60N0=
Expand Down Expand Up @@ -1374,6 +1374,7 @@ github.com/onsi/gomega v1.27.10/go.mod h1:RsS8tutOdbdgzbPtzzATp12yT7kM5I5aElG3ev
github.com/onsi/gomega v1.30.0/go.mod h1:9sxs+SwGrKI0+PWe4Fxa9tFQQBG5xSsSbMXOI8PPpoQ=
github.com/onsi/gomega v1.31.1/go.mod h1:y40C95dwAD1Nz36SsEnxvfFe8FFfNxzI5eJ0EYGyAy0=
github.com/onsi/gomega v1.33.1 h1:dsYjIxxSR755MDmKVsaFQTE22ChNBcuuTWgkUDSubOk=
github.com/onsi/gomega v1.33.1/go.mod h1:U4R44UsT+9eLIaYRB2a5qajjtQYn0hauxvRm16AVYg0=
github.com/opencontainers/go-digest v1.0.0-rc1/go.mod h1:cMLVZDEM3+U2I4VmLI6N8jQYUd2OVphdqWwCJHrFt2s=
github.com/opencontainers/go-digest v1.0.0 h1:apOUWs51W5PlhuyGyz9FCeeBIOUDA/6nW8Oi/yOhh5U=
github.com/opencontainers/go-digest v1.0.0/go.mod h1:0JzlMkj0TRzQZfJkVvzbP0HBR3IKzErnv2BNG4W4MAM=
Expand Down
17 changes: 16 additions & 1 deletion ibm/service/vpc/data_source_ibm_is_instance.go
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,16 @@ func DataSourceIBMISInstance() *schema.Resource {
Required: true,
Description: "Instance name",
},

"confidential_compute_mode": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The confidential compute mode to use for this virtual server instance.If unspecified, the default confidential compute mode from the profile will be used.",
},
"enable_secure_boot": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "Indicates whether secure boot is enabled for this virtual server instance.If unspecified, the default secure boot mode from the profile will be used.",
},
isInstanceMetadataServiceEnabled: {
Type: schema.TypeBool,
Computed: true,
Expand Down Expand Up @@ -1262,6 +1271,9 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er
primaryNicList = append(primaryNicList, currentPrimNic)
d.Set(isInstancePrimaryNetworkInterface, primaryNicList)
}
if err = d.Set("confidential_compute_mode", instance.ConfidentialComputeMode); err != nil {
return fmt.Errorf("Error setting confidential_compute_mode: %s", err)
}
primaryNetworkAttachment := []map[string]interface{}{}
if instance.PrimaryNetworkAttachment != nil {
modelMap, err := dataSourceIBMIsInstanceInstanceNetworkAttachmentReferenceToMap(instance.PrimaryNetworkAttachment)
Expand All @@ -1274,6 +1286,9 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er
return fmt.Errorf("Error setting primary_network_attachment %s", err)
}

if err = d.Set("enable_secure_boot", instance.EnableSecureBoot); err != nil {
return fmt.Errorf("Error setting enable_secure_boot: %s", err)
}
if instance.NetworkInterfaces != nil {
interfacesList := make([]map[string]interface{}, 0)
for _, intfc := range instance.NetworkInterfaces {
Expand Down
97 changes: 97 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_profile.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,8 @@
package vpc

import (
"fmt"

"github.com/IBM/vpc-go-sdk/vpcv1"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)
Expand All @@ -27,6 +29,60 @@ func DataSourceIBMISInstanceProfile() *schema.Resource {
Required: true,
},

"confidential_compute_modes": &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 confidential compute mode for this profile.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"values": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The supported confidential compute modes.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},

"secure_boot_modes": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "The default secure boot mode for this profile.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"values": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The supported `enable_secure_boot` values for an instance using this profile.",
Elem: &schema.Schema{
Type: schema.TypeBool,
},
},
},
},
},

isInstanceProfileFamily: {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -709,6 +765,31 @@ func instanceProfileGet(d *schema.ResourceData, meta interface{}, name string) e
if profile.Status != nil {
d.Set("status", profile.Status)
}

confidentialComputeModes := []map[string]interface{}{}
if profile.ConfidentialComputeModes != nil {
modelMap, err := dataSourceIBMIsInstanceProfileInstanceProfileSupportedConfidentialComputeModesToMap(profile.ConfidentialComputeModes)
if err != nil {
return (err)
}
confidentialComputeModes = append(confidentialComputeModes, modelMap)
}
if err = d.Set("confidential_compute_modes", confidentialComputeModes); err != nil {
return fmt.Errorf("Error setting confidential_compute_modes %s", err)
}

secureBootModes := []map[string]interface{}{}
if profile.SecureBootModes != nil {
modelMap, err := dataSourceIBMIsInstanceProfileInstanceProfileSupportedSecureBootModesToMap(profile.SecureBootModes)
if err != nil {
return err
}
secureBootModes = append(secureBootModes, modelMap)
}
if err = d.Set("secure_boot_modes", secureBootModes); err != nil {
return fmt.Errorf("Error setting secure_boot_modes %s", err)
}

if profile.Bandwidth != nil {
err = d.Set("bandwidth", dataSourceInstanceProfileFlattenBandwidth(*profile.Bandwidth.(*vpcv1.InstanceProfileBandwidth)))
if err != nil {
Expand Down Expand Up @@ -1335,3 +1416,19 @@ func dataSourceInstanceProfileNumaCountToMap(numaItem vpcv1.InstanceProfileNumaC

return numaMap
}

func dataSourceIBMIsInstanceProfileInstanceProfileSupportedSecureBootModesToMap(model *vpcv1.InstanceProfileSupportedSecureBootModes) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["default"] = model.Default
modelMap["type"] = model.Type
modelMap["values"] = model.Values
return modelMap, nil
}

func dataSourceIBMIsInstanceProfileInstanceProfileSupportedConfidentialComputeModesToMap(model *vpcv1.InstanceProfileSupportedConfidentialComputeModes) (map[string]interface{}, error) {
modelMap := make(map[string]interface{})
modelMap["default"] = model.Default
modelMap["type"] = model.Type
modelMap["values"] = model.Values
return modelMap, nil
}
37 changes: 37 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_profile_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,43 @@ func TestAccIBMISInstanceProfileDataSource_basic(t *testing.T) {
},
})
}
func TestAccIBMISInstanceProfileDataSource_concom(t *testing.T) {
resName := "data.ibm_is_instance_profile.test1"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISInstanceProfileDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttr(resName, "name", acc.InstanceProfileName),
resource.TestCheckResourceAttrSet(resName, "family"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "bandwidth.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "family"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "href"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "memory.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "architecture"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "port_speed.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "vcpu_architecture.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "vcpu_count.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "vcpu_manufacturer.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "vcpu_manufacturer.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "vcpu_manufacturer.0.value"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "network_interface_count.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "network_attachment_count.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "network_attachment_count.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "confidential_compute_modes.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "confidential_compute_modes.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "confidential_compute_modes.0.values.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "secure_boot_modes.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "secure_boot_modes.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profile.test1", "secure_boot_modes.0.values.#"),
),
},
},
})
}

func testAccCheckIBMISInstanceProfileDataSourceConfig() string {
return fmt.Sprintf(`
Expand Down
73 changes: 73 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_profiles.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,59 @@ func DataSourceIBMISInstanceProfiles() *schema.Resource {
Computed: true,
Description: "The product family this virtual server instance profile belongs to.",
},
"confidential_compute_modes": &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 confidential compute mode for this profile.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"values": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The supported confidential compute modes.",
Elem: &schema.Schema{
Type: schema.TypeString,
},
},
},
},
},

"secure_boot_modes": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"default": &schema.Schema{
Type: schema.TypeBool,
Computed: true,
Description: "The default secure boot mode for this profile.",
},
"type": &schema.Schema{
Type: schema.TypeString,
Computed: true,
Description: "The type for this profile field.",
},
"values": &schema.Schema{
Type: schema.TypeList,
Computed: true,
Description: "The supported `enable_secure_boot` values for an instance using this profile.",
Elem: &schema.Schema{
Type: schema.TypeBool,
},
},
},
},
},
"architecture": {
Type: schema.TypeString,
Computed: true,
Expand Down Expand Up @@ -752,6 +805,26 @@ func instanceProfilesList(d *schema.ResourceData, meta interface{}) error {
if profile.Href != nil {
l["href"] = profile.Href
}
confidentialComputeModes := []map[string]interface{}{}
if profile.ConfidentialComputeModes != nil {
modelMap, err := dataSourceIBMIsInstanceProfileInstanceProfileSupportedConfidentialComputeModesToMap(profile.ConfidentialComputeModes)
if err != nil {
return (err)
}
confidentialComputeModes = append(confidentialComputeModes, modelMap)
}
l["confidential_compute_modes"] = confidentialComputeModes

secureBootModes := []map[string]interface{}{}
if profile.SecureBootModes != nil {
modelMap, err := dataSourceIBMIsInstanceProfileInstanceProfileSupportedSecureBootModesToMap(profile.SecureBootModes)
if err != nil {
return err
}
secureBootModes = append(secureBootModes, modelMap)
}
l["secure_boot_modes"] = secureBootModes

if profile.Memory != nil {
memoryList := []map[string]interface{}{}
memoryMap := dataSourceInstanceProfileMemoryToMap(*profile.Memory.(*vpcv1.InstanceProfileMemory))
Expand Down
38 changes: 38 additions & 0 deletions ibm/service/vpc/data_source_ibm_is_instance_profiles_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,44 @@ func TestAccIBMISInstanceProfilesDataSource_basic(t *testing.T) {
},
})
}
func TestAccIBMISInstanceProfilesDataSource_concom(t *testing.T) {
resName := "data.ibm_is_instance_profiles.test1"

resource.Test(t, resource.TestCase{
PreCheck: func() { acc.TestAccPreCheck(t) },
Providers: acc.TestAccProviders,
Steps: []resource.TestStep{
{
Config: testAccCheckIBMISInstanceProfilesDataSourceConfig(),
Check: resource.ComposeTestCheckFunc(
resource.TestCheckResourceAttrSet(resName, "profiles.0.name"),
resource.TestCheckResourceAttrSet(resName, "profiles.0.family"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.bandwidth.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.family"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.href"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.memory.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.architecture"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.port_speed.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.vcpu_architecture.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.vcpu_count.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.network_interface_count.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.network_interface_count.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.network_attachment_count.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.network_attachment_count.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.vcpu_manufacturer.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.vcpu_manufacturer.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.vcpu_manufacturer.0.value"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.confidential_compute_modes.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.confidential_compute_modes.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.confidential_compute_modes.0.values.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.secure_boot_modes.#"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.secure_boot_modes.0.type"),
resource.TestCheckResourceAttrSet("data.ibm_is_instance_profiles.test1", "profiles.0.secure_boot_modes.0.values.#"),
),
},
},
})
}

func testAccCheckIBMISInstanceProfilesDataSourceConfig() string {
// status filter defaults to empty
Expand Down
Loading

0 comments on commit f3b00ca

Please sign in to comment.