From 67daed3906a8d33364870f7d93897b4a1a8649ef Mon Sep 17 00:00:00 2001 From: Paulo Date: Tue, 2 Mar 2021 17:08:27 -0700 Subject: [PATCH 1/2] Fixes bug #10733 --- .../internal/services/netapp/netapp_volume_data_source.go | 2 +- .../internal/services/netapp/netapp_volume_resource.go | 8 ++++++-- 2 files changed, 7 insertions(+), 3 deletions(-) diff --git a/azurerm/internal/services/netapp/netapp_volume_data_source.go b/azurerm/internal/services/netapp/netapp_volume_data_source.go index 868231058ca5..f362312a3ef8 100644 --- a/azurerm/internal/services/netapp/netapp_volume_data_source.go +++ b/azurerm/internal/services/netapp/netapp_volume_data_source.go @@ -155,7 +155,7 @@ func dataSourceNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error return fmt.Errorf("setting `mount_ip_addresses`: %+v", err) } - if props.DataProtection.Replication != nil { + if props.DataProtection != nil && props.DataProtection.Replication != nil { if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil { return fmt.Errorf("setting `data_protection_replication`: %+v", err) } diff --git a/azurerm/internal/services/netapp/netapp_volume_resource.go b/azurerm/internal/services/netapp/netapp_volume_resource.go index 19a9ae8ffc99..f3c748e0e9a4 100644 --- a/azurerm/internal/services/netapp/netapp_volume_resource.go +++ b/azurerm/internal/services/netapp/netapp_volume_resource.go @@ -390,7 +390,7 @@ func resourceNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("mount_ip_addresses", flattenNetAppVolumeMountIPAddresses(props.MountTargets)); err != nil { return fmt.Errorf("setting `mount_ip_addresses`: %+v", err) } - if props.DataProtection.Replication != nil { + if props.DataProtection != nil && props.DataProtection.Replication != nil { if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil { return fmt.Errorf("setting `data_protection_replication`: %+v", err) } @@ -789,7 +789,11 @@ func flattenNetAppVolumeMountIPAddresses(input *[]netapp.MountTargetProperties) } func flattenNetAppVolumeDataProtectionReplication(input *netapp.VolumePropertiesDataProtection) []interface{} { - if input == nil || input.Replication == nil || strings.ToLower(string(input.Replication.EndpointType)) != "dst" { + if input == nil || input.Replication == nil { + return []interface{}{} + } + + if strings.ToLower(string(input.Replication.EndpointType)) == "" || strings.ToLower(string(input.Replication.EndpointType)) != "dst" { return []interface{}{} } From 05559b7a3b354eff13eae1d93e05b98910650dc7 Mon Sep 17 00:00:00 2001 From: Paulo Date: Wed, 3 Mar 2021 11:20:53 -0700 Subject: [PATCH 2/2] Applying changes requested by Tom --- .../internal/services/netapp/netapp_volume_data_source.go | 7 ++----- azurerm/internal/services/netapp/netapp_volume_resource.go | 6 ++---- 2 files changed, 4 insertions(+), 9 deletions(-) diff --git a/azurerm/internal/services/netapp/netapp_volume_data_source.go b/azurerm/internal/services/netapp/netapp_volume_data_source.go index f362312a3ef8..0ba4bbc9b07f 100644 --- a/azurerm/internal/services/netapp/netapp_volume_data_source.go +++ b/azurerm/internal/services/netapp/netapp_volume_data_source.go @@ -154,11 +154,8 @@ func dataSourceNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error if err := d.Set("mount_ip_addresses", flattenNetAppVolumeMountIPAddresses(props.MountTargets)); err != nil { return fmt.Errorf("setting `mount_ip_addresses`: %+v", err) } - - if props.DataProtection != nil && props.DataProtection.Replication != nil { - if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil { - return fmt.Errorf("setting `data_protection_replication`: %+v", err) - } + if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil { + return fmt.Errorf("setting `data_protection_replication`: %+v", err) } } diff --git a/azurerm/internal/services/netapp/netapp_volume_resource.go b/azurerm/internal/services/netapp/netapp_volume_resource.go index f3c748e0e9a4..5dcd742f11c2 100644 --- a/azurerm/internal/services/netapp/netapp_volume_resource.go +++ b/azurerm/internal/services/netapp/netapp_volume_resource.go @@ -390,10 +390,8 @@ func resourceNetAppVolumeRead(d *schema.ResourceData, meta interface{}) error { if err := d.Set("mount_ip_addresses", flattenNetAppVolumeMountIPAddresses(props.MountTargets)); err != nil { return fmt.Errorf("setting `mount_ip_addresses`: %+v", err) } - if props.DataProtection != nil && props.DataProtection.Replication != nil { - if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil { - return fmt.Errorf("setting `data_protection_replication`: %+v", err) - } + if err := d.Set("data_protection_replication", flattenNetAppVolumeDataProtectionReplication(props.DataProtection)); err != nil { + return fmt.Errorf("setting `data_protection_replication`: %+v", err) } }