From 2b42fa73ffdbad1fba6cb8ca063783d0fe8edba8 Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Mon, 7 Oct 2024 17:49:52 +0530 Subject: [PATCH] Update resource_ibm_is_instance.go --- ibm/service/vpc/resource_ibm_is_instance.go | 83 ++++++++++++--------- 1 file changed, 46 insertions(+), 37 deletions(-) diff --git a/ibm/service/vpc/resource_ibm_is_instance.go b/ibm/service/vpc/resource_ibm_is_instance.go index a3165a1c7c..85daa56115 100644 --- a/ibm/service/vpc/resource_ibm_is_instance.go +++ b/ibm/service/vpc/resource_ibm_is_instance.go @@ -1972,60 +1972,69 @@ func instanceCreateByImage(d *schema.ResourceData, meta interface{}, profile, na if volumeattintf, ok := d.GetOk("volume_prototypes"); ok { volumeatt := []vpcv1.VolumeAttachmentPrototype{} for i, _ := range volumeattintf.([]interface{}) { - volName := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_name", i)).(string) - volAutoDelete, ok := d.GetOkExists(fmt.Sprintf("volume_prototypes.%d.delete_volume_on_instance_delete", i)) - volIops := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_iops", i)).(int) - volCapacity := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_capacity", i)).(int) - volEncKey := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_encryption_key", i)).(string) - volProfile := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_profile", i)).(string) - volTags := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_tags", i)).(*schema.Set) - volRg := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_resource_group", i)).(string) - volSnapshot := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_source_snapshot", i)).(string) - volumeattItemModel := &vpcv1.VolumeAttachmentPrototype{} volumeattItemPrototypeModel := &vpcv1.VolumeAttachmentPrototypeVolume{} - - if volName != "" { - volumeattItemPrototypeModel.Name = &volName + if vname, ok := d.GetOk(fmt.Sprintf("volume_prototypes.%d.volume_name", i)); ok { + volName := vname.(string) + if volName != "" { + volumeattItemPrototypeModel.Name = &volName + } } - if ok { + if volAutoDelete, ok := d.GetOkExists(fmt.Sprintf("volume_prototypes.%d.delete_volume_on_instance_delete", i)); ok { volumeattItemModel.DeleteVolumeOnInstanceDelete = core.BoolPtr(volAutoDelete.(bool)) } - - if volTags != nil && volTags.Len() != 0 { - userTagsArray := make([]string, volTags.Len()) - for i, userTag := range volTags.List() { - userTagStr := userTag.(string) - userTagsArray[i] = userTagStr + if volIops, ok := d.GetOk(fmt.Sprintf("volume_prototypes.%d.volume_iops", i)); ok { + if volIops.(int) != 0 { + volumeattItemPrototypeModel.Iops = core.Int64Ptr(int64(volIops.(int))) } - volumeattItemPrototypeModel.UserTags = userTagsArray } - if volEncKey != "" { - volumeattItemPrototypeModel.EncryptionKey = &vpcv1.EncryptionKeyIdentity{ - CRN: &volEncKey, + if volCapacity, ok := d.GetOk(fmt.Sprintf("volume_prototypes.%d.volume_capacity", i)); ok { + if volCapacity != 0 { + volumeattItemPrototypeModel.Capacity = core.Int64Ptr(int64(volCapacity.(int))) } } - if volSnapshot != "" { - volumeattItemPrototypeModel.SourceSnapshot = &vpcv1.SnapshotIdentity{ - ID: &volSnapshot, + if volEncKeyOk, ok := d.GetOk(fmt.Sprintf("volume_prototypes.%d.volume_encryption_key", i)); ok { + volEncKey := volEncKeyOk.(string) + if volEncKey != "" { + volumeattItemPrototypeModel.EncryptionKey = &vpcv1.EncryptionKeyIdentity{ + CRN: &volEncKey, + } } } - if volRg != "" { - volumeattItemPrototypeModel.ResourceGroup = &vpcv1.ResourceGroupIdentity{ - ID: &volRg, + if volProfileOk, ok := d.GetOk(fmt.Sprintf("volume_prototypes.%d.volume_profile", i)); ok { + volProfile := volProfileOk.(string) + if volProfile != "" { + volumeattItemPrototypeModel.Profile = &vpcv1.VolumeProfileIdentity{ + Name: &volProfile, + } } } - if volProfile != "" { - volumeattItemPrototypeModel.Profile = &vpcv1.VolumeProfileIdentity{ - Name: &volProfile, + if volRgOk, ok := d.GetOk(fmt.Sprintf("volume_prototypes.%d.volume_resource_group", i)); ok { + volRg := volRgOk.(string) + if volRg != "" { + volumeattItemPrototypeModel.ResourceGroup = &vpcv1.ResourceGroupIdentity{ + ID: &volRg, + } } } - if volIops != 0 { - volumeattItemPrototypeModel.Iops = core.Int64Ptr(int64(volIops)) + if volSnapshotok, ok := d.GetOk(fmt.Sprintf("volume_prototypes.%d.volume_source_snapshot", i)); ok { + volSnapshot := volSnapshotok.(string) + if volSnapshot != "" { + volumeattItemPrototypeModel.SourceSnapshot = &vpcv1.SnapshotIdentity{ + ID: &volSnapshot, + } + } } - if volCapacity != 0 { - volumeattItemPrototypeModel.Capacity = core.Int64Ptr(int64(volCapacity)) + volTags := d.Get(fmt.Sprintf("volume_prototypes.%d.volume_tags", i)).(*schema.Set) + if volTags != nil && volTags.Len() != 0 { + userTagsArray := make([]string, volTags.Len()) + for i, userTag := range volTags.List() { + userTagStr := userTag.(string) + userTagsArray[i] = userTagStr + } + volumeattItemPrototypeModel.UserTags = userTagsArray } + volumeattItemModel.Volume = volumeattItemPrototypeModel volumeatt = append(volumeatt, *volumeattItemModel)