From b7e7996aefd7e5036ed3f3b61f4d8e4a1902e880 Mon Sep 17 00:00:00 2001 From: Ujjwal Kumar Date: Wed, 13 Apr 2022 11:27:53 +0530 Subject: [PATCH] enhancement(changed): changed list logic in datasource by name --- .../vpc/data_source_ibm_is_flow_log.go | 36 +- .../vpc/data_source_ibm_is_flow_log_test.go | 22 +- ibm/service/vpc/data_source_ibm_is_image.go | 84 ++- .../vpc/data_source_ibm_is_instance.go | 541 +++++++++--------- .../vpc/data_source_ibm_is_snapshot.go | 89 ++- ..._source_ibm_is_virtual_endpoint_gateway.go | 65 +-- ibm/service/vpc/data_source_ibm_is_volume.go | 132 ++--- 7 files changed, 462 insertions(+), 507 deletions(-) diff --git a/ibm/service/vpc/data_source_ibm_is_flow_log.go b/ibm/service/vpc/data_source_ibm_is_flow_log.go index a0cdeaab41..604d930009 100644 --- a/ibm/service/vpc/data_source_ibm_is_flow_log.go +++ b/ibm/service/vpc/data_source_ibm_is_flow_log.go @@ -207,32 +207,24 @@ func dataSourceIBMIsFlowLogRead(context context.Context, d *schema.ResourceData, var flowLogCollector *vpcv1.FlowLogCollector if name != "" { - start := "" - allrecs := []vpcv1.FlowLogCollector{} - for { - listOptions := &vpcv1.ListFlowLogCollectorsOptions{} - if start != "" { - listOptions.Start = &start - } - flowlogCollectors, response, err := sess.ListFlowLogCollectors(listOptions) - if err != nil { - return diag.FromErr(fmt.Errorf("[ERROR] Error Fetching Flow Logs for VPC %s\n%s", err, response)) - } - start = flex.GetNext(flowlogCollectors.Next) - allrecs = append(allrecs, flowlogCollectors.FlowLogCollectors...) - if start == "" { - break - } + + listOptions := &vpcv1.ListFlowLogCollectorsOptions{ + Name: &name, } - for _, flowlogCollector := range allrecs { - if *flowlogCollector.Name == name { - flowLogCollector = &flowlogCollector - break - } + + flowlogCollectors, response, err := sess.ListFlowLogCollectors(listOptions) + if err != nil { + return diag.FromErr(fmt.Errorf("Error Fetching Flow Logs for VPC %s\n%s", err, response)) } - if flowLogCollector == nil { + + allrecs := flowlogCollectors.FlowLogCollectors + + if len(allrecs) == 0 { return diag.FromErr(fmt.Errorf("[ERROR] No flow log collector found with name (%s)", name)) } + flc := allrecs[0] + flowLogCollector = &flc + } else if identifier != "" { getFlowLogCollectorOptions := &vpcv1.GetFlowLogCollectorOptions{} diff --git a/ibm/service/vpc/data_source_ibm_is_flow_log_test.go b/ibm/service/vpc/data_source_ibm_is_flow_log_test.go index 84bcaa007e..fc1651742e 100644 --- a/ibm/service/vpc/data_source_ibm_is_flow_log_test.go +++ b/ibm/service/vpc/data_source_ibm_is_flow_log_test.go @@ -50,6 +50,12 @@ func TestAccIBMIsFlowLogDataSourceBasic(t *testing.T) { resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log", "storage_bucket.#"), resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log", "target.#"), resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log", "vpc.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log_name", "vpc.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log_name", "target.#"), + resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log_name", "name"), + resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log_name", "lifecycle_state"), + resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log_name", "href"), + resource.TestCheckResourceAttrSet("data.ibm_is_flow_log.is_flow_log_name", "crn"), ), }, }, @@ -104,16 +110,20 @@ func testAccCheckIBMISFlowLogDataSourceConfig(vpcname, name, flowlogname, sshnam } resource "ibm_is_flow_log" "test_flow_log" { - name = "%s" - target = ibm_is_instance.testacc_instance.id - storage_bucket = ibm_cos_bucket.bucket2.bucket_name - active = %v + name = "%s" + target = ibm_is_instance.testacc_instance.id + storage_bucket = ibm_cos_bucket.bucket2.bucket_name + active = %v } data "ibm_is_flow_log" "is_flow_log" { identifier = ibm_is_flow_log.test_flow_log.id - } + } + + data "ibm_is_flow_log" "is_flow_log_name" { + name = ibm_is_flow_log.test_flow_log.name + } - `, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, name, "r006-13938c0a-89e4-4370-b59b-55cd1402562d", acc.InstanceProfileName, acc.ISZoneName, serviceName, bucketName, bucketRegion, bucketClass, flowlogname, isActive) + `, vpcname, subnetname, acc.ISZoneName, acc.ISCIDR, sshname, publicKey, name, acc.IsImage, acc.InstanceProfileName, acc.ISZoneName, serviceName, bucketName, bucketRegion, bucketClass, flowlogname, isActive) } diff --git a/ibm/service/vpc/data_source_ibm_is_image.go b/ibm/service/vpc/data_source_ibm_is_image.go index 86a07f2942..ca66c60691 100644 --- a/ibm/service/vpc/data_source_ibm_is_image.go +++ b/ibm/service/vpc/data_source_ibm_is_image.go @@ -6,7 +6,6 @@ package vpc import ( "fmt" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" "github.com/IBM/vpc-go-sdk/vpcv1" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -112,56 +111,47 @@ func imageGetByName(d *schema.ResourceData, meta interface{}, name, visibility s if err != nil { return err } - start := "" - allrecs := []vpcv1.Image{} - for { - listImagesOptions := &vpcv1.ListImagesOptions{} - if start != "" { - listImagesOptions.Start = &start - } - if visibility != "" { - listImagesOptions.Visibility = &visibility - } - availableImages, response, err := sess.ListImages(listImagesOptions) - if err != nil { - return fmt.Errorf("[ERROR] Error Fetching Images %s\n%s", err, response) - } - start = flex.GetNext(availableImages.Next) - allrecs = append(allrecs, availableImages.Images...) - if start == "" { - break - } + listImagesOptions := &vpcv1.ListImagesOptions{ + Name: &name, } - for _, image := range allrecs { - if *image.Name == name { - d.SetId(*image.ID) - d.Set("status", *image.Status) - if *image.Status == "deprecated" { - fmt.Printf("[WARN] Given image %s is deprecated and soon will be obsolete.", name) - } - d.Set("name", *image.Name) - d.Set("visibility", *image.Visibility) - d.Set("os", *image.OperatingSystem.Name) - d.Set("architecture", *image.OperatingSystem.Architecture) - d.Set("crn", *image.CRN) - if image.Encryption != nil { - d.Set("encryption", *image.Encryption) - } - if image.EncryptionKey != nil { - d.Set("encryption_key", *image.EncryptionKey.CRN) - } - if image.File != nil && image.File.Checksums != nil { - d.Set(isImageCheckSum, *image.File.Checksums.Sha256) - } - if image.SourceVolume != nil { - d.Set("source_volume", *image.SourceVolume.ID) - } - return nil - } + if visibility != "" { + listImagesOptions.Visibility = &visibility + } + availableImages, response, err := sess.ListImages(listImagesOptions) + if err != nil { + return fmt.Errorf("[ERROR] Error Fetching Images %s\n%s", err, response) + } + allrecs := availableImages.Images + + if len(allrecs) == 0 { + return fmt.Errorf("[ERROR] No image found with name %s", name) + } + image := allrecs[0] + d.SetId(*image.ID) + d.Set("status", *image.Status) + if *image.Status == "deprecated" { + fmt.Printf("[WARN] Given image %s is deprecated and soon will be obsolete.", name) + } + d.Set("name", *image.Name) + d.Set("visibility", *image.Visibility) + d.Set("os", *image.OperatingSystem.Name) + d.Set("architecture", *image.OperatingSystem.Architecture) + d.Set("crn", *image.CRN) + if image.Encryption != nil { + d.Set("encryption", *image.Encryption) } + if image.EncryptionKey != nil { + d.Set("encryption_key", *image.EncryptionKey.CRN) + } + if image.File != nil && image.File.Checksums != nil { + d.Set(isImageCheckSum, *image.File.Checksums.Sha256) + } + if image.SourceVolume != nil { + d.Set("source_volume", *image.SourceVolume.ID) + } + return nil - return fmt.Errorf("[ERROR] No image found with name %s", name) } func imageGetById(d *schema.ResourceData, meta interface{}, identifier string) error { sess, err := vpcClient(meta) diff --git a/ibm/service/vpc/data_source_ibm_is_instance.go b/ibm/service/vpc/data_source_ibm_is_instance.go index 5f517d3acf..c4f02ebc26 100644 --- a/ibm/service/vpc/data_source_ibm_is_instance.go +++ b/ibm/service/vpc/data_source_ibm_is_instance.go @@ -540,323 +540,316 @@ func instanceGetByName(d *schema.ResourceData, meta interface{}, name string) er if err != nil { return err } - start := "" - allrecs := []vpcv1.Instance{} - for { - listInstancesOptions := &vpcv1.ListInstancesOptions{} - if start != "" { - listInstancesOptions.Start = &start - } - instances, response, err := sess.ListInstances(listInstancesOptions) - if err != nil { - return fmt.Errorf("[ERROR] Error Fetching Instances %s\n%s", err, response) - } - start = flex.GetNext(instances.Next) - allrecs = append(allrecs, instances.Instances...) - if start == "" { - break - } + listInstancesOptions := &vpcv1.ListInstancesOptions{ + Name: &name, } - for _, instance := range allrecs { - if *instance.Name == name { - d.SetId(*instance.ID) - id := *instance.ID - d.Set(isInstanceName, *instance.Name) - if instance.Profile != nil { - d.Set(isInstanceProfile, *instance.Profile.Name) - } - if instance.MetadataService != nil { - d.Set(isInstanceMetadataServiceEnabled, instance.MetadataService.Enabled) - } - if instance.AvailabilityPolicy != nil && instance.AvailabilityPolicy.HostFailure != nil { - d.Set(isInstanceAvailablePolicyHostFailure, *instance.AvailabilityPolicy.HostFailure) - } - cpuList := make([]map[string]interface{}, 0) - if instance.Vcpu != nil { - currentCPU := map[string]interface{}{} - currentCPU[isInstanceCPUArch] = *instance.Vcpu.Architecture - currentCPU[isInstanceCPUCount] = *instance.Vcpu.Count - cpuList = append(cpuList, currentCPU) - } - d.Set(isInstanceCPU, cpuList) - if instance.PlacementTarget != nil { - placementTargetMap := resourceIbmIsInstanceInstancePlacementToMap(*instance.PlacementTarget.(*vpcv1.InstancePlacementTarget)) - d.Set("placement_target", []map[string]interface{}{placementTargetMap}) - } + instances, response, err := sess.ListInstances(listInstancesOptions) + if err != nil { + return fmt.Errorf("[ERROR] Error Fetching Instances %s\n%s", err, response) + } + allrecs := instances.Instances - d.Set(isInstanceMemory, *instance.Memory) - - gpuList := make([]map[string]interface{}, 0) - if instance.Gpu != nil { - currentGpu := map[string]interface{}{} - currentGpu[isInstanceGpuManufacturer] = instance.Gpu.Manufacturer - currentGpu[isInstanceGpuModel] = instance.Gpu.Model - currentGpu[isInstanceGpuCount] = instance.Gpu.Count - currentGpu[isInstanceGpuMemory] = instance.Gpu.Memory - gpuList = append(gpuList, currentGpu) - d.Set(isInstanceGpu, gpuList) - } + if len(allrecs) == 0 { + return fmt.Errorf("[ERROR] No Instance found with name %s", name) + } + instance := allrecs[0] + d.SetId(*instance.ID) + id := *instance.ID + d.Set(isInstanceName, *instance.Name) + if instance.Profile != nil { + d.Set(isInstanceProfile, *instance.Profile.Name) + } + if instance.MetadataService != nil { + d.Set(isInstanceMetadataServiceEnabled, instance.MetadataService.Enabled) + } + if instance.AvailabilityPolicy != nil && instance.AvailabilityPolicy.HostFailure != nil { + d.Set(isInstanceAvailablePolicyHostFailure, *instance.AvailabilityPolicy.HostFailure) + } + cpuList := make([]map[string]interface{}, 0) + if instance.Vcpu != nil { + currentCPU := map[string]interface{}{} + currentCPU[isInstanceCPUArch] = *instance.Vcpu.Architecture + currentCPU[isInstanceCPUCount] = *instance.Vcpu.Count + cpuList = append(cpuList, currentCPU) + } + d.Set(isInstanceCPU, cpuList) - if instance.Bandwidth != nil { - d.Set(isInstanceBandwidth, int(*instance.Bandwidth)) - } + if instance.PlacementTarget != nil { + placementTargetMap := resourceIbmIsInstanceInstancePlacementToMap(*instance.PlacementTarget.(*vpcv1.InstancePlacementTarget)) + d.Set("placement_target", []map[string]interface{}{placementTargetMap}) + } - if instance.TotalNetworkBandwidth != nil { - d.Set(isInstanceTotalNetworkBandwidth, int(*instance.TotalNetworkBandwidth)) - } + d.Set(isInstanceMemory, *instance.Memory) + + gpuList := make([]map[string]interface{}, 0) + if instance.Gpu != nil { + currentGpu := map[string]interface{}{} + currentGpu[isInstanceGpuManufacturer] = instance.Gpu.Manufacturer + currentGpu[isInstanceGpuModel] = instance.Gpu.Model + currentGpu[isInstanceGpuCount] = instance.Gpu.Count + currentGpu[isInstanceGpuMemory] = instance.Gpu.Memory + gpuList = append(gpuList, currentGpu) + d.Set(isInstanceGpu, gpuList) + } - if instance.TotalVolumeBandwidth != nil { - d.Set(isInstanceTotalVolumeBandwidth, int(*instance.TotalVolumeBandwidth)) - } + if instance.Bandwidth != nil { + d.Set(isInstanceBandwidth, int(*instance.Bandwidth)) + } + + if instance.TotalNetworkBandwidth != nil { + d.Set(isInstanceTotalNetworkBandwidth, int(*instance.TotalNetworkBandwidth)) + } - if instance.Disks != nil { - d.Set(isInstanceDisks, dataSourceInstanceFlattenDisks(instance.Disks)) + if instance.TotalVolumeBandwidth != nil { + d.Set(isInstanceTotalVolumeBandwidth, int(*instance.TotalVolumeBandwidth)) + } + + if instance.Disks != nil { + d.Set(isInstanceDisks, dataSourceInstanceFlattenDisks(instance.Disks)) + } + + if instance.PrimaryNetworkInterface != nil { + primaryNicList := make([]map[string]interface{}, 0) + currentPrimNic := map[string]interface{}{} + currentPrimNic["id"] = *instance.PrimaryNetworkInterface.ID + currentPrimNic[isInstanceNicName] = *instance.PrimaryNetworkInterface.Name + currentPrimNic[isInstanceNicPrimaryIpv4Address] = *instance.PrimaryNetworkInterface.PrimaryIpv4Address + getnicoptions := &vpcv1.GetInstanceNetworkInterfaceOptions{ + InstanceID: &id, + ID: instance.PrimaryNetworkInterface.ID, + } + insnic, response, err := sess.GetInstanceNetworkInterface(getnicoptions) + if err != nil { + return fmt.Errorf("[ERROR] Error getting network interfaces attached to the instance %s\n%s", err, response) + } + if insnic.PortSpeed != nil { + currentPrimNic[isInstanceNicPortSpeed] = *insnic.PortSpeed + } + currentPrimNic[isInstanceNicSubnet] = *insnic.Subnet.ID + if len(insnic.SecurityGroups) != 0 { + secgrpList := []string{} + for i := 0; i < len(insnic.SecurityGroups); i++ { + secgrpList = append(secgrpList, string(*(insnic.SecurityGroups[i].ID))) } + currentPrimNic[isInstanceNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList) + } + + primaryNicList = append(primaryNicList, currentPrimNic) + d.Set(isInstancePrimaryNetworkInterface, primaryNicList) + } - if instance.PrimaryNetworkInterface != nil { - primaryNicList := make([]map[string]interface{}, 0) - currentPrimNic := map[string]interface{}{} - currentPrimNic["id"] = *instance.PrimaryNetworkInterface.ID - currentPrimNic[isInstanceNicName] = *instance.PrimaryNetworkInterface.Name - currentPrimNic[isInstanceNicPrimaryIpv4Address] = *instance.PrimaryNetworkInterface.PrimaryIpv4Address + if instance.NetworkInterfaces != nil { + interfacesList := make([]map[string]interface{}, 0) + for _, intfc := range instance.NetworkInterfaces { + if *intfc.ID != *instance.PrimaryNetworkInterface.ID { + currentNic := map[string]interface{}{} + currentNic["id"] = *intfc.ID + currentNic[isInstanceNicName] = *intfc.Name + currentNic[isInstanceNicPrimaryIpv4Address] = *intfc.PrimaryIpv4Address getnicoptions := &vpcv1.GetInstanceNetworkInterfaceOptions{ InstanceID: &id, - ID: instance.PrimaryNetworkInterface.ID, + ID: intfc.ID, } insnic, response, err := sess.GetInstanceNetworkInterface(getnicoptions) if err != nil { return fmt.Errorf("[ERROR] Error getting network interfaces attached to the instance %s\n%s", err, response) } - if insnic.PortSpeed != nil { - currentPrimNic[isInstanceNicPortSpeed] = *insnic.PortSpeed - } - currentPrimNic[isInstanceNicSubnet] = *insnic.Subnet.ID + currentNic[isInstanceNicSubnet] = *insnic.Subnet.ID if len(insnic.SecurityGroups) != 0 { secgrpList := []string{} for i := 0; i < len(insnic.SecurityGroups); i++ { secgrpList = append(secgrpList, string(*(insnic.SecurityGroups[i].ID))) } - currentPrimNic[isInstanceNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList) + currentNic[isInstanceNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList) } + interfacesList = append(interfacesList, currentNic) - primaryNicList = append(primaryNicList, currentPrimNic) - d.Set(isInstancePrimaryNetworkInterface, primaryNicList) } + } - if instance.NetworkInterfaces != nil { - interfacesList := make([]map[string]interface{}, 0) - for _, intfc := range instance.NetworkInterfaces { - if *intfc.ID != *instance.PrimaryNetworkInterface.ID { - currentNic := map[string]interface{}{} - currentNic["id"] = *intfc.ID - currentNic[isInstanceNicName] = *intfc.Name - currentNic[isInstanceNicPrimaryIpv4Address] = *intfc.PrimaryIpv4Address - getnicoptions := &vpcv1.GetInstanceNetworkInterfaceOptions{ - InstanceID: &id, - ID: intfc.ID, + d.Set(isInstanceNetworkInterfaces, interfacesList) + } + + var rsaKey *rsa.PrivateKey + if instance.Image != nil { + d.Set(isInstanceImage, *instance.Image.ID) + image := *instance.Image.Name + res := strings.Contains(image, "windows") + if res { + if privatekey, ok := d.GetOk(isInstancePEM); ok { + keyFlag := privatekey.(string) + keybytes := []byte(keyFlag) + + if keyFlag != "" { + block, err := pem.Decode(keybytes) + if block == nil { + return fmt.Errorf("[ERROR] Failed to load the private key from the given key contents. Instead of the key file path, please make sure the private key is pem format") + } + isEncrypted := false + switch block.Type { + case "RSA PRIVATE KEY": + isEncrypted = x509.IsEncryptedPEMBlock(block) + case "OPENSSH PRIVATE KEY": + var err error + isEncrypted, err = isOpenSSHPrivKeyEncrypted(block.Bytes) + if err != nil { + return fmt.Errorf("[ERROR] Failed to check if the provided open ssh key is encrypted or not %s", err) + } + default: + return fmt.Errorf("PEM and OpenSSH private key formats with RSA key type are supported, can not support this key file type: %s", err) + } + passphrase := "" + var privateKey interface{} + if isEncrypted { + if pass, ok := d.GetOk(isInstancePassphrase); ok { + passphrase = pass.(string) + } else { + return fmt.Errorf("[ERROR] Mandatory field 'passphrase' not provided") } - insnic, response, err := sess.GetInstanceNetworkInterface(getnicoptions) + var err error + privateKey, err = sshkeys.ParseEncryptedRawPrivateKey(keybytes, []byte(passphrase)) if err != nil { - return fmt.Errorf("[ERROR] Error getting network interfaces attached to the instance %s\n%s", err, response) + return fmt.Errorf("[ERROR] Fail to decrypting the private key: %s", err) } - currentNic[isInstanceNicSubnet] = *insnic.Subnet.ID - if len(insnic.SecurityGroups) != 0 { - secgrpList := []string{} - for i := 0; i < len(insnic.SecurityGroups); i++ { - secgrpList = append(secgrpList, string(*(insnic.SecurityGroups[i].ID))) - } - currentNic[isInstanceNicSecurityGroups] = flex.NewStringSet(schema.HashString, secgrpList) + } else { + var err error + privateKey, err = sshkeys.ParseEncryptedRawPrivateKey(keybytes, nil) + if err != nil { + return fmt.Errorf("[ERROR] Fail to decrypting the private key: %s", err) } - interfacesList = append(interfacesList, currentNic) - } - } - - d.Set(isInstanceNetworkInterfaces, interfacesList) - } - - var rsaKey *rsa.PrivateKey - if instance.Image != nil { - d.Set(isInstanceImage, *instance.Image.ID) - image := *instance.Image.Name - res := strings.Contains(image, "windows") - if res { - if privatekey, ok := d.GetOk(isInstancePEM); ok { - keyFlag := privatekey.(string) - keybytes := []byte(keyFlag) - - if keyFlag != "" { - block, err := pem.Decode(keybytes) - if block == nil { - return fmt.Errorf("[ERROR] Failed to load the private key from the given key contents. Instead of the key file path, please make sure the private key is pem format") - } - isEncrypted := false - switch block.Type { - case "RSA PRIVATE KEY": - isEncrypted = x509.IsEncryptedPEMBlock(block) - case "OPENSSH PRIVATE KEY": - var err error - isEncrypted, err = isOpenSSHPrivKeyEncrypted(block.Bytes) - if err != nil { - return fmt.Errorf("[ERROR] Failed to check if the provided open ssh key is encrypted or not %s", err) - } - default: - return fmt.Errorf("PEM and OpenSSH private key formats with RSA key type are supported, can not support this key file type: %s", err) - } - passphrase := "" - var privateKey interface{} - if isEncrypted { - if pass, ok := d.GetOk(isInstancePassphrase); ok { - passphrase = pass.(string) - } else { - return fmt.Errorf("Mandatory field 'passphrase' not provided") - } - var err error - privateKey, err = sshkeys.ParseEncryptedRawPrivateKey(keybytes, []byte(passphrase)) - if err != nil { - return fmt.Errorf("Fail to decrypting the private key: %s", err) - } - } else { - var err error - privateKey, err = sshkeys.ParseEncryptedRawPrivateKey(keybytes, nil) - if err != nil { - return fmt.Errorf("Fail to decrypting the private key: %s", err) - } - } - var ok bool - rsaKey, ok = privateKey.(*rsa.PrivateKey) - if !ok { - return fmt.Errorf("[ERROR] Failed to convert to RSA private key") - } - } + var ok bool + rsaKey, ok = privateKey.(*rsa.PrivateKey) + if !ok { + return fmt.Errorf("[ERROR] Failed to convert to RSA private key") } } } + } + } - getInstanceInitializationOptions := &vpcv1.GetInstanceInitializationOptions{ - ID: &id, - } - initParms, response, err := sess.GetInstanceInitialization(getInstanceInitializationOptions) - if err != nil { - return fmt.Errorf("[ERROR] Error Getting instance Initialization: %s\n%s", err, response) + getInstanceInitializationOptions := &vpcv1.GetInstanceInitializationOptions{ + ID: &id, + } + initParms, response, err := sess.GetInstanceInitialization(getInstanceInitializationOptions) + if err != nil { + return fmt.Errorf("[ERROR] Error Getting instance Initialization: %s\n%s", err, response) + } + if initParms.Keys != nil { + initKeyList := make([]map[string]interface{}, 0) + for _, key := range initParms.Keys { + initKey := map[string]interface{}{} + id := "" + if key.ID != nil { + id = *key.ID } - if initParms.Keys != nil { - initKeyList := make([]map[string]interface{}, 0) - for _, key := range initParms.Keys { - initKey := map[string]interface{}{} - id := "" - if key.ID != nil { - id = *key.ID - } - initKey["id"] = id - name := "" - if key.Name != nil { - name = *key.Name - } - initKey["name"] = name - initKeyList = append(initKeyList, initKey) - break - - } - d.Set(isInstanceInitKeys, initKeyList) - } - if initParms.Password != nil && initParms.Password.EncryptedPassword != nil { - ciphertext := *initParms.Password.EncryptedPassword - password := base64.StdEncoding.EncodeToString(ciphertext) - if rsaKey != nil { - rng := rand.Reader - clearPassword, err := rsa.DecryptPKCS1v15(rng, rsaKey, ciphertext) - if err != nil { - return fmt.Errorf("Can not decrypt the password with the given key, %s", err) - } - password = string(clearPassword) - } - d.Set(isInstanceInitPassword, password) + initKey["id"] = id + name := "" + if key.Name != nil { + name = *key.Name } + initKey["name"] = name + initKeyList = append(initKeyList, initKey) + break - d.Set(isInstanceStatus, *instance.Status) - //set the status reasons - if instance.StatusReasons != nil { - statusReasonsList := make([]map[string]interface{}, 0) - for _, sr := range instance.StatusReasons { - currentSR := map[string]interface{}{} - if sr.Code != nil && sr.Message != nil { - currentSR[isInstanceStatusReasonsCode] = *sr.Code - currentSR[isInstanceStatusReasonsMessage] = *sr.Message - statusReasonsList = append(statusReasonsList, currentSR) - } - } - d.Set(isInstanceStatusReasons, statusReasonsList) - } - d.Set(isInstanceVPC, *instance.VPC.ID) - d.Set(isInstanceZone, *instance.Zone.Name) - - var volumes []string - volumes = make([]string, 0) - if instance.VolumeAttachments != nil { - for _, volume := range instance.VolumeAttachments { - if volume.Volume != nil && *volume.Volume.ID != *instance.BootVolumeAttachment.Volume.ID { - volumes = append(volumes, *volume.Volume.ID) - } - } - } - d.Set(isInstanceVolumes, flex.NewStringSet(schema.HashString, volumes)) - if instance.VolumeAttachments != nil { - volList := make([]map[string]interface{}, 0) - for _, volume := range instance.VolumeAttachments { - vol := map[string]interface{}{} - if volume.Volume != nil { - vol["id"] = *volume.ID - vol["volume_id"] = *volume.Volume.ID - vol["name"] = *volume.Name - vol["volume_name"] = *volume.Volume.Name - vol["volume_crn"] = *volume.Volume.CRN - volList = append(volList, vol) - } - } - d.Set(isInstanceVolumeAttachments, volList) - } - if instance.BootVolumeAttachment != nil { - bootVolList := make([]map[string]interface{}, 0) - bootVol := map[string]interface{}{} - bootVol["id"] = *instance.BootVolumeAttachment.ID - bootVol["name"] = *instance.BootVolumeAttachment.Name - if instance.BootVolumeAttachment.Device != nil { - bootVol["device"] = *instance.BootVolumeAttachment.Device.ID - } - if instance.BootVolumeAttachment.Volume != nil { - bootVol["volume_name"] = *instance.BootVolumeAttachment.Volume.Name - bootVol["volume_id"] = *instance.BootVolumeAttachment.Volume.ID - bootVol["volume_crn"] = *instance.BootVolumeAttachment.Volume.CRN - } - bootVolList = append(bootVolList, bootVol) - d.Set(isInstanceBootVolume, bootVolList) - } - tags, err := flex.GetTagsUsingCRN(meta, *instance.CRN) + } + d.Set(isInstanceInitKeys, initKeyList) + } + if initParms.Password != nil && initParms.Password.EncryptedPassword != nil { + ciphertext := *initParms.Password.EncryptedPassword + password := base64.StdEncoding.EncodeToString(ciphertext) + if rsaKey != nil { + rng := rand.Reader + clearPassword, err := rsa.DecryptPKCS1v15(rng, rsaKey, ciphertext) if err != nil { - log.Printf( - "Error on get of resource vpc Instance (%s) tags: %s", d.Id(), err) + return fmt.Errorf("[ERROR] Can not decrypt the password with the given key, %s", err) } - d.Set(isInstanceTags, tags) + password = string(clearPassword) + } + d.Set(isInstanceInitPassword, password) + } - controller, err := flex.GetBaseController(meta) - if err != nil { - return err + d.Set(isInstanceStatus, *instance.Status) + //set the status reasons + if instance.StatusReasons != nil { + statusReasonsList := make([]map[string]interface{}, 0) + for _, sr := range instance.StatusReasons { + currentSR := map[string]interface{}{} + if sr.Code != nil && sr.Message != nil { + currentSR[isInstanceStatusReasonsCode] = *sr.Code + currentSR[isInstanceStatusReasonsMessage] = *sr.Message + statusReasonsList = append(statusReasonsList, currentSR) + } + } + d.Set(isInstanceStatusReasons, statusReasonsList) + } + d.Set(isInstanceVPC, *instance.VPC.ID) + d.Set(isInstanceZone, *instance.Zone.Name) + + var volumes []string + volumes = make([]string, 0) + if instance.VolumeAttachments != nil { + for _, volume := range instance.VolumeAttachments { + if volume.Volume != nil && *volume.Volume.ID != *instance.BootVolumeAttachment.Volume.ID { + volumes = append(volumes, *volume.Volume.ID) } - d.Set(flex.ResourceControllerURL, controller+"/vpc-ext/compute/vs") - d.Set(flex.ResourceName, instance.Name) - d.Set(flex.ResourceCRN, instance.CRN) - d.Set(IsInstanceCRN, instance.CRN) - d.Set(flex.ResourceStatus, instance.Status) - if instance.ResourceGroup != nil { - d.Set(isInstanceResourceGroup, instance.ResourceGroup.ID) - d.Set(flex.ResourceGroupName, instance.ResourceGroup.Name) + } + } + d.Set(isInstanceVolumes, flex.NewStringSet(schema.HashString, volumes)) + if instance.VolumeAttachments != nil { + volList := make([]map[string]interface{}, 0) + for _, volume := range instance.VolumeAttachments { + vol := map[string]interface{}{} + if volume.Volume != nil { + vol["id"] = *volume.ID + vol["volume_id"] = *volume.Volume.ID + vol["name"] = *volume.Name + vol["volume_name"] = *volume.Volume.Name + vol["volume_crn"] = *volume.Volume.CRN + volList = append(volList, vol) } - return nil } + d.Set(isInstanceVolumeAttachments, volList) } - return fmt.Errorf("[ERROR] No Instance found with name %s", name) + if instance.BootVolumeAttachment != nil { + bootVolList := make([]map[string]interface{}, 0) + bootVol := map[string]interface{}{} + bootVol["id"] = *instance.BootVolumeAttachment.ID + bootVol["name"] = *instance.BootVolumeAttachment.Name + if instance.BootVolumeAttachment.Device != nil { + bootVol["device"] = *instance.BootVolumeAttachment.Device.ID + } + if instance.BootVolumeAttachment.Volume != nil { + bootVol["volume_name"] = *instance.BootVolumeAttachment.Volume.Name + bootVol["volume_id"] = *instance.BootVolumeAttachment.Volume.ID + bootVol["volume_crn"] = *instance.BootVolumeAttachment.Volume.CRN + } + bootVolList = append(bootVolList, bootVol) + d.Set(isInstanceBootVolume, bootVolList) + } + tags, err := flex.GetTagsUsingCRN(meta, *instance.CRN) + if err != nil { + log.Printf( + "[ERROR] Error on get of resource vpc Instance (%s) tags: %s", d.Id(), err) + } + d.Set(isInstanceTags, tags) + + controller, err := flex.GetBaseController(meta) + if err != nil { + return err + } + d.Set(flex.ResourceControllerURL, controller+"/vpc-ext/compute/vs") + d.Set(flex.ResourceName, instance.Name) + d.Set(flex.ResourceCRN, instance.CRN) + d.Set(IsInstanceCRN, instance.CRN) + d.Set(flex.ResourceStatus, instance.Status) + if instance.ResourceGroup != nil { + d.Set(isInstanceResourceGroup, instance.ResourceGroup.ID) + d.Set(flex.ResourceGroupName, instance.ResourceGroup.Name) + } + return nil + } const opensshv1Magic = "openssh-key-v1" @@ -873,7 +866,7 @@ type opensshPrivateKey struct { func isOpenSSHPrivKeyEncrypted(data []byte) (bool, error) { magic := append([]byte(opensshv1Magic), 0) if !bytes.Equal(magic, data[0:len(magic)]) { - return false, errors.New("Invalid openssh private key format") + return false, errors.New("[ERROR] Invalid openssh private key format") } content := data[len(magic):] diff --git a/ibm/service/vpc/data_source_ibm_is_snapshot.go b/ibm/service/vpc/data_source_ibm_is_snapshot.go index 928d4b7cea..8225bafdf2 100644 --- a/ibm/service/vpc/data_source_ibm_is_snapshot.go +++ b/ibm/service/vpc/data_source_ibm_is_snapshot.go @@ -6,7 +6,6 @@ package vpc import ( "fmt" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM-Cloud/terraform-provider-ibm/ibm/validate" "github.com/IBM/vpc-go-sdk/vpcv1" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" @@ -143,54 +142,46 @@ func snapshotGetByNameOrID(d *schema.ResourceData, meta interface{}, name, id st return err } if name != "" { - start := "" - allrecs := []vpcv1.Snapshot{} - for { - listSnapshotOptions := &vpcv1.ListSnapshotsOptions{} - if start != "" { - listSnapshotOptions.Start = &start - } - snapshots, response, err := sess.ListSnapshots(listSnapshotOptions) - if err != nil { - return fmt.Errorf("[ERROR] Error Fetching snapshots %s\n%s", err, response) - } - start = flex.GetNext(snapshots.Next) - allrecs = append(allrecs, snapshots.Snapshots...) - if start == "" { - break - } - } - for _, snapshot := range allrecs { - if *snapshot.Name == name || *snapshot.ID == id { - d.SetId(*snapshot.ID) - d.Set(isSnapshotName, *snapshot.Name) - d.Set(isSnapshotHref, *snapshot.Href) - d.Set(isSnapshotCRN, *snapshot.CRN) - d.Set(isSnapshotMinCapacity, *snapshot.MinimumCapacity) - d.Set(isSnapshotSize, *snapshot.Size) - d.Set(isSnapshotEncryption, *snapshot.Encryption) - d.Set(isSnapshotLCState, *snapshot.LifecycleState) - d.Set(isSnapshotResourceType, *snapshot.ResourceType) - d.Set(isSnapshotBootable, *snapshot.Bootable) - if snapshot.CapturedAt != nil { - d.Set(isSnapshotCapturedAt, (*snapshot.CapturedAt).String()) - } - if snapshot.ResourceGroup != nil && snapshot.ResourceGroup.ID != nil { - d.Set(isSnapshotResourceGroup, *snapshot.ResourceGroup.ID) - } - if snapshot.SourceVolume != nil && snapshot.SourceVolume.ID != nil { - d.Set(isSnapshotSourceVolume, *snapshot.SourceVolume.ID) - } - if snapshot.SourceImage != nil && snapshot.SourceImage.ID != nil { - d.Set(isSnapshotSourceImage, *snapshot.SourceImage.ID) - } - if snapshot.OperatingSystem != nil && snapshot.OperatingSystem.Name != nil { - d.Set(isSnapshotOperatingSystem, *snapshot.OperatingSystem.Name) - } - return nil - } - } - return fmt.Errorf("[ERROR] No snapshot found with name %s", name) + listSnapshotOptions := &vpcv1.ListSnapshotsOptions{ + Name: &name, + } + + snapshots, response, err := sess.ListSnapshots(listSnapshotOptions) + if err != nil { + return fmt.Errorf("[ERROR] Error Fetching snapshots %s\n%s", err, response) + } + allrecs := snapshots.Snapshots + + if len(allrecs) == 0 { + return fmt.Errorf("[ERROR] No snapshot found with name %s", name) + } + snapshot := allrecs[0] + d.SetId(*snapshot.ID) + d.Set(isSnapshotName, *snapshot.Name) + d.Set(isSnapshotHref, *snapshot.Href) + d.Set(isSnapshotCRN, *snapshot.CRN) + d.Set(isSnapshotMinCapacity, *snapshot.MinimumCapacity) + d.Set(isSnapshotSize, *snapshot.Size) + d.Set(isSnapshotEncryption, *snapshot.Encryption) + d.Set(isSnapshotLCState, *snapshot.LifecycleState) + d.Set(isSnapshotResourceType, *snapshot.ResourceType) + d.Set(isSnapshotBootable, *snapshot.Bootable) + if snapshot.CapturedAt != nil { + d.Set(isSnapshotCapturedAt, (*snapshot.CapturedAt).String()) + } + if snapshot.ResourceGroup != nil && snapshot.ResourceGroup.ID != nil { + d.Set(isSnapshotResourceGroup, *snapshot.ResourceGroup.ID) + } + if snapshot.SourceVolume != nil && snapshot.SourceVolume.ID != nil { + d.Set(isSnapshotSourceVolume, *snapshot.SourceVolume.ID) + } + if snapshot.SourceImage != nil && snapshot.SourceImage.ID != nil { + d.Set(isSnapshotSourceImage, *snapshot.SourceImage.ID) + } + if snapshot.OperatingSystem != nil && snapshot.OperatingSystem.Name != nil { + d.Set(isSnapshotOperatingSystem, *snapshot.OperatingSystem.Name) + } + return nil } else { getSnapshotOptions := &vpcv1.GetSnapshotOptions{ ID: &id, diff --git a/ibm/service/vpc/data_source_ibm_is_virtual_endpoint_gateway.go b/ibm/service/vpc/data_source_ibm_is_virtual_endpoint_gateway.go index dd34937481..97e0a2714a 100644 --- a/ibm/service/vpc/data_source_ibm_is_virtual_endpoint_gateway.go +++ b/ibm/service/vpc/data_source_ibm_is_virtual_endpoint_gateway.go @@ -6,7 +6,6 @@ package vpc import ( "fmt" - "github.com/IBM-Cloud/terraform-provider-ibm/ibm/flex" "github.com/IBM/vpc-go-sdk/vpcv1" "github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema" ) @@ -118,7 +117,6 @@ func DataSourceIBMISEndpointGateway() *schema.Resource { func dataSourceIBMISEndpointGatewayRead( d *schema.ResourceData, meta interface{}) error { - var found bool sess, err := vpcClient(meta) if err != nil { return err @@ -126,46 +124,33 @@ func dataSourceIBMISEndpointGatewayRead( name := d.Get(isVirtualEndpointGatewayName).(string) - start := "" - allrecs := []vpcv1.EndpointGateway{} - for { - options := sess.NewListEndpointGatewaysOptions() - if start != "" { - options.Start = &start - } - result, response, err := sess.ListEndpointGateways(options) - if err != nil { - return fmt.Errorf("[ERROR] Error fetching endpoint gateways %s\n%s", err, response) - } - start = flex.GetNext(result.Next) - allrecs = append(allrecs, result.EndpointGateways...) - if start == "" { - break - } - } - for _, result := range allrecs { - if *result.Name == name { - d.SetId(*result.ID) - d.Set(isVirtualEndpointGatewayName, result.Name) - d.Set(isVirtualEndpointGatewayCRN, result.CRN) - d.Set(isVirtualEndpointGatewayHealthState, result.HealthState) - d.Set(isVirtualEndpointGatewayCreatedAt, result.CreatedAt.String()) - d.Set(isVirtualEndpointGatewayLifecycleState, result.LifecycleState) - d.Set(isVirtualEndpointGatewayResourceType, result.ResourceType) - d.Set(isVirtualEndpointGatewayIPs, flattenIPs(result.Ips)) - d.Set(isVirtualEndpointGatewayResourceGroupID, result.ResourceGroup.ID) - d.Set(isVirtualEndpointGatewayTarget, flattenEndpointGatewayTarget( - result.Target.(*vpcv1.EndpointGatewayTarget))) - d.Set(isVirtualEndpointGatewayVpcID, result.VPC.ID) - if result.SecurityGroups != nil { - d.Set(isVirtualEndpointGatewaySecurityGroups, flattenDataSourceSecurityGroups(result.SecurityGroups)) - } - found = true - break - } + options := sess.NewListEndpointGatewaysOptions() + options.Name = &name + + results, response, err := sess.ListEndpointGateways(options) + if err != nil { + return fmt.Errorf("[ERROR] Error fetching endpoint gateways %s\n%s", err, response) } - if !found { + allrecs := results.EndpointGateways + + if len(allrecs) == 0 { return fmt.Errorf("[ERROR] No Virtual Endpoints Gateway found with given name %s", name) } + result := allrecs[0] + d.SetId(*result.ID) + d.Set(isVirtualEndpointGatewayName, result.Name) + d.Set(isVirtualEndpointGatewayCRN, result.CRN) + d.Set(isVirtualEndpointGatewayHealthState, result.HealthState) + d.Set(isVirtualEndpointGatewayCreatedAt, result.CreatedAt.String()) + d.Set(isVirtualEndpointGatewayLifecycleState, result.LifecycleState) + d.Set(isVirtualEndpointGatewayResourceType, result.ResourceType) + d.Set(isVirtualEndpointGatewayIPs, flattenIPs(result.Ips)) + d.Set(isVirtualEndpointGatewayResourceGroupID, result.ResourceGroup.ID) + d.Set(isVirtualEndpointGatewayTarget, flattenEndpointGatewayTarget( + result.Target.(*vpcv1.EndpointGatewayTarget))) + d.Set(isVirtualEndpointGatewayVpcID, result.VPC.ID) + if result.SecurityGroups != nil { + d.Set(isVirtualEndpointGatewaySecurityGroups, flattenDataSourceSecurityGroups(result.SecurityGroups)) + } return nil } diff --git a/ibm/service/vpc/data_source_ibm_is_volume.go b/ibm/service/vpc/data_source_ibm_is_volume.go index 785cb44a10..322a65cd60 100644 --- a/ibm/service/vpc/data_source_ibm_is_volume.go +++ b/ibm/service/vpc/data_source_ibm_is_volume.go @@ -186,77 +186,71 @@ func volumeGet(d *schema.ResourceData, meta interface{}, name string) error { if zname, ok := d.GetOk(isVolumeZone); ok { zone = zname.(string) } - start := "" - allrecs := []vpcv1.Volume{} - for { - listVolumesOptions := &vpcv1.ListVolumesOptions{} - if start != "" { - listVolumesOptions.Start = &start - } - if zone != "" { - listVolumesOptions.ZoneName = &zone - } - listVolumesOptions.Name = &name - vols, response, err := sess.ListVolumes(listVolumesOptions) - if err != nil { - return fmt.Errorf("[ERROR] Error Fetching volumes %s\n%s", err, response) - } - start = flex.GetNext(vols.Next) - allrecs = append(allrecs, vols.Volumes...) - if start == "" { - break - } + listVolumesOptions := &vpcv1.ListVolumesOptions{ + Name: &name, } - for _, vol := range allrecs { - d.SetId(*vol.ID) - d.Set(isVolumeBandwidth, int(*vol.Bandwidth)) - d.Set(isVolumeName, *vol.Name) - d.Set(isVolumeProfileName, *vol.Profile.Name) - d.Set(isVolumeZone, *vol.Zone.Name) - if vol.EncryptionKey != nil { - d.Set(isVolumeEncryptionKey, vol.EncryptionKey.CRN) - } - if vol.Encryption != nil { - d.Set(isVolumeEncryptionType, vol.Encryption) - } - if vol.SourceSnapshot != nil { - d.Set(isVolumeSourceSnapshot, *vol.SourceSnapshot.ID) - } - d.Set(isVolumeIops, *vol.Iops) - d.Set(isVolumeCapacity, *vol.Capacity) - d.Set(isVolumeCrn, *vol.CRN) - d.Set(isVolumeStatus, *vol.Status) - if vol.StatusReasons != nil { - statusReasonsList := make([]map[string]interface{}, 0) - for _, sr := range vol.StatusReasons { - currentSR := map[string]interface{}{} - if sr.Code != nil && sr.Message != nil { - currentSR[isVolumeStatusReasonsCode] = *sr.Code - currentSR[isVolumeStatusReasonsMessage] = *sr.Message - statusReasonsList = append(statusReasonsList, currentSR) - } + + if zone != "" { + listVolumesOptions.ZoneName = &zone + } + listVolumesOptions.Name = &name + vols, response, err := sess.ListVolumes(listVolumesOptions) + if err != nil { + return fmt.Errorf("[ERROR] Error Fetching volumes %s\n%s", err, response) + } + allrecs := vols.Volumes + + if len(allrecs) == 0 { + return fmt.Errorf("[ERROR] No Volume found with name %s", name) + } + vol := allrecs[0] + d.SetId(*vol.ID) + d.Set(isVolumeBandwidth, int(*vol.Bandwidth)) + d.Set(isVolumeName, *vol.Name) + d.Set(isVolumeProfileName, *vol.Profile.Name) + d.Set(isVolumeZone, *vol.Zone.Name) + if vol.EncryptionKey != nil { + d.Set(isVolumeEncryptionKey, vol.EncryptionKey.CRN) + } + if vol.Encryption != nil { + d.Set(isVolumeEncryptionType, vol.Encryption) + } + if vol.SourceSnapshot != nil { + d.Set(isVolumeSourceSnapshot, *vol.SourceSnapshot.ID) + } + d.Set(isVolumeIops, *vol.Iops) + d.Set(isVolumeCapacity, *vol.Capacity) + d.Set(isVolumeCrn, *vol.CRN) + d.Set(isVolumeStatus, *vol.Status) + if vol.StatusReasons != nil { + statusReasonsList := make([]map[string]interface{}, 0) + for _, sr := range vol.StatusReasons { + currentSR := map[string]interface{}{} + if sr.Code != nil && sr.Message != nil { + currentSR[isVolumeStatusReasonsCode] = *sr.Code + currentSR[isVolumeStatusReasonsMessage] = *sr.Message + statusReasonsList = append(statusReasonsList, currentSR) } - d.Set(isVolumeStatusReasons, statusReasonsList) - } - tags, err := flex.GetTagsUsingCRN(meta, *vol.CRN) - if err != nil { - log.Printf( - "Error on get of resource vpc volume (%s) tags: %s", d.Id(), err) } - d.Set(isVolumeTags, tags) - controller, err := flex.GetBaseController(meta) - if err != nil { - return err - } - d.Set(flex.ResourceControllerURL, controller+"/vpc-ext/storage/storageVolumes") - d.Set(flex.ResourceName, *vol.Name) - d.Set(flex.ResourceCRN, *vol.CRN) - d.Set(flex.ResourceStatus, *vol.Status) - if vol.ResourceGroup != nil { - d.Set(flex.ResourceGroupName, vol.ResourceGroup.Name) - d.Set(isVolumeResourceGroup, *vol.ResourceGroup.ID) - } - return nil + d.Set(isVolumeStatusReasons, statusReasonsList) } - return fmt.Errorf("[ERROR] No Volume found with name %s", name) + tags, err := flex.GetTagsUsingCRN(meta, *vol.CRN) + if err != nil { + log.Printf( + "Error on get of resource vpc volume (%s) tags: %s", d.Id(), err) + } + d.Set(isVolumeTags, tags) + controller, err := flex.GetBaseController(meta) + if err != nil { + return err + } + d.Set(flex.ResourceControllerURL, controller+"/vpc-ext/storage/storageVolumes") + d.Set(flex.ResourceName, *vol.Name) + d.Set(flex.ResourceCRN, *vol.CRN) + d.Set(flex.ResourceStatus, *vol.Status) + if vol.ResourceGroup != nil { + d.Set(flex.ResourceGroupName, vol.ResourceGroup.Name) + d.Set(isVolumeResourceGroup, *vol.ResourceGroup.ID) + } + return nil }