diff --git a/azurerm/internal/services/apimanagement/api_management_group_data_source.go b/azurerm/internal/services/apimanagement/api_management_group_data_source.go index d0dbf410f8e6..1f85f2bea518 100644 --- a/azurerm/internal/services/apimanagement/api_management_group_data_source.go +++ b/azurerm/internal/services/apimanagement/api_management_group_data_source.go @@ -2,7 +2,6 @@ package apimanagement import ( "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -62,9 +61,7 @@ func dataSourceApiManagementGroupRead(d *schema.ResourceData, meta interface{}) resp, err := client.Get(ctx, resourceGroup, serviceName, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] Group %q (Resource Group %q / API Management Service %q) was not found - removing from state!", name, resourceGroup, serviceName) - d.SetId("") - return nil + return fmt.Errorf("Group %q (Resource Group %q / API Management Service %q) was not found", name, resourceGroup, serviceName) } return fmt.Errorf("making Read request for Group %q (Resource Group %q / API Management Service %q): %+v", name, resourceGroup, serviceName, err) diff --git a/azurerm/internal/services/compute/image_data_source.go b/azurerm/internal/services/compute/image_data_source.go index e9217965b84d..1027d088915d 100644 --- a/azurerm/internal/services/compute/image_data_source.go +++ b/azurerm/internal/services/compute/image_data_source.go @@ -152,7 +152,7 @@ func dataSourceArmImageRead(d *schema.ResourceData, meta interface{}) error { resp, err := client.ListByResourceGroupComplete(ctx, resGroup) if err != nil { if utils.ResponseWasNotFound(resp.Response().Response) { - return fmt.Errorf("Error: Unable to list images for Resource Group %q", resGroup) + return fmt.Errorf("No Images were found for Resource Group %q", resGroup) } return fmt.Errorf("[ERROR] Error getting list of images (resource group %q): %+v", resGroup, err) } @@ -162,21 +162,20 @@ func dataSourceArmImageRead(d *schema.ResourceData, meta interface{}) error { if r.Match(([]byte)(*img.Name)) { list = append(list, img) } - err = resp.Next() + err = resp.NextWithContext(ctx) if err != nil { return err } } - if len(list) < 1 { - d.SetId("") - return nil + if 1 > len(list) { + return fmt.Errorf("No Images were found for Resource Group %q", resGroup) } if len(list) > 1 { desc := d.Get("sort_descending").(bool) - log.Printf("[DEBUG] arm_image - multiple results found and `sort_descending` is set to: %t", desc) + log.Printf("[DEBUG] Image - multiple results found and `sort_descending` is set to: %t", desc) sort.Slice(list, func(i, j int) bool { return (!desc && *list[i].Name < *list[j].Name) || diff --git a/azurerm/internal/services/compute/shared_image_version_data_source.go b/azurerm/internal/services/compute/shared_image_version_data_source.go index a43222fe2fd2..95c8ea153a49 100644 --- a/azurerm/internal/services/compute/shared_image_version_data_source.go +++ b/azurerm/internal/services/compute/shared_image_version_data_source.go @@ -3,7 +3,6 @@ package compute import ( "context" "fmt" - "log" "time" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" @@ -95,17 +94,11 @@ func dataSourceArmSharedImageVersionRead(d *schema.ResourceData, meta interface{ galleryName := d.Get("gallery_name").(string) resourceGroup := d.Get("resource_group_name").(string) - image, found, err := obtainImage(client, ctx, resourceGroup, galleryName, imageName, imageVersion) + image, err := obtainImage(client, ctx, resourceGroup, galleryName, imageName, imageVersion) if err != nil { - d.SetId("") return err } - if !found { - d.SetId("") - return nil - } - d.SetId(*image.ID) d.Set("name", image.Name) d.Set("image_name", imageName) @@ -136,60 +129,64 @@ func dataSourceArmSharedImageVersionRead(d *schema.ResourceData, meta interface{ return tags.FlattenAndSet(d, image.Tags) } -func obtainImage(client *compute.GalleryImageVersionsClient, ctx context.Context, resourceGroup string, galleryName string, galleryImageName string, galleryImageVersionName string) (compute.GalleryImageVersion, bool, error) { - var ( - image compute.GalleryImageVersion - err error - found bool - ) +func obtainImage(client *compute.GalleryImageVersionsClient, ctx context.Context, resourceGroup string, galleryName string, galleryImageName string, galleryImageVersionName string) (*compute.GalleryImageVersion, error) { + notFoundError := fmt.Errorf("A Version was not found for Shared Image %q / Gallery %q / Resource Group %q", galleryImageName, galleryName, resourceGroup) + switch galleryImageVersionName { case "latest": images, err := client.ListByGalleryImage(ctx, resourceGroup, galleryName, galleryImageName) if err != nil { if utils.ResponseWasNotFound(images.Response().Response) { - log.Printf("[DEBUG] Shared Image Versions (Image %q / Gallery %q / Resource Group %q) was not found - removing from state", galleryImageName, galleryName, resourceGroup) - return image, false, nil + return nil, notFoundError } - return image, false, fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) + return nil, fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) } + // the last image in the list is the latest version if len(images.Values()) > 0 { - image = images.Values()[len(images.Values())-1] - found = true + image := images.Values()[len(images.Values())-1] + return &image, nil } + + return nil, notFoundError + case "recent": images, err := client.ListByGalleryImage(ctx, resourceGroup, galleryName, galleryImageName) if err != nil { if utils.ResponseWasNotFound(images.Response().Response) { - log.Printf("[DEBUG] Shared Image Versions (Image %q / Gallery %q / Resource Group %q) was not found - removing from state", galleryImageName, galleryName, resourceGroup) - return image, false, nil + return nil, notFoundError } - return image, false, fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) + return nil, fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageName, galleryName, resourceGroup, err) } - var recentDate time.Time + var image *compute.GalleryImageVersion + var recentDate *time.Time // compare dates until we find the image that was updated most recently for _, currImage := range images.Values() { if profile := currImage.PublishingProfile; profile != nil { - if profile.PublishedDate != nil && profile.PublishedDate.Time.After(recentDate) { - recentDate = profile.PublishedDate.Time - image = currImage - found = true + if profile.PublishedDate != nil && (recentDate == nil || profile.PublishedDate.Time.After(*recentDate)) { + recentDate = &profile.PublishedDate.Time + image = &currImage } } } + + if image != nil { + return image, nil + } + + return nil, notFoundError + default: - image, err = client.Get(ctx, resourceGroup, galleryName, galleryImageName, galleryImageVersionName, compute.ReplicationStatusTypesReplicationStatus) + image, err := client.Get(ctx, resourceGroup, galleryName, galleryImageName, galleryImageVersionName, compute.ReplicationStatusTypesReplicationStatus) if err != nil { if utils.ResponseWasNotFound(image.Response) { - log.Printf("[DEBUG] Shared Image Version %q (Image %q / Gallery %q / Resource Group %q) was not found - removing from state", galleryImageVersionName, galleryImageName, galleryName, resourceGroup) - return image, false, nil + return nil, notFoundError } - return image, false, fmt.Errorf("Error retrieving Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageVersionName, galleryImageName, galleryName, resourceGroup, err) + return nil, fmt.Errorf("Error retrieving Shared Image Version %q (Image %q / Gallery %q / Resource Group %q): %+v", galleryImageVersionName, galleryImageName, galleryName, resourceGroup, err) } - found = true - } - return image, found, nil + return &image, nil + } } func flattenSharedImageVersionDataSourceTargetRegions(input *[]compute.TargetRegion) []interface{} { diff --git a/azurerm/internal/services/compute/shared_image_versions_data_source.go b/azurerm/internal/services/compute/shared_image_versions_data_source.go index 59f51dff0478..ad4ca24b33c5 100644 --- a/azurerm/internal/services/compute/shared_image_versions_data_source.go +++ b/azurerm/internal/services/compute/shared_image_versions_data_source.go @@ -2,7 +2,6 @@ package compute import ( "fmt" - "log" "time" "github.com/Azure/azure-sdk-for-go/services/compute/mgmt/2019-07-01/compute" @@ -106,9 +105,7 @@ func dataSourceArmSharedImageVersionsRead(d *schema.ResourceData, meta interface resp, err := client.ListByGalleryImage(ctx, resourceGroup, galleryName, imageName) if err != nil { if utils.ResponseWasNotFound(resp.Response().Response) { - log.Printf("[DEBUG] Shared Image Versions (Image %q / Gallery %q / Resource Group %q) was not found - removing from state", imageName, galleryName, resourceGroup) - d.SetId("") - return nil + return fmt.Errorf("Shared Image Versions (Image %q / Gallery %q / Resource Group %q) was not found", imageName, galleryName, resourceGroup) } return fmt.Errorf("retrieving Shared Image Versions (Image %q / Gallery %q / Resource Group %q): %+v", imageName, galleryName, resourceGroup, err) } diff --git a/azurerm/internal/services/datalake/data_lake_store_data_source.go b/azurerm/internal/services/datalake/data_lake_store_data_source.go index 50984d1360b4..4eb28727d36a 100644 --- a/azurerm/internal/services/datalake/data_lake_store_data_source.go +++ b/azurerm/internal/services/datalake/data_lake_store_data_source.go @@ -2,7 +2,6 @@ package datalake import ( "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -72,11 +71,9 @@ func dataSourceArmDateLakeStoreAccountRead(d *schema.ResourceData, meta interfac resp, err := client.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[WARN] DataLakeStoreAccount %q was not found (Resource Group %q)", name, resourceGroup) - d.SetId("") - return nil + return fmt.Errorf("Data Lake Store Account %q was not found in Resource Group %q", name, resourceGroup) } - return fmt.Errorf("Error making Read request on Azure Data Lake %q (Resource Group %q): %+v", name, resourceGroup, err) + return fmt.Errorf("retrieving Data Lake Store Account %q (Resource Group %q): %+v", name, resourceGroup, err) } d.SetId(*resp.ID) diff --git a/azurerm/internal/services/datashare/data_share_account_data_source.go b/azurerm/internal/services/datashare/data_share_account_data_source.go index 8d467b8fab2b..2c8e6aa640af 100644 --- a/azurerm/internal/services/datashare/data_share_account_data_source.go +++ b/azurerm/internal/services/datashare/data_share_account_data_source.go @@ -2,7 +2,6 @@ package datashare import ( "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -68,9 +67,7 @@ func dataSourceArmDataShareAccountRead(d *schema.ResourceData, meta interface{}) resp, err := client.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] DataShare %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil + return fmt.Errorf("DataShare Account %q does not exist in Resource Group %q", name, resourceGroup) } return fmt.Errorf("retrieving DataShare Account %q (Resource Group %q): %+v", name, resourceGroup, err) } diff --git a/azurerm/internal/services/hdinsight/hdinsight_cluster_data_source.go b/azurerm/internal/services/hdinsight/hdinsight_cluster_data_source.go index 082431a83061..2c50ae6015a9 100644 --- a/azurerm/internal/services/hdinsight/hdinsight_cluster_data_source.go +++ b/azurerm/internal/services/hdinsight/hdinsight_cluster_data_source.go @@ -2,7 +2,6 @@ package hdinsight import ( "fmt" - "log" "strings" "time" @@ -111,9 +110,7 @@ func dataSourceArmHDInsightClusterRead(d *schema.ResourceData, meta interface{}) resp, err := clustersClient.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[DEBUG] HDInsight Cluster %q was not found in Resource Group %q - removing from state!", name, resourceGroup) - d.SetId("") - return nil + return fmt.Errorf("HDInsight Cluster %q was not found in Resource Group %q", name, resourceGroup) } return fmt.Errorf("Error retrieving HDInsight Cluster %q (Resource Group %q): %+v", name, resourceGroup, err) diff --git a/azurerm/internal/services/healthcare/healthcare_service_data_source.go b/azurerm/internal/services/healthcare/healthcare_service_data_source.go index 5d73c82fef94..c8984a588f7c 100644 --- a/azurerm/internal/services/healthcare/healthcare_service_data_source.go +++ b/azurerm/internal/services/healthcare/healthcare_service_data_source.go @@ -2,7 +2,6 @@ package healthcare import ( "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -126,8 +125,6 @@ func dataSourceArmHealthcareServiceRead(d *schema.ResourceData, meta interface{} resp, err := client.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[WARN] Healthcare Service %q was not found (Resource Group %q)", name, resourceGroup) - d.SetId("") return fmt.Errorf("HealthCare Service %q was not found in Resource Group %q", name, resourceGroup) } return fmt.Errorf("Error making Read request on Azure Healthcare Service %q (Resource Group %q): %+v", name, resourceGroup, err) @@ -138,25 +135,23 @@ func dataSourceArmHealthcareServiceRead(d *schema.ResourceData, meta interface{} d.Set("kind", kind) } - if properties := resp.Properties; properties != nil { - if accessPolicies := properties.AccessPolicies; accessPolicies != nil { - d.Set("access_policy_object_ids", flattenHealthcareAccessPolicies(accessPolicies)) + if props := resp.Properties; props != nil { + if err := d.Set("access_policy_object_ids", flattenHealthcareAccessPolicies(props.AccessPolicies)); err != nil { + return fmt.Errorf("Error setting `access_policy_object_ids`: %+v", err) } - if config := properties.CosmosDbConfiguration; config != nil { - d.Set("cosmosdb_throughput", config.OfferThroughput) + cosmosThroughput := 0 + if props.CosmosDbConfiguration != nil && props.CosmosDbConfiguration.OfferThroughput != nil { + cosmosThroughput = int(*props.CosmosDbConfiguration.OfferThroughput) } + d.Set("cosmosdb_throughput", cosmosThroughput) - if authConfig := properties.AuthenticationConfiguration; authConfig != nil { - if err := d.Set("authentication_configuration", flattenHealthcareAuthConfig(authConfig)); err != nil { - return fmt.Errorf("Error setting `authentication_configuration`: %+v", flattenHealthcareAuthConfig(authConfig)) - } + if err := d.Set("authentication_configuration", flattenHealthcareAuthConfig(props.AuthenticationConfiguration)); err != nil { + return fmt.Errorf("Error setting `authentication_configuration`: %+v", err) } - if corsConfig := properties.CorsConfiguration; corsConfig != nil { - if err := d.Set("cors_configuration", flattenHealthcareCorsConfig(corsConfig)); err != nil { - return fmt.Errorf("Error setting `cors_configuration`: %+v", flattenHealthcareCorsConfig(corsConfig)) - } + if err := d.Set("cors_configuration", flattenHealthcareCorsConfig(props.CorsConfiguration)); err != nil { + return fmt.Errorf("Error setting `cors_configuration`: %+v", err) } } diff --git a/azurerm/internal/services/healthcare/healthcare_service_resource.go b/azurerm/internal/services/healthcare/healthcare_service_resource.go index e4bb8cb21d2c..5aee9e63b7c0 100644 --- a/azurerm/internal/services/healthcare/healthcare_service_resource.go +++ b/azurerm/internal/services/healthcare/healthcare_service_resource.go @@ -255,24 +255,23 @@ func resourceArmHealthcareServiceRead(d *schema.ResourceData, meta interface{}) if kind := resp.Kind; string(kind) != "" { d.Set("kind", kind) } - if properties := resp.Properties; properties != nil { - if config := properties.AccessPolicies; config != nil { - d.Set("access_policy_object_ids", flattenHealthcareAccessPolicies(config)) + if props := resp.Properties; props != nil { + if err := d.Set("access_policy_object_ids", flattenHealthcareAccessPolicies(props.AccessPolicies)); err != nil { + return fmt.Errorf("Error setting `access_policy_object_ids`: %+v", err) } - if config := properties.CosmosDbConfiguration; config != nil { - d.Set("cosmosdb_throughput", config.OfferThroughput) + + cosmosThroughput := 0 + if props.CosmosDbConfiguration != nil && props.CosmosDbConfiguration.OfferThroughput != nil { + cosmosThroughput = int(*props.CosmosDbConfiguration.OfferThroughput) } + d.Set("cosmosdb_throughput", cosmosThroughput) - if authConfig := properties.AuthenticationConfiguration; authConfig != nil { - if err := d.Set("authentication_configuration", flattenHealthcareAuthConfig(authConfig)); err != nil { - return fmt.Errorf("Error setting `authentication_configuration`: %+v", flattenHealthcareAuthConfig(authConfig)) - } + if err := d.Set("authentication_configuration", flattenHealthcareAuthConfig(props.AuthenticationConfiguration)); err != nil { + return fmt.Errorf("Error setting `authentication_configuration`: %+v", err) } - if corsConfig := properties.CorsConfiguration; corsConfig != nil { - if err := d.Set("cors_configuration", flattenHealthcareCorsConfig(corsConfig)); err != nil { - return fmt.Errorf("Error setting `cors_configuration`: %+v", flattenHealthcareCorsConfig(corsConfig)) - } + if err := d.Set("cors_configuration", flattenHealthcareCorsConfig(props.CorsConfiguration)); err != nil { + return fmt.Errorf("Error setting `cors_configuration`: %+v", err) } } @@ -348,12 +347,12 @@ func expandAzureRMhealthcareapisAuthentication(d *schema.ResourceData) *healthca authConfigAttr := authConfigRaw[0].(map[string]interface{}) authority := authConfigAttr["authority"].(string) audience := authConfigAttr["audience"].(string) - smart_proxy_enabled := authConfigAttr["smart_proxy_enabled"].(bool) + smartProxyEnabled := authConfigAttr["smart_proxy_enabled"].(bool) auth := &healthcareapis.ServiceAuthenticationConfigurationInfo{ Authority: &authority, Audience: &audience, - SmartProxyEnabled: &smart_proxy_enabled, + SmartProxyEnabled: &smartProxyEnabled, } return auth } @@ -374,44 +373,53 @@ func flattenHealthcareAccessPolicies(policies *[]healthcareapis.ServiceAccessPol return result } -func flattenHealthcareAuthConfig(authConfig *healthcareapis.ServiceAuthenticationConfigurationInfo) []interface{} { - authOutput := make([]interface{}, 0) +func flattenHealthcareAuthConfig(input *healthcareapis.ServiceAuthenticationConfigurationInfo) []interface{} { + if input == nil { + return []interface{}{} + } - output := make(map[string]interface{}) - if authConfig.Authority != nil { - output["authority"] = *authConfig.Authority + authority := "" + if input.Authority != nil { + authority = *input.Authority } - if authConfig.Audience != nil { - output["audience"] = *authConfig.Audience + audience := "" + if input.Audience != nil { + audience = *input.Audience } - if authConfig.SmartProxyEnabled != nil { - output["smart_proxy_enabled"] = *authConfig.SmartProxyEnabled + smartProxyEnabled := false + if input.SmartProxyEnabled != nil { + smartProxyEnabled = *input.SmartProxyEnabled + } + return []interface{}{ + map[string]interface{}{ + "audience": audience, + "authority": authority, + "smart_proxy_enabled": smartProxyEnabled, + }, } - authOutput = append(authOutput, output) - - return authOutput } -func flattenHealthcareCorsConfig(corsConfig *healthcareapis.ServiceCorsConfigurationInfo) []interface{} { - corsOutput := make([]interface{}, 0) - - output := make(map[string]interface{}) - if corsConfig.Origins != nil { - output["allowed_origins"] = *corsConfig.Origins - } - if corsConfig.Headers != nil { - output["allowed_headers"] = *corsConfig.Headers - } - if corsConfig.Methods != nil { - output["allowed_methods"] = *corsConfig.Methods +func flattenHealthcareCorsConfig(input *healthcareapis.ServiceCorsConfigurationInfo) []interface{} { + if input == nil { + return []interface{}{} } - if corsConfig.MaxAge != nil { - output["max_age_in_seconds"] = *corsConfig.MaxAge + + maxAge := 0 + if input.MaxAge != nil { + maxAge = int(*input.MaxAge) } - if corsConfig.AllowCredentials != nil { - output["allow_credentials"] = *corsConfig.AllowCredentials + allowCredentials := false + if input.AllowCredentials != nil { + allowCredentials = *input.AllowCredentials } - corsOutput = append(corsOutput, output) - return corsOutput + return []interface{}{ + map[string]interface{}{ + "allow_credentials": allowCredentials, + "allowed_headers": utils.FlattenStringSlice(input.Headers), + "allowed_methods": utils.FlattenStringSlice(input.Methods), + "allowed_origins": utils.FlattenStringSlice(input.Origins), + "max_age_in_seconds": maxAge, + }, + } } diff --git a/azurerm/internal/services/maintenance/maintenance_configuration_data_source.go b/azurerm/internal/services/maintenance/maintenance_configuration_data_source.go index 75e6ad0b0a50..87e6f48319b7 100644 --- a/azurerm/internal/services/maintenance/maintenance_configuration_data_source.go +++ b/azurerm/internal/services/maintenance/maintenance_configuration_data_source.go @@ -2,7 +2,6 @@ package maintenance import ( "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -55,11 +54,9 @@ func dataSourceArmMaintenanceConfigurationRead(d *schema.ResourceData, meta inte resp, err := client.Get(ctx, resGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - log.Printf("[INFO] Maintenance Configuration %q does not exist - removing from state", d.Id()) - d.SetId("") - return nil + return fmt.Errorf("Maintenance Configuration %q was not found in Resource Group %q", name, resGroup) } - return fmt.Errorf("failure retrieving MaintenanceConfiguration %q (Resource Group %q): %+v", name, resGroup, err) + return fmt.Errorf("retrieving Maintenance Configuration %q (Resource Group %q): %+v", name, resGroup, err) } if id := resp.ID; id != nil { diff --git a/azurerm/internal/services/msi/user_assigned_identity_data_source.go b/azurerm/internal/services/msi/user_assigned_identity_data_source.go index a5d2bd849c9e..4a3a2ea270a3 100644 --- a/azurerm/internal/services/msi/user_assigned_identity_data_source.go +++ b/azurerm/internal/services/msi/user_assigned_identity_data_source.go @@ -59,8 +59,7 @@ func dataSourceArmUserAssignedIdentityRead(d *schema.ResourceData, meta interfac resp, err := client.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil + return fmt.Errorf("User Assigned Identity %q was not found in Resource Group %q", name, resourceGroup) } return fmt.Errorf("Error making Read request on User Assigned Identity %q (Resource Group %q): %+v", name, resourceGroup, err) } diff --git a/azurerm/internal/services/network/firewall_data_source.go b/azurerm/internal/services/network/firewall_data_source.go index 9cc57a5e7c29..660ed9ea6eb6 100644 --- a/azurerm/internal/services/network/firewall_data_source.go +++ b/azurerm/internal/services/network/firewall_data_source.go @@ -2,7 +2,6 @@ package network import ( "fmt" - "log" "time" "github.com/hashicorp/terraform-plugin-sdk/helper/schema" @@ -77,9 +76,7 @@ func dataSourceArmFirewallRead(d *schema.ResourceData, meta interface{}) error { read, err := client.Get(ctx, resourceGroup, name) if err != nil { if utils.ResponseWasNotFound(read.Response) { - log.Printf("[DEBUG] Firewall %q was not found in Resource Group %q - removing from state!", name, resourceGroup) - d.SetId("") - return nil + return fmt.Errorf("Firewall %q was not found in Resource Group %q", name, resourceGroup) } return fmt.Errorf("Error making Read request on Azure Firewall %q (Resource Group %q): %+v", name, resourceGroup, err) diff --git a/azurerm/internal/services/network/private_endpoint_connection_data_source.go b/azurerm/internal/services/network/private_endpoint_connection_data_source.go index 45dab5aae4da..6fd9a9e23862 100644 --- a/azurerm/internal/services/network/private_endpoint_connection_data_source.go +++ b/azurerm/internal/services/network/private_endpoint_connection_data_source.go @@ -71,8 +71,7 @@ func dataSourceArmPrivateEndpointConnectionRead(d *schema.ResourceData, meta int resp, err := client.Get(ctx, resourceGroup, name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { - d.SetId("") - return nil + return fmt.Errorf("Private Endpoint %q was not found in Resource Group %q", name, resourceGroup) } return fmt.Errorf("Error reading Private Endpoint %q (Resource Group %q): %+v", name, resourceGroup, err) } diff --git a/scripts/run-gradually-deprecated.sh b/scripts/run-gradually-deprecated.sh index 15ff698c52ba..8de3012b2b5c 100755 --- a/scripts/run-gradually-deprecated.sh +++ b/scripts/run-gradually-deprecated.sh @@ -5,7 +5,7 @@ function checkForConditionalRun { then echo "Checking if this should be conditionally run.." result=$(git diff --name-only origin/master | grep azurerm/) - if [ "$result" = "" ]; + if [ "$result" == "" ]; then echo "No changes committed to ./azurerm - nothing to lint - exiting" exit 0 @@ -13,18 +13,12 @@ function checkForConditionalRun { fi } -function runDeprecatedFunctions { +function runGraduallyDeprecatedFunctions { echo "==> Checking for use of gradually deprecated functions..." - result=$(git diff --name-only origin/master | grep azurerm/) - if [ "$result" = "" ]; - then - # No changes committed to ./azurerm - so nothing to check - exit 0 - fi - + # require resources to be imported is now hard-coded on - but only checking for additions result=$(git diff origin/master | grep + | grep -R "features\.ShouldResourcesBeImported") - if [ "$result" = "" ]; + if [ "$result" != "" ]; then echo "The Feature Flag for 'ShouldResourcesBeImported' will be deprecated in the future" echo "and shouldn't be used in new resources - please remove new usages of the" @@ -36,8 +30,24 @@ function runDeprecatedFunctions { fi } +function runDeprecatedFunctions { + echo "==> Checking for use of deprecated functions..." + result=$(grep -Ril "d.setid(\"\")" ./azurerm/internal/services/**/data_source_*.go) + if [ "$result" != "" ]; + then + echo "Data Sources should return an error when a resource cannot be found rather than" + echo "setting an empty ID (by calling 'd.SetId("")'." + echo "" + echo "Please remove the references to 'd.SetId("") from the Data Sources listed below" + echo "and raise an error instead:" + echo "" + echo $result + fi +} + function main { checkForConditionalRun + runGraduallyDeprecatedFunctions runDeprecatedFunctions }