Fixes behaviour when azurerm resources disappear.
Regressions were introduced when fixing https://github.com/hashicorp/terraform/pull/8607 . Specifically when resources in the statefile are deleted or missing in real life, then terraform plan would exit with an error when it recieved a 404 not found. The correct behaviour would be to show a plan with the offer to create the missing resources.
This commit is contained in:
parent
00c0c75b16
commit
e5219ba56d
|
@ -118,12 +118,12 @@ func resourceArmAvailabilitySetRead(d *schema.ResourceData, meta interface{}) er
|
||||||
|
|
||||||
resp, err := availSetClient.Get(resGroup, name)
|
resp, err := availSetClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Availability Set %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Availability Set %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
availSet := *resp.Properties
|
availSet := *resp.Properties
|
||||||
d.Set("platform_update_domain_count", availSet.PlatformUpdateDomainCount)
|
d.Set("platform_update_domain_count", availSet.PlatformUpdateDomainCount)
|
||||||
|
|
|
@ -226,12 +226,12 @@ func resourceArmCdnEndpointRead(d *schema.ResourceData, meta interface{}) error
|
||||||
log.Printf("[INFO] Trying to find the AzureRM CDN Endpoint %s (Profile: %s, RG: %s)", name, profileName, resGroup)
|
log.Printf("[INFO] Trying to find the AzureRM CDN Endpoint %s (Profile: %s, RG: %s)", name, profileName, resGroup)
|
||||||
resp, err := cdnEndpointsClient.Get(name, profileName, resGroup)
|
resp, err := cdnEndpointsClient.Get(name, profileName, resGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure CDN Endpoint %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure CDN Endpoint %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
d.Set("host_name", resp.Properties.HostName)
|
d.Set("host_name", resp.Properties.HostName)
|
||||||
|
|
|
@ -100,12 +100,12 @@ func resourceArmCdnProfileRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := cdnProfilesClient.Get(name, resGroup)
|
resp, err := cdnProfilesClient.Get(name, resGroup)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure CDN Profile %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Sku != nil {
|
if resp.Sku != nil {
|
||||||
d.Set("sku", string(resp.Sku.Name))
|
d.Set("sku", string(resp.Sku.Name))
|
||||||
|
|
|
@ -110,12 +110,12 @@ func resourceArmLocalNetworkGatewayRead(d *schema.ResourceData, meta interface{}
|
||||||
|
|
||||||
resp, err := lnetClient.Get(resGroup, name)
|
resp, err := lnetClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
return fmt.Errorf("Error reading the state of Azure ARM local network gateway '%s': %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
d.Set("location", resp.Location)
|
d.Set("location", resp.Location)
|
||||||
|
|
|
@ -246,12 +246,12 @@ func resourceArmNetworkInterfaceRead(d *schema.ResourceData, meta interface{}) e
|
||||||
|
|
||||||
resp, err := ifaceClient.Get(resGroup, name, "")
|
resp, err := ifaceClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Network Interface %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Network Interface %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
iface := *resp.Properties
|
iface := *resp.Properties
|
||||||
|
|
||||||
|
|
|
@ -192,12 +192,12 @@ func resourceArmNetworkSecurityGroupRead(d *schema.ResourceData, meta interface{
|
||||||
|
|
||||||
resp, err := secGroupClient.Get(resGroup, name, "")
|
resp, err := secGroupClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Network Security Group %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Network Security Group %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Properties.SecurityRules != nil {
|
if resp.Properties.SecurityRules != nil {
|
||||||
d.Set("security_rule", flattenNetworkSecurityRules(resp.Properties.SecurityRules))
|
d.Set("security_rule", flattenNetworkSecurityRules(resp.Properties.SecurityRules))
|
||||||
|
|
|
@ -176,12 +176,12 @@ func resourceArmNetworkSecurityRuleRead(d *schema.ResourceData, meta interface{}
|
||||||
|
|
||||||
resp, err := secRuleClient.Get(resGroup, networkSGName, sgRuleName)
|
resp, err := secRuleClient.Get(resGroup, networkSGName, sgRuleName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Network Security Rule %s: %s", sgRuleName, err)
|
return fmt.Errorf("Error making Read request on Azure Network Security Rule %s: %s", sgRuleName, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("access", resp.Properties.Access)
|
d.Set("access", resp.Properties.Access)
|
||||||
d.Set("destination_address_prefix", resp.Properties.DestinationAddressPrefix)
|
d.Set("destination_address_prefix", resp.Properties.DestinationAddressPrefix)
|
||||||
|
|
|
@ -166,12 +166,12 @@ func resourceArmPublicIpRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := publicIPClient.Get(resGroup, name, "")
|
resp, err := publicIPClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure public ip %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("location", resp.Location)
|
d.Set("location", resp.Location)
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
|
|
|
@ -113,12 +113,12 @@ func resourceArmRouteRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := routesClient.Get(resGroup, rtName, routeName)
|
resp, err := routesClient.Get(resGroup, rtName, routeName)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Route %s: %s", routeName, err)
|
return fmt.Errorf("Error making Read request on Azure Route %s: %s", routeName, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
|
@ -143,12 +143,12 @@ func resourceArmRouteTableRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
|
|
||||||
resp, err := routeTablesClient.Get(resGroup, name, "")
|
resp, err := routeTablesClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Route Table %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Route Table %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Properties.Subnets != nil {
|
if resp.Properties.Subnets != nil {
|
||||||
if len(*resp.Properties.Subnets) > 0 {
|
if len(*resp.Properties.Subnets) > 0 {
|
||||||
|
|
|
@ -256,12 +256,12 @@ func resourceArmStorageAccountRead(d *schema.ResourceData, meta interface{}) err
|
||||||
|
|
||||||
resp, err := client.GetProperties(resGroup, name)
|
resp, err := client.GetProperties(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error reading the state of AzureRM Storage Account %q: %s", name, err)
|
return fmt.Errorf("Error reading the state of AzureRM Storage Account %q: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
keys, err := client.ListKeys(resGroup, name)
|
keys, err := client.ListKeys(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
|
|
@ -133,12 +133,12 @@ func resourceArmSubnetRead(d *schema.ResourceData, meta interface{}) error {
|
||||||
resp, err := subnetClient.Get(resGroup, vnetName, name, "")
|
resp, err := subnetClient.Get(resGroup, vnetName, name, "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Subnet %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Subnet %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Properties.IPConfigurations != nil && len(*resp.Properties.IPConfigurations) > 0 {
|
if resp.Properties.IPConfigurations != nil && len(*resp.Properties.IPConfigurations) > 0 {
|
||||||
ips := make([]string, 0, len(*resp.Properties.IPConfigurations))
|
ips := make([]string, 0, len(*resp.Properties.IPConfigurations))
|
||||||
|
|
|
@ -144,12 +144,12 @@ func resourceArmTemplateDeploymentRead(d *schema.ResourceData, meta interface{})
|
||||||
|
|
||||||
resp, err := deployClient.Get(resGroup, name)
|
resp, err := deployClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure RM Template Deployment %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure RM Template Deployment %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
var outputs map[string]string
|
var outputs map[string]string
|
||||||
if resp.Properties.Outputs != nil && len(*resp.Properties.Outputs) > 0 {
|
if resp.Properties.Outputs != nil && len(*resp.Properties.Outputs) > 0 {
|
||||||
|
|
|
@ -153,12 +153,12 @@ func resourceArmTrafficManagerEndpointRead(d *schema.ResourceData, meta interfac
|
||||||
|
|
||||||
resp, err := client.Get(resGroup, profileName, endpointType, name)
|
resp, err := client.Get(resGroup, profileName, endpointType, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on TrafficManager Endpoint %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on TrafficManager Endpoint %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
endpoint := *resp.Properties
|
endpoint := *resp.Properties
|
||||||
|
|
||||||
|
|
|
@ -151,12 +151,12 @@ func resourceArmTrafficManagerProfileRead(d *schema.ResourceData, meta interface
|
||||||
|
|
||||||
resp, err := client.Get(resGroup, name)
|
resp, err := client.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Traffic Manager Profile %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Traffic Manager Profile %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
profile := *resp.Properties
|
profile := *resp.Properties
|
||||||
|
|
||||||
|
|
|
@ -520,12 +520,12 @@ func resourceArmVirtualMachineRead(d *schema.ResourceData, meta interface{}) err
|
||||||
resp, err := vmClient.Get(resGroup, name, "")
|
resp, err := vmClient.Get(resGroup, name, "")
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Virtual Machine %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Virtual Machine %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
if resp.Plan != nil {
|
if resp.Plan != nil {
|
||||||
if err := d.Set("plan", flattenAzureRmVirtualMachinePlan(resp.Plan)); err != nil {
|
if err := d.Set("plan", flattenAzureRmVirtualMachinePlan(resp.Plan)); err != nil {
|
||||||
|
|
|
@ -432,13 +432,13 @@ func resourceArmVirtualMachineScaleSetRead(d *schema.ResourceData, meta interfac
|
||||||
|
|
||||||
resp, err := vmScaleSetClient.Get(resGroup, name)
|
resp, err := vmScaleSetClient.Get(resGroup, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
log.Printf("[INFO] AzureRM Virtual Machine Scale Set (%s) Not Found. Removing from State", name)
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure Virtual Machine Scale Set %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure Virtual Machine Scale Set %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
log.Printf("[INFO] AzureRM Virtual Machine Scale Set (%s) Not Found. Removing from State", name)
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
d.Set("location", resp.Location)
|
d.Set("location", resp.Location)
|
||||||
d.Set("name", resp.Name)
|
d.Set("name", resp.Name)
|
||||||
|
|
|
@ -133,12 +133,13 @@ func resourceArmVirtualNetworkRead(d *schema.ResourceData, meta interface{}) err
|
||||||
|
|
||||||
resp, err := vnetClient.Get(resGroup, name, "")
|
resp, err := vnetClient.Get(resGroup, name, "")
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure virtual network %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure virtual network %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
vnet := *resp.Properties
|
vnet := *resp.Properties
|
||||||
|
|
||||||
// update appropriate values
|
// update appropriate values
|
||||||
|
|
|
@ -124,12 +124,12 @@ func resourceArmVirtualNetworkPeeringRead(d *schema.ResourceData, meta interface
|
||||||
|
|
||||||
resp, err := client.Get(resGroup, vnetName, name)
|
resp, err := client.Get(resGroup, vnetName, name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
if resp.StatusCode == http.StatusNotFound {
|
||||||
|
d.SetId("")
|
||||||
|
return nil
|
||||||
|
}
|
||||||
return fmt.Errorf("Error making Read request on Azure virtual network peering %s: %s", name, err)
|
return fmt.Errorf("Error making Read request on Azure virtual network peering %s: %s", name, err)
|
||||||
}
|
}
|
||||||
if resp.StatusCode == http.StatusNotFound {
|
|
||||||
d.SetId("")
|
|
||||||
return nil
|
|
||||||
}
|
|
||||||
|
|
||||||
peer := *resp.Properties
|
peer := *resp.Properties
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue