From 1003f42de1d96dac199c1dde1066fe24c030806d Mon Sep 17 00:00:00 2001 From: hvle Date: Sun, 16 May 2021 22:02:58 +0200 Subject: [PATCH] refactor: use parse.LinkedServiceID (#11740) Co-authored-by: Hong Viet Le --- ...ked_service_azure_blob_storage_resource.go | 27 ++++++++----------- ...inked_service_azure_databricks_resource.go | 25 +++++++---------- ...ked_service_azure_file_storage_resource.go | 27 ++++++++----------- ..._linked_service_azure_function_resource.go | 27 ++++++++----------- ...ed_service_azure_table_storage_resource.go | 27 ++++++++----------- ...actory_linked_service_cosmosdb_resource.go | 25 +++++++---------- ...service_data_lake_storage_gen2_resource.go | 25 +++++++---------- ...ctory_linked_service_key_vault_resource.go | 25 +++++++---------- ...a_factory_linked_service_mysql_resource.go | 25 +++++++---------- ...tory_linked_service_postgresql_resource.go | 25 +++++++---------- ...ta_factory_linked_service_sftp_resource.go | 25 +++++++---------- ...ata_factory_linked_service_web_resource.go | 25 +++++++---------- 12 files changed, 124 insertions(+), 184 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_blob_storage_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_blob_storage_resource.go index cd9d2e09d5df..92f14eb39b56 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_blob_storage_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_blob_storage_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -251,31 +252,28 @@ func resourceDataFactoryLinkedServiceBlobStorageRead(d *schema.ResourceData, met ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service BlobStorage %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service BlobStorage %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) blobStorage, ok := resp.Properties.AsAzureBlobStorageLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service BlobStorage %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureBlobStorage, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service BlobStorage %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureBlobStorage, *resp.Type) } if blobStorage != nil { @@ -297,7 +295,7 @@ func resourceDataFactoryLinkedServiceBlobStorageRead(d *schema.ResourceData, met annotations := flattenDataFactoryAnnotations(blobStorage.Annotations) if err := d.Set("annotations", annotations); err != nil { - return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure Blob Storage %q (Data Factory %q) / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure Blob Storage %q (Data Factory %q) / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } parameters := flattenDataFactoryParameters(blobStorage.Parameters) @@ -319,18 +317,15 @@ func resourceDataFactoryLinkedServiceBlobStorageDelete(d *schema.ResourceData, m ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service BlobStorage %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service BlobStorage %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_databricks_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_databricks_resource.go index 7acc29dc36db..9562954e231d 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_databricks_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_databricks_resource.go @@ -13,6 +13,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" databricksValidator "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/databricks/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -432,31 +433,28 @@ func resourceDataFactoryLinkedServiceDatabricksRead(d *schema.ResourceData, meta ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service Databricks %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service Databricks %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) databricks, ok := resp.Properties.AsAzureDatabricksLinkedService() if !ok { - return fmt.Errorf("classifiying Data Factory Linked Service Databricks %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureDatabricks, *resp.Type) + return fmt.Errorf("classifiying Data Factory Linked Service Databricks %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureDatabricks, *resp.Type) } // Check the properties and verify if authentication is set to MSI @@ -581,18 +579,15 @@ func resourceDataFactoryLinkedServiceDatabricksDelete(d *schema.ResourceData, me ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service Databricks %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service Databricks %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } return nil diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_file_storage_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_file_storage_resource.go index 6fa413141e39..8b61a5c026b6 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_file_storage_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_file_storage_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -239,31 +240,28 @@ func resourceDataFactoryLinkedServiceAzureFileStorageRead(d *schema.ResourceData ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service Azure File Storage %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service Azure File Storage %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) fileStorage, ok := resp.Properties.AsAzureFileStorageLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service Azure File Storage %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureFileStorage, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service Azure File Storage %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureFileStorage, *resp.Type) } d.Set("additional_properties", fileStorage.AdditionalProperties) @@ -279,7 +277,7 @@ func resourceDataFactoryLinkedServiceAzureFileStorageRead(d *schema.ResourceData annotations := flattenDataFactoryAnnotations(fileStorage.Annotations) if err := d.Set("annotations", annotations); err != nil { - return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure File Storage %q (Data Factory %q) / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure File Storage %q (Data Factory %q) / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } parameters := flattenDataFactoryParameters(fileStorage.Parameters) @@ -307,18 +305,15 @@ func resourceDataFactoryLinkedServiceAzureFileStorageDelete(d *schema.ResourceDa ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service Azure File Storage %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service Azure File Storage %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_function_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_function_resource.go index edcb4004344a..68f47564889e 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_function_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_function_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -182,31 +183,28 @@ func resourceDataFactoryLinkedServiceAzureFunctionRead(d *schema.ResourceData, m ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service Azure Function %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service Azure Function %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) azureFunction, ok := resp.Properties.AsAzureFunctionLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service Azure Function %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureFunction, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service Azure Function %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureFunction, *resp.Type) } d.Set("url", azureFunction.AzureFunctionLinkedServiceTypeProperties.FunctionAppURL) @@ -216,7 +214,7 @@ func resourceDataFactoryLinkedServiceAzureFunctionRead(d *schema.ResourceData, m annotations := flattenDataFactoryAnnotations(azureFunction.Annotations) if err := d.Set("annotations", annotations); err != nil { - return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure Function %q (Data Factory %q) / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure Function %q (Data Factory %q) / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } parameters := flattenDataFactoryParameters(azureFunction.Parameters) @@ -238,18 +236,15 @@ func resourceDataFactoryLinkedServiceAzureFunctionDelete(d *schema.ResourceData, ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service Azure Function %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service Azure Function %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_table_storage_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_table_storage_resource.go index c3e2846a05c5..d6f77a74ce81 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_azure_table_storage_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_azure_table_storage_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -175,31 +176,28 @@ func resourceDataFactoryLinkedServiceTableStorageRead(d *schema.ResourceData, me ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service TableStorage %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service TableStorage %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) tableStorage, ok := resp.Properties.AsAzureTableStorageLinkedService() if !ok { - return fmt.Errorf("Error classifying Data Factory Linked Service TableStorage %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureTableStorage, *resp.Type) + return fmt.Errorf("Error classifying Data Factory Linked Service TableStorage %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureTableStorage, *resp.Type) } d.Set("additional_properties", tableStorage.AdditionalProperties) @@ -207,7 +205,7 @@ func resourceDataFactoryLinkedServiceTableStorageRead(d *schema.ResourceData, me annotations := flattenDataFactoryAnnotations(tableStorage.Annotations) if err := d.Set("annotations", annotations); err != nil { - return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure Table Storage %q (Data Factory %q) / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error setting `annotations` for Data Factory Linked Service Azure Table Storage %q (Data Factory %q) / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } parameters := flattenDataFactoryParameters(tableStorage.Parameters) @@ -229,18 +227,15 @@ func resourceDataFactoryLinkedServiceTableStorageDelete(d *schema.ResourceData, ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service TableStorage %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service TableStorage %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_cosmosdb_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_cosmosdb_resource.go index 28d54a3d7493..fbf8c55ea99b 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_cosmosdb_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_cosmosdb_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -221,31 +222,28 @@ func resourceDataFactoryLinkedServiceCosmosDbRead(d *schema.ResourceData, meta i ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service CosmosDB %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service CosmosDB %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) cosmosdb, ok := resp.Properties.AsCosmosDbLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service CosmosDb %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeCosmosDb, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service CosmosDb %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeCosmosDb, *resp.Type) } d.Set("additional_properties", cosmosdb.AdditionalProperties) @@ -283,18 +281,15 @@ func resourceDataFactoryLinkedServiceCosmosDbDelete(d *schema.ResourceData, meta ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service CosmosDb %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service CosmosDb %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_data_lake_storage_gen2_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_data_lake_storage_gen2_resource.go index d42280d25c01..8890ec436005 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_data_lake_storage_gen2_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_data_lake_storage_gen2_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -222,32 +223,29 @@ func resourceDataFactoryLinkedServiceDataLakeStorageGen2Read(d *schema.ResourceD ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service Data Lake Storage Gen2 %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service Data Lake Storage Gen2 %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) dataLakeStorageGen2, ok := resp.Properties.AsAzureBlobFSLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service Data Lake Storage Gen2 %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureBlobFS, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service Data Lake Storage Gen2 %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureBlobFS, *resp.Type) } if dataLakeStorageGen2.Tenant != nil { @@ -295,18 +293,15 @@ func resourceDataFactoryLinkedServiceDataLakeStorageGen2Delete(d *schema.Resourc ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service Data Lake Storage Gen2 %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service Data Lake Storage Gen2 %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_key_vault_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_key_vault_resource.go index f85ffb66e3cd..887a60d279d9 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_key_vault_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_key_vault_resource.go @@ -11,6 +11,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" keyVaultParse "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/keyvault/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" @@ -187,31 +188,28 @@ func resourceDataFactoryLinkedServiceKeyVaultRead(d *schema.ResourceData, meta i ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service Key Vault %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service Key Vault %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) keyVault, ok := resp.Properties.AsAzureKeyVaultLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service Key Vault %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureKeyVault, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service Key Vault %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeAzureKeyVault, *resp.Type) } d.Set("additional_properties", keyVault.AdditionalProperties) @@ -262,18 +260,15 @@ func resourceDataFactoryLinkedServiceKeyVaultDelete(d *schema.ResourceData, meta ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service Key Vault %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service Key Vault %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_mysql_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_mysql_resource.go index 3160d8b7f86c..9f804d9b61a1 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_mysql_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_mysql_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -182,31 +183,28 @@ func resourceDataFactoryLinkedServiceMySQLRead(d *schema.ResourceData, meta inte ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service MySQL %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service MySQL %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) mysql, ok := resp.Properties.AsMySQLLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service MySQL %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeMySQL, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service MySQL %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeMySQL, *resp.Type) } d.Set("additional_properties", mysql.AdditionalProperties) @@ -236,18 +234,15 @@ func resourceDataFactoryLinkedServiceMySQLDelete(d *schema.ResourceData, meta in ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service MySQL %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service MySQL %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_postgresql_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_postgresql_resource.go index 7459e1a2dbbe..8ae82bc5d8b9 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_postgresql_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_postgresql_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -182,31 +183,28 @@ func resourceDataFactoryLinkedServicePostgreSQLRead(d *schema.ResourceData, meta ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service PostgreSQL %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service PostgreSQL %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) postgresql, ok := resp.Properties.AsPostgreSQLLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service PostgreSQL %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypePostgreSQL, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service PostgreSQL %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypePostgreSQL, *resp.Type) } d.Set("additional_properties", postgresql.AdditionalProperties) @@ -236,18 +234,15 @@ func resourceDataFactoryLinkedServicePostgreSQLDelete(d *schema.ResourceData, me ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service PostgreSQL %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service PostgreSQL %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_sftp_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_sftp_resource.go index 943039a84040..b3096a06024e 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_sftp_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_sftp_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -215,31 +216,28 @@ func resourceDataFactoryLinkedServiceSFTPRead(d *schema.ResourceData, meta inter ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service SFTP %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service SFTP %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) sftp, ok := resp.Properties.AsSftpServerLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service SFTP %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeSftp, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service SFTP %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeSftp, *resp.Type) } d.Set("authentication_type", sftp.AuthenticationType) @@ -274,18 +272,15 @@ func resourceDataFactoryLinkedServiceSFTPDelete(d *schema.ResourceData, meta int ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service SFTP %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service SFTP %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_web_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_web_resource.go index 35bec7d8b540..159d7b761d78 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_web_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_web_resource.go @@ -10,6 +10,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/azure" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/parse" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/services/datafactory/validate" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/tf/pluginsdk" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" @@ -216,31 +217,28 @@ func resourceDataFactoryLinkedServiceWebRead(d *schema.ResourceData, meta interf ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + resp, err := client.Get(ctx, id.ResourceGroup, id.FactoryName, id.Name, "") if err != nil { if utils.ResponseWasNotFound(resp.Response) { d.SetId("") return nil } - return fmt.Errorf("Error retrieving Data Factory Linked Service Web %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service Web %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } d.Set("name", resp.Name) - d.Set("resource_group_name", resourceGroup) - d.Set("data_factory_name", dataFactoryName) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) web, ok := resp.Properties.AsWebLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service Web %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeBasicLinkedServiceTypeWeb, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Linked Service Web %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeBasicLinkedServiceTypeWeb, *resp.Type) } isWebPropertiesLoaded := false @@ -289,18 +287,15 @@ func resourceDataFactoryLinkedServiceWebDelete(d *schema.ResourceData, meta inte ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) defer cancel() - id, err := azure.ParseAzureResourceID(d.Id()) + id, err := parse.LinkedServiceID(d.Id()) if err != nil { return err } - resourceGroup := id.ResourceGroup - dataFactoryName := id.Path["factories"] - name := id.Path["linkedservices"] - response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + response, err := client.Delete(ctx, id.ResourceGroup, id.FactoryName, id.Name) if err != nil { if !utils.ResponseWasNotFound(response) { - return fmt.Errorf("Error deleting Data Factory Linked Service Web %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service Web %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } }