From 120599e68f27100be3a4a53ca2078f1f7f620ff6 Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Mon, 1 Jun 2015 11:18:48 +0200 Subject: [PATCH] Add some additional checks --- builtin/providers/azure/resource_azure_instance.go | 4 ++++ builtin/providers/azure/resource_azure_security_group.go | 8 ++++++++ 2 files changed, 12 insertions(+) diff --git a/builtin/providers/azure/resource_azure_instance.go b/builtin/providers/azure/resource_azure_instance.go index 7ad150c3d..ad8a77a9c 100644 --- a/builtin/providers/azure/resource_azure_instance.go +++ b/builtin/providers/azure/resource_azure_instance.go @@ -340,6 +340,10 @@ func resourceAzureInstanceRead(d *schema.ResourceData, meta interface{}) error { log.Printf("[DEBUG] Retrieving instance: %s", d.Id()) dpmt, err := virtualmachine.NewClient(mc).GetDeployment(d.Id(), d.Id()) if err != nil { + if management.IsResourceNotFoundError(err) { + d.SetId("") + return nil + } return fmt.Errorf("Error retrieving instance %s: %s", d.Id(), err) } diff --git a/builtin/providers/azure/resource_azure_security_group.go b/builtin/providers/azure/resource_azure_security_group.go index 0d7e8a0a1..842b12434 100644 --- a/builtin/providers/azure/resource_azure_security_group.go +++ b/builtin/providers/azure/resource_azure_security_group.go @@ -8,6 +8,7 @@ import ( "github.com/hashicorp/terraform/helper/hashcode" "github.com/hashicorp/terraform/helper/schema" + "github.com/svanharmelen/azure-sdk-for-go/management" "github.com/svanharmelen/azure-sdk-for-go/management/networksecuritygroup" ) @@ -194,6 +195,10 @@ func resourceAzureSecurityGroupRead(d *schema.ResourceData, meta interface{}) er sg, err := networksecuritygroup.NewClient(mc).GetNetworkSecurityGroup(d.Id()) if err != nil { + if management.IsResourceNotFoundError(err) { + d.SetId("") + return nil + } return fmt.Errorf("Error retrieving Network Security Group %s: %s", d.Id(), err) } @@ -293,6 +298,9 @@ func resourceAzureSecurityGroupRuleDelete( // Delete the rule req, err := networksecuritygroup.NewClient(mc).DeleteNetworkSecurityGroupRule(d.Id(), name) if err != nil { + if management.IsResourceNotFoundError(err) { + return nil + } return fmt.Errorf("Error deleting Network Security Group rule %s: %s", name, err) }