From 95655d8f1783bd10c09d788df478386554d0f46a Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Thu, 17 Dec 2020 21:57:40 -0300 Subject: [PATCH 01/13] azurerm_data_factory_linked_service_synapse resource --- ...factory_linked_service_synapse_resource.go | 329 ++++++++++++++++++ ...ry_linked_service_synapse_resource_test.go | 221 ++++++++++++ .../services/datafactory/registration.go | 1 + ...ctory_linked_service_synapse.html.markdown | 137 ++++++++ 4 files changed, 688 insertions(+) create mode 100644 azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go create mode 100644 azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go create mode 100644 website/docs/r/data_factory_linked_service_synapse.html.markdown diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go new file mode 100644 index 000000000000..79634be2f65d --- /dev/null +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go @@ -0,0 +1,329 @@ +package datafactory + +import ( + "fmt" + "log" + "time" + + "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" + "github.com/hashicorp/terraform-plugin-sdk/helper/schema" + "github.com/hashicorp/terraform-plugin-sdk/helper/validation" + "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/helpers/validate" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/timeouts" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func resourceArmDataFactoryLinkedServiceSynapse() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDataFactoryLinkedServiceSynapseCreateUpdate, + Read: resourceArmDataFactoryLinkedServiceSynapseRead, + Update: resourceArmDataFactoryLinkedServiceSynapseCreateUpdate, + Delete: resourceArmDataFactoryLinkedServiceSynapseDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + Timeouts: &schema.ResourceTimeout{ + Create: schema.DefaultTimeout(30 * time.Minute), + Read: schema.DefaultTimeout(5 * time.Minute), + Update: schema.DefaultTimeout(30 * time.Minute), + Delete: schema.DefaultTimeout(30 * time.Minute), + }, + + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validateAzureRMDataFactoryLinkedServiceDatasetName, + }, + + "data_factory_name": { + Type: schema.TypeString, + Required: true, + ForceNew: true, + ValidateFunc: validate.DataFactoryName(), + }, + + // There's a bug in the Azure API where this is returned in lower-case + // BUG: https://github.com/Azure/azure-rest-api-specs/issues/5788 + "resource_group_name": azure.SchemaResourceGroupNameDiffSuppress(), + + "connection_string": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: azureRmDataFactoryLinkedServiceConnectionStringDiff, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "key_vault_password_reference": { + Type: schema.TypeList, + Optional: true, + MaxItems: 1, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "key_vault_linked_service_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "key_vault_password_secret_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + }, + }, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "integration_runtime_name": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringIsNotEmpty, + }, + + "parameters": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "annotations": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "additional_properties": { + Type: schema.TypeMap, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + }, + } +} + +func resourceArmDataFactoryLinkedServiceSynapseCreateUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataFactory.LinkedServiceClient + ctx, cancel := timeouts.ForCreateUpdate(meta.(*clients.Client).StopContext, d) + defer cancel() + + name := d.Get("name").(string) + dataFactoryName := d.Get("data_factory_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + if d.IsNewResource() { + existing, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + if err != nil { + if !utils.ResponseWasNotFound(existing.Response) { + return fmt.Errorf("Error checking for presence of existing Data Factory Linked Service Synapse%q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_data_factory_linked_service_synapse", *existing.ID) + } + } + + passwordReferenceProps := d.Get("key_vault_password_reference").([]interface{}) + + sqlDWProperties := &datafactory.AzureSQLDWLinkedServiceTypeProperties{ + ConnectionString: d.Get("connection_string").(string), + Password: expandAzureKeyVaultSecretReference(passwordReferenceProps), + } + + description := d.Get("description").(string) + + sqlDWLinkedService := &datafactory.AzureSQLDWLinkedService{ + Description: &description, + AzureSQLDWLinkedServiceTypeProperties: sqlDWProperties, + Type: datafactory.TypeAzureSQLDW, + } + + if v, ok := d.GetOk("parameters"); ok { + sqlDWLinkedService.Parameters = expandDataFactoryParameters(v.(map[string]interface{})) + } + + if v, ok := d.GetOk("integration_runtime_name"); ok { + sqlDWLinkedService.ConnectVia = expandDataFactoryLinkedServiceIntegrationRuntime(v.(string)) + } + + if v, ok := d.GetOk("additional_properties"); ok { + sqlDWLinkedService.AdditionalProperties = v.(map[string]interface{}) + } + + if v, ok := d.GetOk("annotations"); ok { + annotations := v.([]interface{}) + sqlDWLinkedService.Annotations = &annotations + } + + linkedService := datafactory.LinkedServiceResource{ + Properties: sqlDWLinkedService, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, dataFactoryName, name, linkedService, ""); err != nil { + return fmt.Errorf("Error creating/updating Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + if err != nil { + return fmt.Errorf("Error retrieving Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + + if resp.ID == nil { + return fmt.Errorf("Cannot read Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + + d.SetId(*resp.ID) + + return resourceArmDataFactoryLinkedServiceSynapseRead(d, meta) +} + +func resourceArmDataFactoryLinkedServiceSynapseRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataFactory.LinkedServiceClient + ctx, cancel := timeouts.ForRead(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(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, "") + if err != nil { + if utils.ResponseWasNotFound(resp.Response) { + d.SetId("") + return nil + } + + return fmt.Errorf("Error retrieving Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("data_factory_name", dataFactoryName) + + sqlDW, ok := resp.Properties.AsAzureSQLDWLinkedService() + if !ok { + return fmt.Errorf("Error classifiying Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeAzureSQLDW, *resp.Type) + } + + d.Set("additional_properties", sqlDW.AdditionalProperties) + d.Set("description", sqlDW.Description) + + annotations := flattenDataFactoryAnnotations(sqlDW.Annotations) + if err := d.Set("annotations", annotations); err != nil { + return fmt.Errorf("Error setting `annotations`: %+v", err) + } + + parameters := flattenDataFactoryParameters(sqlDW.Parameters) + if err := d.Set("parameters", parameters); err != nil { + return fmt.Errorf("Error setting `parameters`: %+v", err) + } + + if connectVia := sqlDW.ConnectVia; connectVia != nil { + if connectVia.ReferenceName != nil { + d.Set("integration_runtime_name", connectVia.ReferenceName) + } + } + + if properties := sqlDW.AzureSQLDWLinkedServiceTypeProperties; properties != nil { + if properties.ConnectionString != nil { + if val, ok := properties.ConnectionString.(string); ok { + d.Set("connection_string", val) + } else { + d.Set("connection_string", "") + log.Printf("[DEBUG] Skipping connection string %q since it's not a string", val) + } + } + + if err := d.Set("key_vault_password_reference", flattenAzureKeyVaultSecretReference(properties.Password)); err != nil { + return fmt.Errorf("setting `custom_parameters`: %+v", err) + } + } + + return nil +} + +func resourceArmDataFactoryLinkedServiceSynapseDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*clients.Client).DataFactory.LinkedServiceClient + ctx, cancel := timeouts.ForDelete(meta.(*clients.Client).StopContext, d) + defer cancel() + + id, err := azure.ParseAzureResourceID(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) + if err != nil { + if !utils.ResponseWasNotFound(response) { + return fmt.Errorf("Error deleting Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + } + + return nil +} + +func expandAzureKeyVaultSecretReference(input []interface{}) *datafactory.AzureKeyVaultSecretReference { + if len(input) == 0 || input[0] == nil { + return nil + } + + config := input[0].(map[string]interface{}) + + keyVaultLinkedServiceName := config["key_vault_linked_service_name"].(string) + keyVaultPasswordSecretName := config["key_vault_password_secret_name"].(string) + linkedServiceType := "LinkedServiceReference" + + return &datafactory.AzureKeyVaultSecretReference{ + SecretName: keyVaultPasswordSecretName, + Store: &datafactory.LinkedServiceReference{ + Type: &linkedServiceType, + ReferenceName: &keyVaultLinkedServiceName, + }, + } +} + +func flattenAzureKeyVaultSecretReference(secretReference *datafactory.AzureKeyVaultSecretReference) []interface{} { + if secretReference == nil { + return nil + } + + parameters := make(map[string]interface{}) + + if store := secretReference.Store; store != nil { + if store.ReferenceName != nil { + parameters["key_vault_linked_service_name"] = *store.ReferenceName + } + } + + if secretName := secretReference.SecretName; secretName != nil { + parameters["key_vault_password_secret_name"] = secretName + } + + return []interface{}{parameters} +} diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go new file mode 100644 index 000000000000..b0854770edd2 --- /dev/null +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go @@ -0,0 +1,221 @@ +package datafactory_test + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform-plugin-sdk/helper/resource" + "github.com/hashicorp/terraform-plugin-sdk/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/acceptance" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/internal/clients" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" +) + +func TestAccAzureRMDataFactoryLinkedServiceSynapse_ConnectionString(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_synapse", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceSynapseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataFactoryLinkedServiceSynapse_connection_string(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryLinkedServiceSynapseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "connection_string"), + ), + }, + data.ImportStep(), + }, + }) +} + +func TestAccAzureRMDataFactoryLinkedServiceSynapse_KeyVaultReference(t *testing.T) { + data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_synapse", "test") + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { acceptance.PreCheck(t) }, + Providers: acceptance.SupportedProviders, + CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceSynapseDestroy, + Steps: []resource.TestStep{ + { + Config: testAccAzureRMDataFactoryLinkedServiceSynapse_key_vault_reference(data), + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryLinkedServiceSynapseExists(data.ResourceName), + resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), + resource.TestCheckResourceAttrSet(data.ResourceName, "connection_string"), + resource.TestCheckResourceAttrSet(data.ResourceName, "key_vault_password_reference.0.key_vault_linked_service_name"), + resource.TestCheckResourceAttr(data.ResourceName, "key_vault_password_reference.0.key_vault_password_secret_name", "secret"), + ), + }, + data.ImportStep(), + }, + }) +} + +func testCheckAzureRMDataFactoryLinkedServiceSynapseExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DataFactory.LinkedServiceClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + // Ensure we have enough information in state to look up in API + rs, ok := s.RootModule().Resources[name] + if !ok { + return fmt.Errorf("Not found: %s", name) + } + + name := rs.Primary.Attributes["name"] + resourceGroup, hasResourceGroup := rs.Primary.Attributes["resource_group_name"] + dataFactoryName := rs.Primary.Attributes["data_factory_name"] + if !hasResourceGroup { + return fmt.Errorf("Bad: no resource group found in state for Data Factory: %s", name) + } + + resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + if err != nil { + return fmt.Errorf("Bad: Get on dataFactoryLinkedServiceClient: %+v", err) + } + + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Data Factory Linked Service Synapse %q (data factory name: %q / resource group: %q) does not exist", name, dataFactoryName, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMDataFactoryLinkedServiceSynapseDestroy(s *terraform.State) error { + client := acceptance.AzureProvider.Meta().(*clients.Client).DataFactory.LinkedServiceClient + ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_data_factory_linked_service_synapse" { + continue + } + + name := rs.Primary.Attributes["name"] + resourceGroup := rs.Primary.Attributes["resource_group_name"] + dataFactoryName := rs.Primary.Attributes["data_factory_name"] + + resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + if err != nil { + return nil + } + + if resp.StatusCode != http.StatusNotFound { + return fmt.Errorf("Data Factory Linked Service Synapse still exists:\n%#v", resp.Properties) + } + } + + return nil +} + +func testAccAzureRMDataFactoryLinkedServiceSynapse_connection_string(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-df-%d" + location = "%s" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdf%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_data_factory_linked_service_synapse" "test" { + name = "acctestlssql%d" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" + + annotations = ["test1", "test2", "test3"] + description = "test description" + + parameters = { + foo = "test1" + bar = "test2" + } + + additional_properties = { + foo = "test1" + bar = "test2" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} + +func testAccAzureRMDataFactoryLinkedServiceSynapse_key_vault_reference(data acceptance.TestData) string { + return fmt.Sprintf(` +provider "azurerm" { + features {} +} + +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "test" { + name = "acctestRG-df-%d" + location = "%s" +} + +resource "azurerm_key_vault" "test" { + name = "acctkv%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "standard" +} + +resource "azurerm_data_factory" "test" { + name = "acctestdf%d" + location = azurerm_resource_group.test.location + resource_group_name = azurerm_resource_group.test.name +} + +resource "azurerm_data_factory_linked_service_key_vault" "test" { + name = "linkkv" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + key_vault_id = azurerm_key_vault.test.id +} + +resource "azurerm_data_factory_linked_service_synapse" "test" { + name = "linksynapse" + resource_group_name = azurerm_resource_group.test.name + data_factory_name = azurerm_data_factory.test.name + + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" + key_vault_password_reference { + key_vault_linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name + key_vault_password_secret_name = "secret" + } + + annotations = ["test1", "test2", "test3"] + description = "test description" + + parameters = { + foo = "test1" + bar = "test2" + } + + additional_properties = { + foo = "test1" + bar = "test2" + } +} +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +} diff --git a/azurerm/internal/services/datafactory/registration.go b/azurerm/internal/services/datafactory/registration.go index 57c431e172a7..f71d9a5a528e 100644 --- a/azurerm/internal/services/datafactory/registration.go +++ b/azurerm/internal/services/datafactory/registration.go @@ -50,6 +50,7 @@ func (r Registration) SupportedResources() map[string]*schema.Resource { "azurerm_data_factory_linked_service_postgresql": resourceArmDataFactoryLinkedServicePostgreSQL(), "azurerm_data_factory_linked_service_sftp": resourceArmDataFactoryLinkedServiceSFTP(), "azurerm_data_factory_linked_service_sql_server": resourceArmDataFactoryLinkedServiceSQLServer(), + "azurerm_data_factory_linked_service_synapse": resourceArmDataFactoryLinkedServiceSynapse(), "azurerm_data_factory_linked_service_web": resourceArmDataFactoryLinkedServiceWeb(), "azurerm_data_factory_pipeline": resourceArmDataFactoryPipeline(), "azurerm_data_factory_trigger_schedule": resourceArmDataFactoryTriggerSchedule(), diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown new file mode 100644 index 000000000000..e1408682fb72 --- /dev/null +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -0,0 +1,137 @@ +--- +subcategory: "Data Factory" +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_factory_linked_service_synapse" +description: |- + Manages a Linked Service (connection) between Synapse and Azure Data Factory. +--- + +# azurerm_data_factory_linked_service_synapse + +Manages a Linked Service (connection) between Synapse and Azure Data Factory. + +~> **Note:** All arguments including the client secret will be stored in the raw state as plain-text. [Read more about sensitive data in state](/docs/state/sensitive-data.html). + +## Example Usage + +```hcl +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "northeurope" +} + +resource "azurerm_data_factory" "example" { + name = "example" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_data_factory_linked_service_synapse" "example" { + name = "example" + resource_group_name = azurerm_resource_group.example.name + data_factory_name = azurerm_data_factory.example.name + + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" +} +``` + +## Example Usage with Password in Key Vault + +```hcl +data "azurerm_client_config" "current" {} + +resource "azurerm_resource_group" "example" { + name = "example-resources" + location = "northeurope" +} + +resource "azurerm_key_vault" "example" { + name = "example" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "standard" +} + +resource "azurerm_data_factory" "example" { + name = "example" + location = azurerm_resource_group.example.location + resource_group_name = azurerm_resource_group.example.name +} + +resource "azurerm_data_factory_linked_service_key_vault" "example" { + name = "kvlink" + resource_group_name = azurerm_resource_group.example.name + data_factory_name = azurerm_data_factory.example.name + key_vault_id = azurerm_key_vault.example.id +} + +resource "azurerm_data_factory_linked_service_synapse" "example" { + name = "example" + resource_group_name = azurerm_resource_group.example.name + data_factory_name = azurerm_data_factory.example.name + + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" + key_vault_password_reference { + key_vault_linked_service_name = azurerm_data_factory_linked_service_key_vault.example.name + key_vault_password_secret_name = "secret" + } +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Data Factory Linked Service Synapse. Changing this forces a new resource to be created. Must be globally unique. See the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/data-factory/naming-rules) for all restrictions. + +* `resource_group_name` - (Required) The name of the resource group in which to create the Data Factory Linked Service Synapse. Changing this forces a new resource + +* `data_factory_name` - (Required) The Data Factory name in which to associate the Linked Service with. Changing this forces a new resource. + +* `connection_string` - (Required) The connection string in which to authenticate with the Synapse. + +* `key_vault_password_reference` - (Optional) A `key_vault_password_reference` block as defined below. Use this argument to store Synapse password in an existing Key Vault. It needs an existing Data Factory linked service to Key Vault. + +* `description` - (Optional) The description for the Data Factory Linked Service Synapse. + +* `integration_runtime_name` - (Optional) The integration runtime reference to associate with the Data Factory Linked Service Synapse. + +* `annotations` - (Optional) List of tags that can be used for describing the Data Factory Linked Service Synapse. + +* `parameters` - (Optional) A map of parameters to associate with the Data Factory Linked Service Synapse. + +* `additional_properties` - (Optional) A map of additional properties to associate with the Data Factory Linked Service Synapse. + +--- + +A `key_vault_password_reference` block supports the following: + +* `key_vault_linked_service_name` - (Required) Specifies the existing Data Factory linked service to Key Vault. + +* `key_vault_password_secret_name` - (Required) Specifies the secret name in Azure Key Vault that stores Synapse password. + +--- + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Data Factory Synapse Linked Service. + +## Timeouts + +The `timeouts` block allows you to specify [timeouts](https://www.terraform.io/docs/configuration/resources.html#timeouts) for certain actions: + +* `create` - (Defaults to 30 minutes) Used when creating the Data Factory Synapse Linked Service. +* `update` - (Defaults to 30 minutes) Used when updating the Data Factory Synapse Linked Service. +* `read` - (Defaults to 5 minutes) Used when retrieving the Data Factory Synapse Linked Service. +* `delete` - (Defaults to 30 minutes) Used when deleting the Data Factory Synapse Linked Service. + +## Import + +Data Factory Synapse Linked Service's can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_data_factory_linked_service_synapse.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.DataFactory/factories/example/linkedservices/example +``` From 3c350b86277b5e66fa71a4523d626f9e148ab97e Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Thu, 17 Dec 2020 22:09:49 -0300 Subject: [PATCH 02/13] fixing docs fmt --- .../data_factory_linked_service_synapse_resource_test.go | 4 ++-- .../docs/r/data_factory_linked_service_synapse.html.markdown | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go index b0854770edd2..3e25f64b5e68 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go @@ -137,7 +137,7 @@ resource "azurerm_data_factory" "test" { } resource "azurerm_data_factory_linked_service_synapse" "test" { - name = "acctestlssql%d" + name = "linksynapse" resource_group_name = azurerm_resource_group.test.name data_factory_name = azurerm_data_factory.test.name @@ -156,7 +156,7 @@ resource "azurerm_data_factory_linked_service_synapse" "test" { bar = "test2" } } -`, data.RandomInteger, data.Locations.Primary, data.RandomInteger, data.RandomInteger) +`, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } func testAccAzureRMDataFactoryLinkedServiceSynapse_key_vault_reference(data acceptance.TestData) string { diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown index e1408682fb72..ad276d88e14d 100644 --- a/website/docs/r/data_factory_linked_service_synapse.html.markdown +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -31,7 +31,7 @@ resource "azurerm_data_factory_linked_service_synapse" "example" { resource_group_name = azurerm_resource_group.example.name data_factory_name = azurerm_data_factory.example.name - connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" } ``` @@ -71,7 +71,7 @@ resource "azurerm_data_factory_linked_service_synapse" "example" { resource_group_name = azurerm_resource_group.example.name data_factory_name = azurerm_data_factory.example.name - connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" key_vault_password_reference { key_vault_linked_service_name = azurerm_data_factory_linked_service_key_vault.example.name key_vault_password_secret_name = "secret" From e578c554bcaaa4e0af0110c1a38502ace021480d Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Thu, 17 Dec 2020 22:20:44 -0300 Subject: [PATCH 03/13] fixing go fmt --- ...ry_linked_service_synapse_resource_test.go | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go index 3e25f64b5e68..fff6e822176d 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go @@ -141,10 +141,10 @@ resource "azurerm_data_factory_linked_service_synapse" "test" { resource_group_name = azurerm_resource_group.test.name data_factory_name = azurerm_data_factory.test.name - connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" - - annotations = ["test1", "test2", "test3"] - description = "test description" + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test" + + annotations = ["test1", "test2", "test3"] + description = "test description" parameters = { foo = "test1" @@ -197,15 +197,15 @@ resource "azurerm_data_factory_linked_service_synapse" "test" { name = "linksynapse" resource_group_name = azurerm_resource_group.test.name data_factory_name = azurerm_data_factory.test.name - - connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" + + connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" key_vault_password_reference { - key_vault_linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name - key_vault_password_secret_name = "secret" + key_vault_linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name + key_vault_password_secret_name = "secret" } - annotations = ["test1", "test2", "test3"] - description = "test description" + annotations = ["test1", "test2", "test3"] + description = "test description" parameters = { foo = "test1" From e29bfce779b0343d1618a05e2fcdb5acb5e19d27 Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Fri, 18 Dec 2020 07:42:45 -0300 Subject: [PATCH 04/13] refactoring linked service docs --- ...data_factory_linked_service_synapse.html.markdown | 12 +++++++----- 1 file changed, 7 insertions(+), 5 deletions(-) diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown index ad276d88e14d..f4ad82a0db1b 100644 --- a/website/docs/r/data_factory_linked_service_synapse.html.markdown +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -81,7 +81,7 @@ resource "azurerm_data_factory_linked_service_synapse" "example" { ## Argument Reference -The following arguments are supported: +The following supported arguments are common across all Azure Data Factory Linked Services: * `name` - (Required) Specifies the name of the Data Factory Linked Service Synapse. Changing this forces a new resource to be created. Must be globally unique. See the [Microsoft documentation](https://docs.microsoft.com/en-us/azure/data-factory/naming-rules) for all restrictions. @@ -89,10 +89,6 @@ The following arguments are supported: * `data_factory_name` - (Required) The Data Factory name in which to associate the Linked Service with. Changing this forces a new resource. -* `connection_string` - (Required) The connection string in which to authenticate with the Synapse. - -* `key_vault_password_reference` - (Optional) A `key_vault_password_reference` block as defined below. Use this argument to store Synapse password in an existing Key Vault. It needs an existing Data Factory linked service to Key Vault. - * `description` - (Optional) The description for the Data Factory Linked Service Synapse. * `integration_runtime_name` - (Optional) The integration runtime reference to associate with the Data Factory Linked Service Synapse. @@ -103,6 +99,12 @@ The following arguments are supported: * `additional_properties` - (Optional) A map of additional properties to associate with the Data Factory Linked Service Synapse. +The following supported arguments are specific to Azure File Storage Linked Service: + +* `connection_string` - (Required) The connection string in which to authenticate with the Synapse. + +* `key_vault_password_reference` - (Optional) A `key_vault_password_reference` block as defined below. Use this argument to store Synapse password in an existing Key Vault. It needs an existing Data Factory linked service to Key Vault. + --- A `key_vault_password_reference` block supports the following: From b0230de6d5bcc6a84c182a33eade1c3f19866d40 Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Fri, 18 Dec 2020 07:43:29 -0300 Subject: [PATCH 05/13] refactoring linked service docs --- .../docs/r/data_factory_linked_service_synapse.html.markdown | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown index f4ad82a0db1b..e096d7429baf 100644 --- a/website/docs/r/data_factory_linked_service_synapse.html.markdown +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -99,7 +99,7 @@ The following supported arguments are common across all Azure Data Factory Linke * `additional_properties` - (Optional) A map of additional properties to associate with the Data Factory Linked Service Synapse. -The following supported arguments are specific to Azure File Storage Linked Service: +The following supported arguments are specific to Data Factory Synapse Linked Service: * `connection_string` - (Required) The connection string in which to authenticate with the Synapse. From f06d23614bd31987f3abddf9f6d59578653d903c Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Fri, 18 Dec 2020 07:44:38 -0300 Subject: [PATCH 06/13] improving names on linked svc doc --- .../docs/r/data_factory_linked_service_synapse.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown index e096d7429baf..e3d0fb0a7126 100644 --- a/website/docs/r/data_factory_linked_service_synapse.html.markdown +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -103,13 +103,13 @@ The following supported arguments are specific to Data Factory Synapse Linked Se * `connection_string` - (Required) The connection string in which to authenticate with the Synapse. -* `key_vault_password_reference` - (Optional) A `key_vault_password_reference` block as defined below. Use this argument to store Synapse password in an existing Key Vault. It needs an existing Data Factory linked service to Key Vault. +* `key_vault_password_reference` - (Optional) A `key_vault_password_reference` block as defined below. Use this argument to store Synapse password in an existing Key Vault. It needs an existing Key Vault Data Factory Linked Service. --- A `key_vault_password_reference` block supports the following: -* `key_vault_linked_service_name` - (Required) Specifies the existing Data Factory linked service to Key Vault. +* `key_vault_linked_service_name` - (Required) Specifies the name of an existing Key Vault Data Factory Linked Service. * `key_vault_password_secret_name` - (Required) Specifies the secret name in Azure Key Vault that stores Synapse password. From 895a7c0be6fae3fd07cabbe20a85f48acc66ba3e Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Sun, 20 Dec 2020 12:04:55 -0300 Subject: [PATCH 07/13] refactoring interface names --- .../data_factory_linked_service_synapse_resource.go | 12 ++++++------ ...a_factory_linked_service_synapse_resource_test.go | 8 ++++---- ...data_factory_linked_service_synapse.html.markdown | 8 ++++---- 3 files changed, 14 insertions(+), 14 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go index 79634be2f65d..cad718b8e02c 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go @@ -66,13 +66,13 @@ func resourceArmDataFactoryLinkedServiceSynapse() *schema.Resource { MaxItems: 1, Elem: &schema.Resource{ Schema: map[string]*schema.Schema{ - "key_vault_linked_service_name": { + "linked_service_name": { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringIsNotEmpty, }, - "key_vault_password_secret_name": { + "password_secret_name": { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringIsNotEmpty, @@ -295,8 +295,8 @@ func expandAzureKeyVaultSecretReference(input []interface{}) *datafactory.AzureK config := input[0].(map[string]interface{}) - keyVaultLinkedServiceName := config["key_vault_linked_service_name"].(string) - keyVaultPasswordSecretName := config["key_vault_password_secret_name"].(string) + keyVaultLinkedServiceName := config["linked_service_name"].(string) + keyVaultPasswordSecretName := config["password_secret_name"].(string) linkedServiceType := "LinkedServiceReference" return &datafactory.AzureKeyVaultSecretReference{ @@ -317,12 +317,12 @@ func flattenAzureKeyVaultSecretReference(secretReference *datafactory.AzureKeyVa if store := secretReference.Store; store != nil { if store.ReferenceName != nil { - parameters["key_vault_linked_service_name"] = *store.ReferenceName + parameters["linked_service_name"] = *store.ReferenceName } } if secretName := secretReference.SecretName; secretName != nil { - parameters["key_vault_password_secret_name"] = secretName + parameters["password_secret_name"] = secretName } return []interface{}{parameters} diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go index fff6e822176d..2d04609e7a74 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go @@ -53,8 +53,8 @@ func TestAccAzureRMDataFactoryLinkedServiceSynapse_KeyVaultReference(t *testing. resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), resource.TestCheckResourceAttrSet(data.ResourceName, "connection_string"), - resource.TestCheckResourceAttrSet(data.ResourceName, "key_vault_password_reference.0.key_vault_linked_service_name"), - resource.TestCheckResourceAttr(data.ResourceName, "key_vault_password_reference.0.key_vault_password_secret_name", "secret"), + resource.TestCheckResourceAttrSet(data.ResourceName, "key_vault_password_reference.0.linked_service_name"), + resource.TestCheckResourceAttr(data.ResourceName, "key_vault_password_reference.0.password_secret_name", "secret"), ), }, data.ImportStep(), @@ -200,8 +200,8 @@ resource "azurerm_data_factory_linked_service_synapse" "test" { connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" key_vault_password_reference { - key_vault_linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name - key_vault_password_secret_name = "secret" + linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name + password_secret_name = "secret" } annotations = ["test1", "test2", "test3"] diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown index e3d0fb0a7126..c5d2fc7b8b54 100644 --- a/website/docs/r/data_factory_linked_service_synapse.html.markdown +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -73,8 +73,8 @@ resource "azurerm_data_factory_linked_service_synapse" "example" { connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" key_vault_password_reference { - key_vault_linked_service_name = azurerm_data_factory_linked_service_key_vault.example.name - key_vault_password_secret_name = "secret" + linked_service_name = azurerm_data_factory_linked_service_key_vault.example.name + password_secret_name = "secret" } } ``` @@ -109,9 +109,9 @@ The following supported arguments are specific to Data Factory Synapse Linked Se A `key_vault_password_reference` block supports the following: -* `key_vault_linked_service_name` - (Required) Specifies the name of an existing Key Vault Data Factory Linked Service. +* `linked_service_name` - (Required) Specifies the name of an existing Key Vault Data Factory Linked Service. -* `key_vault_password_secret_name` - (Required) Specifies the secret name in Azure Key Vault that stores Synapse password. +* `password_secret_name` - (Required) Specifies the secret name in Azure Key Vault that stores Synapse password. --- From 1d8033e492d5d0ba3136fcf5ed8eb45810054a55 Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Sun, 20 Dec 2020 13:29:08 -0300 Subject: [PATCH 08/13] refactoring internal methods --- .../services/datafactory/data_factory.go | 38 +++++++++++++++ ...factory_linked_service_synapse_resource.go | 48 ++----------------- 2 files changed, 42 insertions(+), 44 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory.go b/azurerm/internal/services/datafactory/data_factory.go index d93c0d08754a..c967bd2003b5 100644 --- a/azurerm/internal/services/datafactory/data_factory.go +++ b/azurerm/internal/services/datafactory/data_factory.go @@ -227,3 +227,41 @@ func serializeDataFactoryPipelineActivities(activities *[]datafactory.BasicActiv func suppressJsonOrderingDifference(_, old, new string, _ *schema.ResourceData) bool { return utils.NormalizeJson(old) == utils.NormalizeJson(new) } + +func expandAzureKeyVaultPasswordReference(input []interface{}) *datafactory.AzureKeyVaultSecretReference { + if len(input) == 0 || input[0] == nil { + return nil + } + + config := input[0].(map[string]interface{}) + + keyVaultLinkedServiceName := config["linked_service_name"].(string) + keyVaultPasswordSecretName := config["password_secret_name"].(string) + linkedServiceType := "LinkedServiceReference" + + return &datafactory.AzureKeyVaultSecretReference{ + SecretName: keyVaultPasswordSecretName, + Store: &datafactory.LinkedServiceReference{ + Type: &linkedServiceType, + ReferenceName: &keyVaultLinkedServiceName, + }, + } +} + +func flattenAzureKeyVaultPasswordReference(secretReference *datafactory.AzureKeyVaultSecretReference) []interface{} { + if secretReference == nil { + return nil + } + + parameters := make(map[string]interface{}) + + if store := secretReference.Store; store != nil { + if store.ReferenceName != nil { + parameters["linked_service_name"] = *store.ReferenceName + } + } + + parameters["password_secret_name"] = secretReference.SecretName + + return []interface{}{parameters} +} diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go index cad718b8e02c..1bf002a5418b 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go @@ -142,11 +142,11 @@ func resourceArmDataFactoryLinkedServiceSynapseCreateUpdate(d *schema.ResourceDa } } - passwordReferenceProps := d.Get("key_vault_password_reference").([]interface{}) + passwordReference := d.Get("key_vault_password_reference").([]interface{}) sqlDWProperties := &datafactory.AzureSQLDWLinkedServiceTypeProperties{ ConnectionString: d.Get("connection_string").(string), - Password: expandAzureKeyVaultSecretReference(passwordReferenceProps), + Password: expandAzureKeyVaultPasswordReference(passwordReference), } description := d.Get("description").(string) @@ -257,8 +257,8 @@ func resourceArmDataFactoryLinkedServiceSynapseRead(d *schema.ResourceData, meta } } - if err := d.Set("key_vault_password_reference", flattenAzureKeyVaultSecretReference(properties.Password)); err != nil { - return fmt.Errorf("setting `custom_parameters`: %+v", err) + if err := d.Set("key_vault_password_reference", flattenAzureKeyVaultPasswordReference(properties.Password)); err != nil { + return fmt.Errorf("setting `key_vault_password_reference`: %+v", err) } } @@ -287,43 +287,3 @@ func resourceArmDataFactoryLinkedServiceSynapseDelete(d *schema.ResourceData, me return nil } - -func expandAzureKeyVaultSecretReference(input []interface{}) *datafactory.AzureKeyVaultSecretReference { - if len(input) == 0 || input[0] == nil { - return nil - } - - config := input[0].(map[string]interface{}) - - keyVaultLinkedServiceName := config["linked_service_name"].(string) - keyVaultPasswordSecretName := config["password_secret_name"].(string) - linkedServiceType := "LinkedServiceReference" - - return &datafactory.AzureKeyVaultSecretReference{ - SecretName: keyVaultPasswordSecretName, - Store: &datafactory.LinkedServiceReference{ - Type: &linkedServiceType, - ReferenceName: &keyVaultLinkedServiceName, - }, - } -} - -func flattenAzureKeyVaultSecretReference(secretReference *datafactory.AzureKeyVaultSecretReference) []interface{} { - if secretReference == nil { - return nil - } - - parameters := make(map[string]interface{}) - - if store := secretReference.Store; store != nil { - if store.ReferenceName != nil { - parameters["linked_service_name"] = *store.ReferenceName - } - } - - if secretName := secretReference.SecretName; secretName != nil { - parameters["password_secret_name"] = secretName - } - - return []interface{}{parameters} -} From 250335685c136d913c2d4a531f80a05ef433191b Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Thu, 31 Dec 2020 17:29:14 -0300 Subject: [PATCH 09/13] refactoring test names --- ...ry_linked_service_synapse_resource_test.go | 24 +++++++++---------- 1 file changed, 12 insertions(+), 12 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go index 2d04609e7a74..26f474597f41 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go @@ -12,18 +12,18 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) -func TestAccAzureRMDataFactoryLinkedServiceSynapse_ConnectionString(t *testing.T) { +func TestAccDataFactoryLinkedServiceSynapse_ConnectionString(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_synapse", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceSynapseDestroy, + CheckDestroy: testCheckDataFactoryLinkedServiceSynapseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataFactoryLinkedServiceSynapse_connection_string(data), + Config: testAccDataFactoryLinkedServiceSynapse_connection_string(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceSynapseExists(data.ResourceName), + testCheckDataFactoryLinkedServiceSynapseExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), @@ -36,18 +36,18 @@ func TestAccAzureRMDataFactoryLinkedServiceSynapse_ConnectionString(t *testing.T }) } -func TestAccAzureRMDataFactoryLinkedServiceSynapse_KeyVaultReference(t *testing.T) { +func TestAccDataFactoryLinkedServiceSynapse_KeyVaultReference(t *testing.T) { data := acceptance.BuildTestData(t, "azurerm_data_factory_linked_service_synapse", "test") resource.ParallelTest(t, resource.TestCase{ PreCheck: func() { acceptance.PreCheck(t) }, Providers: acceptance.SupportedProviders, - CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceSynapseDestroy, + CheckDestroy: testCheckDataFactoryLinkedServiceSynapseDestroy, Steps: []resource.TestStep{ { - Config: testAccAzureRMDataFactoryLinkedServiceSynapse_key_vault_reference(data), + Config: testAccDataFactoryLinkedServiceSynapse_key_vault_reference(data), Check: resource.ComposeTestCheckFunc( - testCheckAzureRMDataFactoryLinkedServiceSynapseExists(data.ResourceName), + testCheckDataFactoryLinkedServiceSynapseExists(data.ResourceName), resource.TestCheckResourceAttr(data.ResourceName, "parameters.%", "2"), resource.TestCheckResourceAttr(data.ResourceName, "annotations.#", "3"), resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), @@ -62,7 +62,7 @@ func TestAccAzureRMDataFactoryLinkedServiceSynapse_KeyVaultReference(t *testing. }) } -func testCheckAzureRMDataFactoryLinkedServiceSynapseExists(name string) resource.TestCheckFunc { +func testCheckDataFactoryLinkedServiceSynapseExists(name string) resource.TestCheckFunc { return func(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).DataFactory.LinkedServiceClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -93,7 +93,7 @@ func testCheckAzureRMDataFactoryLinkedServiceSynapseExists(name string) resource } } -func testCheckAzureRMDataFactoryLinkedServiceSynapseDestroy(s *terraform.State) error { +func testCheckDataFactoryLinkedServiceSynapseDestroy(s *terraform.State) error { client := acceptance.AzureProvider.Meta().(*clients.Client).DataFactory.LinkedServiceClient ctx := acceptance.AzureProvider.Meta().(*clients.Client).StopContext @@ -119,7 +119,7 @@ func testCheckAzureRMDataFactoryLinkedServiceSynapseDestroy(s *terraform.State) return nil } -func testAccAzureRMDataFactoryLinkedServiceSynapse_connection_string(data acceptance.TestData) string { +func testAccDataFactoryLinkedServiceSynapse_connection_string(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} @@ -159,7 +159,7 @@ resource "azurerm_data_factory_linked_service_synapse" "test" { `, data.RandomInteger, data.Locations.Primary, data.RandomInteger) } -func testAccAzureRMDataFactoryLinkedServiceSynapse_key_vault_reference(data acceptance.TestData) string { +func testAccDataFactoryLinkedServiceSynapse_key_vault_reference(data acceptance.TestData) string { return fmt.Sprintf(` provider "azurerm" { features {} From 2e7c3068bf2089a523561a45b6be4bd2e5241cf4 Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Thu, 31 Dec 2020 17:29:53 -0300 Subject: [PATCH 10/13] validating str not empty, using parseid --- ...factory_linked_service_synapse_resource.go | 52 ++++++++----------- 1 file changed, 23 insertions(+), 29 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go index 1bf002a5418b..34925b7d7f97 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go @@ -12,6 +12,7 @@ import ( "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/tf" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/helpers/validate" "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/timeouts" "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" ) @@ -97,7 +98,8 @@ func resourceArmDataFactoryLinkedServiceSynapse() *schema.Resource { Type: schema.TypeMap, Optional: true, Elem: &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeString, + ValidateFunc: validation.StringIsNotEmpty, }, }, @@ -105,7 +107,8 @@ func resourceArmDataFactoryLinkedServiceSynapse() *schema.Resource { Type: schema.TypeList, Optional: true, Elem: &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeString, + ValidateFunc: validation.StringIsNotEmpty, }, }, @@ -113,7 +116,8 @@ func resourceArmDataFactoryLinkedServiceSynapse() *schema.Resource { Type: schema.TypeMap, Optional: true, Elem: &schema.Schema{ - Type: schema.TypeString, + Type: schema.TypeString, + ValidateFunc: validation.StringIsNotEmpty, }, }, }, @@ -144,17 +148,13 @@ func resourceArmDataFactoryLinkedServiceSynapseCreateUpdate(d *schema.ResourceDa passwordReference := d.Get("key_vault_password_reference").([]interface{}) - sqlDWProperties := &datafactory.AzureSQLDWLinkedServiceTypeProperties{ - ConnectionString: d.Get("connection_string").(string), - Password: expandAzureKeyVaultPasswordReference(passwordReference), - } - - description := d.Get("description").(string) - sqlDWLinkedService := &datafactory.AzureSQLDWLinkedService{ - Description: &description, - AzureSQLDWLinkedServiceTypeProperties: sqlDWProperties, - Type: datafactory.TypeAzureSQLDW, + Description: utils.String(d.Get("description").(string)), + AzureSQLDWLinkedServiceTypeProperties: &datafactory.AzureSQLDWLinkedServiceTypeProperties{ + ConnectionString: d.Get("connection_string").(string), + Password: expandAzureKeyVaultPasswordReference(passwordReference), + }, + Type: datafactory.TypeAzureSQLDW, } if v, ok := d.GetOk("parameters"); ok { @@ -201,31 +201,28 @@ func resourceArmDataFactoryLinkedServiceSynapseRead(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 Synapse %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error retrieving Data Factory Linked Service Synapse %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("name", id.Name) + d.Set("resource_group_name", id.ResourceGroup) + d.Set("data_factory_name", id.FactoryName) sqlDW, ok := resp.Properties.AsAzureSQLDWLinkedService() if !ok { - return fmt.Errorf("Error classifiying Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeAzureSQLDW, *resp.Type) + return fmt.Errorf("Error classifying Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", id.Name, id.FactoryName, id.ResourceGroup, datafactory.TypeAzureSQLDW, *resp.Type) } d.Set("additional_properties", sqlDW.AdditionalProperties) @@ -270,18 +267,15 @@ func resourceArmDataFactoryLinkedServiceSynapseDelete(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 Synapse %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + return fmt.Errorf("Error deleting Data Factory Linked Service Synapse %q (Data Factory %q / Resource Group %q): %+v", id.Name, id.FactoryName, id.ResourceGroup, err) } } From 84c13180571466676aabb4a0f5e3a0cff22ce2d1 Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Fri, 1 Jan 2021 12:30:59 -0300 Subject: [PATCH 11/13] cleaning interface --- .../services/datafactory/data_factory.go | 16 ++++++---------- ...ta_factory_linked_service_synapse_resource.go | 12 ++++++------ ...ctory_linked_service_synapse_resource_test.go | 8 ++++---- 3 files changed, 16 insertions(+), 20 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory.go b/azurerm/internal/services/datafactory/data_factory.go index c967bd2003b5..5039a21e4649 100644 --- a/azurerm/internal/services/datafactory/data_factory.go +++ b/azurerm/internal/services/datafactory/data_factory.go @@ -228,27 +228,23 @@ func suppressJsonOrderingDifference(_, old, new string, _ *schema.ResourceData) return utils.NormalizeJson(old) == utils.NormalizeJson(new) } -func expandAzureKeyVaultPasswordReference(input []interface{}) *datafactory.AzureKeyVaultSecretReference { +func expandAzureKeyVaultPassword(input []interface{}) *datafactory.AzureKeyVaultSecretReference { if len(input) == 0 || input[0] == nil { return nil } config := input[0].(map[string]interface{}) - keyVaultLinkedServiceName := config["linked_service_name"].(string) - keyVaultPasswordSecretName := config["password_secret_name"].(string) - linkedServiceType := "LinkedServiceReference" - return &datafactory.AzureKeyVaultSecretReference{ - SecretName: keyVaultPasswordSecretName, + SecretName: config["secret_name"].(string), Store: &datafactory.LinkedServiceReference{ - Type: &linkedServiceType, - ReferenceName: &keyVaultLinkedServiceName, + Type: utils.String("LinkedServiceReference"), + ReferenceName: utils.String(config["linked_service_name"].(string)), }, } } -func flattenAzureKeyVaultPasswordReference(secretReference *datafactory.AzureKeyVaultSecretReference) []interface{} { +func flattenAzureKeyVaultPassword(secretReference *datafactory.AzureKeyVaultSecretReference) []interface{} { if secretReference == nil { return nil } @@ -261,7 +257,7 @@ func flattenAzureKeyVaultPasswordReference(secretReference *datafactory.AzureKey } } - parameters["password_secret_name"] = secretReference.SecretName + parameters["secret_name"] = secretReference.SecretName return []interface{}{parameters} } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go index 34925b7d7f97..269ac08c0437 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource.go @@ -61,7 +61,7 @@ func resourceArmDataFactoryLinkedServiceSynapse() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "key_vault_password_reference": { + "key_vault_password": { Type: schema.TypeList, Optional: true, MaxItems: 1, @@ -73,7 +73,7 @@ func resourceArmDataFactoryLinkedServiceSynapse() *schema.Resource { ValidateFunc: validation.StringIsNotEmpty, }, - "password_secret_name": { + "secret_name": { Type: schema.TypeString, Required: true, ValidateFunc: validation.StringIsNotEmpty, @@ -146,13 +146,13 @@ func resourceArmDataFactoryLinkedServiceSynapseCreateUpdate(d *schema.ResourceDa } } - passwordReference := d.Get("key_vault_password_reference").([]interface{}) + password := d.Get("key_vault_password").([]interface{}) sqlDWLinkedService := &datafactory.AzureSQLDWLinkedService{ Description: utils.String(d.Get("description").(string)), AzureSQLDWLinkedServiceTypeProperties: &datafactory.AzureSQLDWLinkedServiceTypeProperties{ ConnectionString: d.Get("connection_string").(string), - Password: expandAzureKeyVaultPasswordReference(passwordReference), + Password: expandAzureKeyVaultPassword(password), }, Type: datafactory.TypeAzureSQLDW, } @@ -254,8 +254,8 @@ func resourceArmDataFactoryLinkedServiceSynapseRead(d *schema.ResourceData, meta } } - if err := d.Set("key_vault_password_reference", flattenAzureKeyVaultPasswordReference(properties.Password)); err != nil { - return fmt.Errorf("setting `key_vault_password_reference`: %+v", err) + if err := d.Set("key_vault_password", flattenAzureKeyVaultPassword(properties.Password)); err != nil { + return fmt.Errorf("setting `key_vault_password`: %+v", err) } } diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go index 26f474597f41..daf74df34b74 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go @@ -53,8 +53,8 @@ func TestAccDataFactoryLinkedServiceSynapse_KeyVaultReference(t *testing.T) { resource.TestCheckResourceAttr(data.ResourceName, "additional_properties.%", "2"), resource.TestCheckResourceAttr(data.ResourceName, "description", "test description"), resource.TestCheckResourceAttrSet(data.ResourceName, "connection_string"), - resource.TestCheckResourceAttrSet(data.ResourceName, "key_vault_password_reference.0.linked_service_name"), - resource.TestCheckResourceAttr(data.ResourceName, "key_vault_password_reference.0.password_secret_name", "secret"), + resource.TestCheckResourceAttrSet(data.ResourceName, "key_vault_password.0.linked_service_name"), + resource.TestCheckResourceAttr(data.ResourceName, "key_vault_password.0.secret_name", "secret"), ), }, data.ImportStep(), @@ -199,9 +199,9 @@ resource "azurerm_data_factory_linked_service_synapse" "test" { data_factory_name = azurerm_data_factory.test.name connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" - key_vault_password_reference { + key_vault_password { linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name - password_secret_name = "secret" + secret_name = "secret" } annotations = ["test1", "test2", "test3"] From b256d7fba7808667a1756bbf006838f44556f535 Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Fri, 1 Jan 2021 12:52:01 -0300 Subject: [PATCH 12/13] tflint and docs fix --- ...ata_factory_linked_service_synapse_resource_test.go | 4 ++-- .../data_factory_linked_service_synapse.html.markdown | 10 +++++----- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go index daf74df34b74..d3c7aad1dab3 100644 --- a/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go +++ b/azurerm/internal/services/datafactory/data_factory_linked_service_synapse_resource_test.go @@ -200,8 +200,8 @@ resource "azurerm_data_factory_linked_service_synapse" "test" { connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" key_vault_password { - linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name - secret_name = "secret" + linked_service_name = azurerm_data_factory_linked_service_key_vault.test.name + secret_name = "secret" } annotations = ["test1", "test2", "test3"] diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown index c5d2fc7b8b54..df001e393ff5 100644 --- a/website/docs/r/data_factory_linked_service_synapse.html.markdown +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -72,9 +72,9 @@ resource "azurerm_data_factory_linked_service_synapse" "example" { data_factory_name = azurerm_data_factory.example.name connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" - key_vault_password_reference { + key_vault_password { linked_service_name = azurerm_data_factory_linked_service_key_vault.example.name - password_secret_name = "secret" + secret_name = "secret" } } ``` @@ -103,15 +103,15 @@ The following supported arguments are specific to Data Factory Synapse Linked Se * `connection_string` - (Required) The connection string in which to authenticate with the Synapse. -* `key_vault_password_reference` - (Optional) A `key_vault_password_reference` block as defined below. Use this argument to store Synapse password in an existing Key Vault. It needs an existing Key Vault Data Factory Linked Service. +* `key_vault_password` - (Optional) A `key_vault_password` block as defined below. Use this argument to store Synapse password in an existing Key Vault. It needs an existing Key Vault Data Factory Linked Service. --- -A `key_vault_password_reference` block supports the following: +A `key_vault_password` block supports the following: * `linked_service_name` - (Required) Specifies the name of an existing Key Vault Data Factory Linked Service. -* `password_secret_name` - (Required) Specifies the secret name in Azure Key Vault that stores Synapse password. +* `secret_name` - (Required) Specifies the secret name in Azure Key Vault that stores Synapse password. --- From 64f22d75ec24e9026cd1b7dc98095f2fe511e9c5 Mon Sep 17 00:00:00 2001 From: Allan Targino <13934447+allantargino@users.noreply.github.com> Date: Fri, 1 Jan 2021 12:58:46 -0300 Subject: [PATCH 13/13] fix lint on docs --- .../docs/r/data_factory_linked_service_synapse.html.markdown | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/website/docs/r/data_factory_linked_service_synapse.html.markdown b/website/docs/r/data_factory_linked_service_synapse.html.markdown index df001e393ff5..75b0a374e277 100644 --- a/website/docs/r/data_factory_linked_service_synapse.html.markdown +++ b/website/docs/r/data_factory_linked_service_synapse.html.markdown @@ -73,8 +73,8 @@ resource "azurerm_data_factory_linked_service_synapse" "example" { connection_string = "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;" key_vault_password { - linked_service_name = azurerm_data_factory_linked_service_key_vault.example.name - secret_name = "secret" + linked_service_name = azurerm_data_factory_linked_service_key_vault.example.name + secret_name = "secret" } } ```