Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Refactor] Resource Volume Onboarding #5906

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ibm/service/power/ibm_pi_constants.go
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,8 @@ const (
Arg_AffinityVolume = "pi_affinity_volume"
Arg_AntiAffinityInstances = "pi_anti_affinity_instances"
Arg_AntiAffinityVolumes = "pi_anti_affinity_volumes"
Arg_AuxiliaryVolumeName = "pi_auxiliary_volume_name"
Arg_AuxiliaryVolumes = "pi_auxiliary_volumes"
Arg_BootVolumeReplicationEnabled = "pi_boot_volume_replication_enabled"
Arg_Cidr = "pi_cidr"
Arg_CloudConnectionID = "pi_cloud_connection_id"
Expand All @@ -25,6 +27,7 @@ const (
Arg_DhcpID = "pi_dhcp_id"
Arg_DhcpName = "pi_dhcp_name"
Arg_DhcpSnatEnabled = "pi_dhcp_snat_enabled"
Arg_DisplayName = "pi_display_name"
Arg_DNS = "pi_dns"
Arg_DnsServer = "pi_dns_server"
Arg_EndingIPAddress = "pi_ending_ip_address"
Expand Down Expand Up @@ -65,6 +68,7 @@ const (
Arg_NetworkSecurityGroupMemberID = "pi_network_security_group_member_id"
Arg_NetworkSecurityGroupRuleID = "pi_network_security_group_rule_id"
Arg_NetworkType = "pi_network_type"
Arg_OnboardingVolumes = "pi_onboarding_volumes"
Arg_PinPolicy = "pi_pin_policy"
Arg_PlacementGroupID = "pi_placement_group_id"
Arg_PlacementGroupName = "pi_placement_group_name"
Expand Down Expand Up @@ -97,6 +101,7 @@ const (
Arg_SnapshotID = "pi_snapshot_id"
Arg_SnapShotName = "pi_snap_shot_name"
Arg_SnapshotName = "pi_snapshot_name"
Arg_SourceCRN = "pi_source_crn"
Arg_SourcePorts = "pi_source_ports"
Arg_SPPPlacementGroupID = "pi_spp_placement_group_id"
Arg_SPPPlacementGroupName = "pi_spp_placement_group_name"
Expand Down Expand Up @@ -318,6 +323,7 @@ const (
Attr_NetworkSecurityGroupMemberID = "network_security_group_member_id"
Attr_NetworkSecurityGroups = "network_security_groups"
Attr_NumberOfVolumes = "number_of_volumes"
Attr_OnboardingID = "onboarding_id"
Attr_Onboardings = "onboardings"
Attr_OperatingSystem = "operating_system"
Attr_OSType = "os_type"
Expand Down Expand Up @@ -616,6 +622,20 @@ const (

// TODO: Second Half Cleanup, remove extra variables

PIConsoleLanguageCode = "pi_language_code"
PIInstanceMigratable = "pi_migratable"

// Volume Clone
PIVolumeCloneName = "pi_volume_clone_name"
PIVolumeCloneTaskID = "pi_volume_clone_task_id"
PITargetStorageTier = "pi_target_storage_tier"

// IBM PI Volume Group
PIVolumeGroupID = "pi_volume_group_id"
PIVolumeGroupName = "pi_volume_group_name"
PIVolumeGroupConsistencyGroupName = "pi_consistency_group_name"
PIVolumeGroupAction = "pi_volume_group_action"

// VPN
PIVPNConnectionId = "connection_id"
PIVPNConnectionStatus = "connection_status"
Expand Down
169 changes: 81 additions & 88 deletions ibm/service/power/resource_ibm_pi_volume_onboarding.go
Original file line number Diff line number Diff line change
Expand Up @@ -8,23 +8,13 @@ import (
"fmt"
"time"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/helpers"
"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/power-go-client/power/models"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/hashicorp/terraform-plugin-sdk/v2/diag"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema"
)

const (
piOnboardingVolumes = "pi_onboarding_volumes"
piAuxiliaryVolumes = "pi_auxiliary_volumes"
piAuxiliaryVolumeName = "pi_auxiliary_volume_name"
piSourceCRN = "pi_source_crn"
piDisplayName = "pi_display_name"
piDescription = "pi_description"
)

func ResourceIBMPIVolumeOnboarding() *schema.Resource {
return &schema.Resource{
CreateContext: resourceIBMPIVolumeOnboardingCreate,
Expand All @@ -38,105 +28,108 @@ func ResourceIBMPIVolumeOnboarding() *schema.Resource {
},

Schema: map[string]*schema.Schema{

helpers.PICloudInstanceId: {
Type: schema.TypeString,
Required: true,
// Arguments
Arg_CloudInstanceID: {
Description: "The GUID of the service instance associated with an account.",
ForceNew: true,
Description: "Cloud Instance ID - This is the service_instance_id.",
Required: true,
Type: schema.TypeString,
},

piOnboardingVolumes: {
Type: schema.TypeList,
Required: true,
ForceNew: true,
MinItems: 1,
Arg_Description: {
Computed: true,
Description: "Description of the volume onboarding operation",
Optional: true,
Type: schema.TypeString,
},
Arg_OnboardingVolumes: {
Description: "List of onboarding volumes.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
piSourceCRN: {
Type: schema.TypeString,
Required: true,
Description: "CRN of source ServiceBroker instance from where auxiliary volumes need to be onboarded",
},
piAuxiliaryVolumes: {
Type: schema.TypeList,
Optional: true,
MinItems: 1,
Arg_AuxiliaryVolumes: {
Description: "List auxiliary volumes.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
piAuxiliaryVolumeName: {
Type: schema.TypeString,
Arg_AuxiliaryVolumeName: {
Description: "The auxiliary volume name.",
Required: true,
Description: "Auxiliary volume name at storage host level",
},
piDisplayName: {
Type: schema.TypeString,
},
Arg_DisplayName: {
Description: "The display name of auxiliary volume which is to be onboarded.",
Optional: true,
Description: "Display name of auxVolumeName once onboarded,auxVolumeName will be set to display name if not provided.",
Type: schema.TypeString,
},
},
},
MinItems: 1,
Optional: true,
Type: schema.TypeList,
},
Arg_SourceCRN: {
Description: "The crn of source service broker instance from where auxiliary volumes need to be onboarded.",
Required: true,
Type: schema.TypeString,
},
},
},
},
piDescription: {
Type: schema.TypeString,
Optional: true,
Computed: true,
Description: "Description of the volume onboarding operation",
ForceNew: true,
MinItems: 1,
Required: true,
Type: schema.TypeList,
},

// Computed Attribute
"create_time": {
Type: schema.TypeString,
// Attributes
Attr_CreateTime: {
Computed: true,
Description: "Indicates the create-time of volume onboarding operation",
},
"onboarding_id": {
Description: "The create time of volume onboarding operation.",
Type: schema.TypeString,
Computed: true,
Description: "Indicates the volume onboarding operation id",
},
"input_volumes": {
Type: schema.TypeList,
Attr_InputVolumes: {
Computed: true,
Description: "List of volumes requested to be onboarded",
Description: "List of volumes requested to be onboarded.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
},
"progress": {
Type: schema.TypeFloat,
Attr_OnboardingID: {
Computed: true,
Description: "Indicates the progress of volume onboarding operation",
Description: "The volume onboarding ID.",
Type: schema.TypeString,
},
"results_onboarded_volumes": {
Type: schema.TypeList,
Attr_Progress: {
Computed: true,
Description: "The progress of volume onboarding operation.",
Type: schema.TypeFloat,
},
Attr_ResultsOnboardedVolumes: {
Computed: true,
Description: "List of volumes which are onboarded successfully",
Description: "List of volumes which are onboarded successfully.",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
},
"results_volume_onboarding_failures": {
Type: schema.TypeList,
Computed: true,
Attr_ResultsVolumeOnboardingFailures: {
Computed: true,
Description: "The volume onboarding failure details.",
Elem: &schema.Resource{
Schema: map[string]*schema.Schema{
"failure_message": {
Type: schema.TypeString,
Attr_FailureMessage: {
Computed: true,
Description: "The failure reason for the volumes which have failed to be onboarded",
Type: schema.TypeString,
},
"volumes": {
Type: schema.TypeList,
Attr_Volumes: {
Computed: true,
Description: "List of volumes which have failed to be onboarded",
Elem: &schema.Schema{Type: schema.TypeString},
Type: schema.TypeList,
},
}},
},
},
Type: schema.TypeList,
},
"status": {
Type: schema.TypeString,
Attr_Status: {
Computed: true,
Description: "Indicates the status of volume onboarding operation",
Description: "The status of volume onboarding operation.",
Type: schema.TypeString,
},
},
}
Expand All @@ -147,10 +140,10 @@ func resourceIBMPIVolumeOnboardingCreate(ctx context.Context, d *schema.Resource
if err != nil {
return diag.FromErr(err)
}
cloudInstanceID := d.Get(helpers.PICloudInstanceId).(string)
client := st.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID)
cloudInstanceID := d.Get(Arg_CloudInstanceID).(string)
client := instance.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID)

vol, err := expandCreateVolumeOnboarding(d.Get(piOnboardingVolumes).([]interface{}))
vol, err := expandCreateVolumeOnboarding(d.Get(Arg_OnboardingVolumes).([]interface{}))
if err != nil {
return diag.FromErr(err)
}
Expand All @@ -159,7 +152,7 @@ func resourceIBMPIVolumeOnboardingCreate(ctx context.Context, d *schema.Resource
Volumes: vol,
}

if v, ok := d.GetOk(piDescription); ok {
if v, ok := d.GetOk(Arg_Description); ok {
body.Description = v.(string)
}

Expand All @@ -184,21 +177,21 @@ func resourceIBMPIVolumeOnboardingRead(ctx context.Context, d *schema.ResourceDa
return diag.FromErr(err)
}

client := st.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID)
client := instance.NewIBMPIVolumeOnboardingClient(ctx, sess, cloudInstanceID)

onboardingData, err := client.Get(onboardingID)
if err != nil {
return diag.FromErr(err)
}

d.Set("onboarding_id", *onboardingData.ID)
d.Set("create_time", onboardingData.CreationTimestamp.String())
d.Set(piDescription, onboardingData.Description)
d.Set("input_volumes", onboardingData.InputVolumes)
d.Set("progress", onboardingData.Progress)
d.Set("status", onboardingData.Status)
d.Set("results_onboarded_volumes", onboardingData.Results.OnboardedVolumes)
d.Set("results_volume_onboarding_failures", flattenVolumeOnboardingFailures(onboardingData.Results.VolumeOnboardingFailures))
d.Set(Arg_Description, onboardingData.Description)
d.Set(Attr_CreateTime, onboardingData.CreationTimestamp.String())
d.Set(Attr_InputVolumes, onboardingData.InputVolumes)
d.Set(Attr_OnboardingID, *onboardingData.ID)
d.Set(Attr_Progress, onboardingData.Progress)
d.Set(Attr_ResultsOnboardedVolumes, onboardingData.Results.OnboardedVolumes)
d.Set(Attr_ResultsVolumeOnboardingFailures, flattenVolumeOnboardingFailures(onboardingData.Results.VolumeOnboardingFailures))
d.Set(Attr_Status, onboardingData.Status)
return nil
}

Expand Down Expand Up @@ -247,12 +240,12 @@ func expandAuxiliaryVolumeForOnboarding(data []interface{}) []*models.AuxiliaryV
var auxVolumeName, displayName string
resource := d.(map[string]interface{})

if v, ok := resource["pi_auxiliary_volume_name"]; ok && v != "" {
auxVolumeName = resource["pi_auxiliary_volume_name"].(string)
if v, ok := resource[Arg_AuxiliaryVolumeName]; ok && v != "" {
auxVolumeName = resource[Arg_AuxiliaryVolumeName].(string)
}

if v, ok := resource["pi_display_name"]; ok && v != "" {
displayName = resource["pi_display_name"].(string)
if v, ok := resource[Arg_DisplayName]; ok && v != "" {
displayName = resource[Arg_DisplayName].(string)
}

auxVolumeForOnboarding = append(auxVolumeForOnboarding, &models.AuxiliaryVolumeForOnboarding{
Expand Down
15 changes: 7 additions & 8 deletions ibm/service/power/resource_ibm_pi_volume_onboarding_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,14 @@ import (
"fmt"
"testing"

"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"

st "github.com/IBM-Cloud/power-go-client/clients/instance"
acc "github.com/IBM-Cloud/terraform-provider-ibm/ibm/acctest"

"github.com/IBM-Cloud/power-go-client/clients/instance"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/conns"
"github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/acctest"
"github.com/hashicorp/terraform-plugin-sdk/v2/helper/resource"
"github.com/hashicorp/terraform-plugin-sdk/v2/terraform"
)

func TestAccIBMPIVolumeOnboardingbasic(t *testing.T) {
Expand Down Expand Up @@ -60,7 +60,7 @@ func testAccCheckIBMPIVolumeOnboardingExists(n string) resource.TestCheckFunc {
return err
}
cloudInstanceID, onboardID := ids[0], ids[1]
client := st.NewIBMPIVolumeOnboardingClient(context.Background(), sess, cloudInstanceID)
client := instance.NewIBMPIVolumeOnboardingClient(context.Background(), sess, cloudInstanceID)

_, err = client.Get(onboardID)
if err != nil {
Expand All @@ -82,6 +82,5 @@ func testAccCheckIBMPIVolumeOnboardingConfig(name string) string {
pi_display_name = "%[2]s-1"
}
}
}
`, acc.Pi_cloud_instance_id, name, acc.Pi_volume_onboarding_source_crn, acc.Pi_auxiliary_volume_name)
}`, acc.Pi_cloud_instance_id, name, acc.Pi_volume_onboarding_source_crn, acc.Pi_auxiliary_volume_name)
}
Loading
Loading