From 28eff1bf5e58eaed70a31b8cdb89f5934b7a0680 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 27 Aug 2020 07:34:30 +0200 Subject: [PATCH 1/6] r/network_interface_application_gateway_association: handling the nic being gone during read --- ...ork_interface_application_gateway_association_resource.go | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go b/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go index 7fe72836b80b..84e05933586e 100644 --- a/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go +++ b/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go @@ -84,6 +84,7 @@ func resourceArmNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationC read, err := client.Get(ctx, resourceGroup, networkInterfaceName, "") if err != nil { if utils.ResponseWasNotFound(read.Response) { + return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", networkInterfaceName, resourceGroup) } @@ -176,7 +177,9 @@ func resourceArmNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationR read, err := client.Get(ctx, resourceGroup, networkInterfaceName, "") if err != nil { if utils.ResponseWasNotFound(read.Response) { - return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", networkInterfaceName, resourceGroup) + log.Printf("Network Interface %q (Resource Group %q) was not found - removing from state!", networkInterfaceName, resourceGroup) + d.SetId("") + return nil } return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) From 111849b170183f4027d10ee890ec6e51d4f6faaa Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 27 Aug 2020 07:34:52 +0200 Subject: [PATCH 2/6] r/network_interface_application_security_group_association: handling the nic being gone during read --- ...terface_application_security_group_association_resource.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/network/network_interface_application_security_group_association_resource.go b/azurerm/internal/services/network/network_interface_application_security_group_association_resource.go index 97d6fabe45c9..df63275fac5e 100644 --- a/azurerm/internal/services/network/network_interface_application_security_group_association_resource.go +++ b/azurerm/internal/services/network/network_interface_application_security_group_association_resource.go @@ -144,7 +144,9 @@ func resourceArmNetworkInterfaceApplicationSecurityGroupAssociationRead(d *schem read, err := client.Get(ctx, resourceGroup, networkInterfaceName, "") if err != nil { if utils.ResponseWasNotFound(read.Response) { - return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", networkInterfaceName, resourceGroup) + log.Printf("[DEBUG] Network Interface %q (Resource Group %q) was not found - removing from state!", networkInterfaceName, resourceGroup) + d.SetId("") + return nil } return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) From a25541efb6a455bcb900b873d20f3bba6e8a8fd9 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 27 Aug 2020 07:35:19 +0200 Subject: [PATCH 3/6] r/network_interface_backend_address_pool_association: handling the nic being gone during read --- ...ork_interface_backend_address_pool_association_resource.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/network/network_interface_backend_address_pool_association_resource.go b/azurerm/internal/services/network/network_interface_backend_address_pool_association_resource.go index e891bdea0300..d731f3c7876c 100644 --- a/azurerm/internal/services/network/network_interface_backend_address_pool_association_resource.go +++ b/azurerm/internal/services/network/network_interface_backend_address_pool_association_resource.go @@ -176,7 +176,9 @@ func resourceArmNetworkInterfaceBackendAddressPoolAssociationRead(d *schema.Reso read, err := client.Get(ctx, resourceGroup, networkInterfaceName, "") if err != nil { if utils.ResponseWasNotFound(read.Response) { - return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", networkInterfaceName, resourceGroup) + log.Printf("Network Interface %q (Resource Group %q) was not found - removing from state!", networkInterfaceName, resourceGroup) + d.SetId("") + return nil } return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) From aca0fef14469af26b6acfadb06665e46575ce1d1 Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 27 Aug 2020 07:35:28 +0200 Subject: [PATCH 4/6] r/network_interface_nat_rule_association_resource: handling the nic being gone during a read --- .../network_interface_nat_rule_association_resource.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/network/network_interface_nat_rule_association_resource.go b/azurerm/internal/services/network/network_interface_nat_rule_association_resource.go index 856fb3264476..ad226270276a 100644 --- a/azurerm/internal/services/network/network_interface_nat_rule_association_resource.go +++ b/azurerm/internal/services/network/network_interface_nat_rule_association_resource.go @@ -176,7 +176,9 @@ func resourceArmNetworkInterfaceNatRuleAssociationRead(d *schema.ResourceData, m read, err := client.Get(ctx, resourceGroup, networkInterfaceName, "") if err != nil { if utils.ResponseWasNotFound(read.Response) { - return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", networkInterfaceName, resourceGroup) + log.Printf("Network Interface %q (Resource Group %q) was not found - removing from state!", networkInterfaceName, resourceGroup) + d.SetId("") + return nil } return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", networkInterfaceName, resourceGroup, err) From ab3ff745785e358d856da044ffcd0cf1ca6a1eaf Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 27 Aug 2020 07:36:08 +0200 Subject: [PATCH 5/6] r/network_interface_network_security_group_association: handling the nic being gone during a read --- ...k_interface_network_security_group_association_resource.go | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) diff --git a/azurerm/internal/services/network/network_interface_network_security_group_association_resource.go b/azurerm/internal/services/network/network_interface_network_security_group_association_resource.go index cdf3b5de68fb..4117d2c08d6c 100644 --- a/azurerm/internal/services/network/network_interface_network_security_group_association_resource.go +++ b/azurerm/internal/services/network/network_interface_network_security_group_association_resource.go @@ -143,7 +143,9 @@ func resourceArmNetworkInterfaceSecurityGroupAssociationRead(d *schema.ResourceD read, err := client.Get(ctx, resourceGroup, name, "") if err != nil { if utils.ResponseWasNotFound(read.Response) { - return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", name, resourceGroup) + log.Printf("Network Interface %q (Resource Group %q) was not found - removing from state!", name, resourceGroup) + d.SetId("") + return nil } return fmt.Errorf("Error retrieving Network Interface %q (Resource Group %q): %+v", name, resourceGroup, err) From dc52c9e53acd6f87b6fcc61d51f2a6ac0e22ee3b Mon Sep 17 00:00:00 2001 From: tombuildsstuff Date: Thu, 27 Aug 2020 08:40:58 +0200 Subject: [PATCH 6/6] linting --- ...network_interface_application_gateway_association_resource.go | 1 - 1 file changed, 1 deletion(-) diff --git a/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go b/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go index 84e05933586e..83021dbdadd6 100644 --- a/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go +++ b/azurerm/internal/services/network/network_interface_application_gateway_association_resource.go @@ -84,7 +84,6 @@ func resourceArmNetworkInterfaceApplicationGatewayBackendAddressPoolAssociationC read, err := client.Get(ctx, resourceGroup, networkInterfaceName, "") if err != nil { if utils.ResponseWasNotFound(read.Response) { - return fmt.Errorf("Network Interface %q (Resource Group %q) was not found!", networkInterfaceName, resourceGroup) }