From dcb18679e86a33d0dd3100020c497fe866db0a0c Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 16 Apr 2019 12:35:10 -0600 Subject: [PATCH] New Resource: `azurerm_data_factory_linked_service_mysql` (#3265) --- azurerm/data_factory.go | 53 ++++ azurerm/data_factory_test.go | 40 +++ azurerm/provider.go | 1 + ...e_arm_data_factory_linked_service_mysql.go | 240 ++++++++++++++++++ ..._data_factory_linked_service_mysql_test.go | 230 +++++++++++++++++ ..._data_factory_linked_service_sql_server.go | 52 +--- ..._factory_linked_service_sql_server_test.go | 37 --- website/azurerm.erb | 6 + ...factory_linked_service_mysql.html.markdown | 71 ++++++ 9 files changed, 642 insertions(+), 88 deletions(-) create mode 100644 azurerm/data_factory_test.go create mode 100644 azurerm/resource_arm_data_factory_linked_service_mysql.go create mode 100644 azurerm/resource_arm_data_factory_linked_service_mysql_test.go create mode 100644 website/docs/r/data_factory_linked_service_mysql.html.markdown diff --git a/azurerm/data_factory.go b/azurerm/data_factory.go index 5a2de0759b00..893f48c7b147 100644 --- a/azurerm/data_factory.go +++ b/azurerm/data_factory.go @@ -1,11 +1,64 @@ package azurerm import ( + "fmt" "log" + "regexp" + "sort" + "strings" "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" + "github.com/hashicorp/terraform/helper/schema" ) +func validateAzureRMDataFactoryLinkedServiceDatasetName(v interface{}, k string) (warnings []string, errors []error) { + value := v.(string) + if regexp.MustCompile(`^[-.+?/<>*%&:\\]+$`).MatchString(value) { + errors = append(errors, fmt.Errorf("any of '-' '.', '+', '?', '/', '<', '>', '*', '%%', '&', ':', '\\', are not allowed in %q: %q", k, value)) + } + + return warnings, errors +} + +func expandDataFactoryLinkedServiceIntegrationRuntime(integrationRuntimeName string) *datafactory.IntegrationRuntimeReference { + typeString := "IntegrationRuntimeReference" + + return &datafactory.IntegrationRuntimeReference{ + ReferenceName: &integrationRuntimeName, + Type: &typeString, + } +} + +// Because the password isn't returned from the api in the connection string, we'll check all +// but the password string and return true if they match. +func azureRmDataFactoryLinkedServiceConnectionStringDiff(k, old string, new string, d *schema.ResourceData) bool { + oldSplit := strings.Split(strings.ToLower(old), ";") + newSplit := strings.Split(strings.ToLower(new), ";") + + sort.Strings(oldSplit) + sort.Strings(newSplit) + + // We need to remove the password from the new string since it isn't returned from the api + for i, v := range newSplit { + if strings.HasPrefix(v, "password") { + newSplit = append(newSplit[:i], newSplit[i+1:]...) + } + } + + if len(oldSplit) != len(newSplit) { + return false + } + + // We'll error out if we find any differences between the old and the new connection strings + for i := range oldSplit { + if !strings.EqualFold(oldSplit[i], newSplit[i]) { + return false + } + } + + return true +} + func expandDataFactoryParameters(input map[string]interface{}) map[string]*datafactory.ParameterSpecification { output := make(map[string]*datafactory.ParameterSpecification) diff --git a/azurerm/data_factory_test.go b/azurerm/data_factory_test.go new file mode 100644 index 000000000000..1424fe672118 --- /dev/null +++ b/azurerm/data_factory_test.go @@ -0,0 +1,40 @@ +package azurerm + +import "testing" + +func TestAzureRmDataFactoryLinkedServiceConnectionStringDiff(t *testing.T) { + cases := []struct { + Old string + New string + NoDiff bool + }{ + { + Old: "", + New: "", + NoDiff: true, + }, + { + Old: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test", + New: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test", + NoDiff: true, + }, + { + Old: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test", + New: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test", + NoDiff: true, + }, + { + Old: "Integrated Security=False;Data Source=test2;Initial Catalog=test;User ID=test", + New: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test", + NoDiff: false, + }, + } + + for _, tc := range cases { + noDiff := azureRmDataFactoryLinkedServiceConnectionStringDiff("", tc.Old, tc.New, nil) + + if noDiff != tc.NoDiff { + t.Fatalf("Expected azureRmDataFactoryLinkedServiceConnectionStringDiff to be '%t' for '%s' '%s' - got '%t'", tc.NoDiff, tc.Old, tc.New, noDiff) + } + } +} diff --git a/azurerm/provider.go b/azurerm/provider.go index af3cca47fd29..0e58c4d90b17 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -222,6 +222,7 @@ func Provider() terraform.ResourceProvider { "azurerm_cosmosdb_account": resourceArmCosmosDBAccount(), "azurerm_data_factory": resourceArmDataFactory(), "azurerm_data_factory_dataset_sql_server_table": resourceArmDataFactoryDatasetSQLServerTable(), + "azurerm_data_factory_linked_service_mysql": resourceArmDataFactoryLinkedServiceMySQL(), "azurerm_data_factory_linked_service_sql_server": resourceArmDataFactoryLinkedServiceSQLServer(), "azurerm_data_factory_pipeline": resourceArmDataFactoryPipeline(), "azurerm_data_lake_analytics_account": resourceArmDataLakeAnalyticsAccount(), diff --git a/azurerm/resource_arm_data_factory_linked_service_mysql.go b/azurerm/resource_arm_data_factory_linked_service_mysql.go new file mode 100644 index 000000000000..da00f51a9de9 --- /dev/null +++ b/azurerm/resource_arm_data_factory_linked_service_mysql.go @@ -0,0 +1,240 @@ +package azurerm + +import ( + "fmt" + "regexp" + + "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" + "github.com/hashicorp/terraform/helper/schema" + "github.com/hashicorp/terraform/helper/validation" + "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/utils" +) + +func resourceArmDataFactoryLinkedServiceMySQL() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDataFactoryLinkedServiceMySQLCreateOrUpdate, + Read: resourceArmDataFactoryLinkedServiceMySQLRead, + Update: resourceArmDataFactoryLinkedServiceMySQLCreateOrUpdate, + Delete: resourceArmDataFactoryLinkedServiceMySQLDelete, + + Importer: &schema.ResourceImporter{ + State: schema.ImportStatePassthrough, + }, + + 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: validation.StringMatch( + regexp.MustCompile(`^[A-Za-z0-9]+(?:-[A-Za-z0-9]+)*$`), + `Invalid name for Data Factory, see https://docs.microsoft.com/en-us/azure/data-factory/naming-rules`, + ), + }, + + "resource_group_name": resourceGroupNameSchema(), + + "connection_string": { + Type: schema.TypeString, + Required: true, + DiffSuppressFunc: azureRmDataFactoryLinkedServiceConnectionStringDiff, + ValidateFunc: validate.NoEmptyStrings, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "integration_runtime_name": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "parameters": { + Type: schema.TypeMap, + Optional: true, + }, + + "annotations": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "additional_properties": { + Type: schema.TypeMap, + Optional: true, + }, + }, + } +} + +func resourceArmDataFactoryLinkedServiceMySQLCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataFactoryLinkedServiceClient + ctx := meta.(*ArmClient).StopContext + + name := d.Get("name").(string) + dataFactoryName := d.Get("data_factory_name").(string) + resourceGroup := d.Get("resource_group_name").(string) + + if requireResourcesToBeImported && 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 MySQL %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_mysql", *existing.ID) + } + } + + connectionString := d.Get("connection_string").(string) + secureString := datafactory.SecureString{ + Value: &connectionString, + Type: datafactory.TypeSecureString, + } + + mysqlProperties := &datafactory.MySQLLinkedServiceTypeProperties{ + ConnectionString: &secureString, + } + + description := d.Get("description").(string) + + mysqlLinkedService := &datafactory.MySQLLinkedService{ + Description: &description, + MySQLLinkedServiceTypeProperties: mysqlProperties, + Type: datafactory.TypeMySQL, + } + + if v, ok := d.GetOk("parameters"); ok { + mysqlLinkedService.Parameters = expandDataFactoryParameters(v.(map[string]interface{})) + } + + if v, ok := d.GetOk("integration_runtime_name"); ok { + mysqlLinkedService.ConnectVia = expandDataFactoryLinkedServiceIntegrationRuntime(v.(string)) + } + + if v, ok := d.GetOk("additional_properties"); ok { + mysqlLinkedService.AdditionalProperties = v.(map[string]interface{}) + } + + if v, ok := d.GetOk("annotations"); ok { + annotations := v.([]interface{}) + mysqlLinkedService.Annotations = &annotations + } + + linkedService := datafactory.LinkedServiceResource{ + Properties: mysqlLinkedService, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, dataFactoryName, name, linkedService, ""); err != nil { + return fmt.Errorf("Error creating/updating Data Factory Linked Service MySQL %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 MySQL %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 MySQL %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + + d.SetId(*resp.ID) + + return resourceArmDataFactoryLinkedServiceMySQLRead(d, meta) +} + +func resourceArmDataFactoryLinkedServiceMySQLRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataFactoryLinkedServiceClient + ctx := meta.(*ArmClient).StopContext + + id, err := 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 MySQL %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) + + 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.TypeMySQL, *resp.Type) + } + + d.Set("additional_properties", mysql.AdditionalProperties) + + if mysql.Description != nil { + d.Set("description", *mysql.Description) + } + + annotations := flattenDataFactoryAnnotations(mysql.Annotations) + if err := d.Set("annotations", annotations); err != nil { + return fmt.Errorf("Error setting `annotations`: %+v", err) + } + + parameters := flattenDataFactoryParameters(mysql.Parameters) + if err := d.Set("parameters", parameters); err != nil { + return fmt.Errorf("Error setting `parameters`: %+v", err) + } + + if connectVia := mysql.ConnectVia; connectVia != nil { + if connectVia.ReferenceName != nil { + d.Set("integration_runtime_name", connectVia.ReferenceName) + } + } + + return nil +} + +func resourceArmDataFactoryLinkedServiceMySQLDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataFactoryLinkedServiceClient + ctx := meta.(*ArmClient).StopContext + + id, err := 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 MySQL %q (Data Factory %q / Resource Group %q): %+v", name, dataFactoryName, resourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/resource_arm_data_factory_linked_service_mysql_test.go b/azurerm/resource_arm_data_factory_linked_service_mysql_test.go new file mode 100644 index 000000000000..e9a9c5eb64a1 --- /dev/null +++ b/azurerm/resource_arm_data_factory_linked_service_mysql_test.go @@ -0,0 +1,230 @@ +package azurerm + +import ( + "fmt" + "net/http" + "testing" + + "github.com/hashicorp/terraform/helper/resource" + "github.com/hashicorp/terraform/terraform" + "github.com/terraform-providers/terraform-provider-azurerm/azurerm/utils" + + "github.com/hashicorp/terraform/helper/acctest" +) + +func TestAccAzureRMDataFactoryLinkedServiceMySQL_basic(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMDataFactoryLinkedServiceMySQL_basic(ri, testLocation()) + resourceName := "azurerm_data_factory_linked_service_mysql.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceMySQLDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryLinkedServiceMySQLExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // returned as ***** from the api + "connection_string", + }, + }, + }, + }) +} + +func TestAccAzureRMDataFactoryLinkedServiceMySQL_update(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMDataFactoryLinkedServiceMySQL_update1(ri, testLocation()) + config2 := testAccAzureRMDataFactoryLinkedServiceMySQL_update2(ri, testLocation()) + resourceName := "azurerm_data_factory_linked_service_mysql.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryLinkedServiceMySQLDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryLinkedServiceMySQLExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(resourceName, "description", "test description"), + ), + }, + { + Config: config2, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryLinkedServiceMySQLExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + ImportStateVerifyIgnore: []string{ + // returned as ***** from the api + "connection_string", + }, + }, + }, + }) +} + +func testCheckAzureRMDataFactoryLinkedServiceMySQLExists(name string) resource.TestCheckFunc { + return func(s *terraform.State) error { + // 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) + } + + client := testAccProvider.Meta().(*ArmClient).dataFactoryLinkedServiceClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + 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 MySQL %q (data factory name: %q / resource group: %q) does not exist", name, dataFactoryName, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMDataFactoryLinkedServiceMySQLDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).dataFactoryLinkedServiceClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_data_factory_linked_service_mysql" { + 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 MySQL still exists:\n%#v", resp.Properties) + } + } + + return nil +} + +func testAccAzureRMDataFactoryLinkedServiceMySQL_basic(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%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_mysql" "test" { + name = "acctestlssql%d" + resource_group_name = "${azurerm_resource_group.test.name}" + data_factory_name = "${azurerm_data_factory.test.name}" + connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMDataFactoryLinkedServiceMySQL_update1(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%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_mysql" "test" { + name = "acctestlssql%d" + resource_group_name = "${azurerm_resource_group.test.name}" + data_factory_name = "${azurerm_data_factory.test.name}" + connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" + annotations = ["test1", "test2", "test3"] + description = "test description" + parameters { + "foo" = "test1" + "bar" = "test2" + } + additional_properties { + "foo" = "test1" + "bar" = "test2" + } +} +`, rInt, location, rInt, rInt) +} + +func testAccAzureRMDataFactoryLinkedServiceMySQL_update2(rInt int, location string) string { + return fmt.Sprintf(` +resource "azurerm_resource_group" "test" { + name = "acctestrg-%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_mysql" "test" { + name = "acctestlssql%d" + resource_group_name = "${azurerm_resource_group.test.name}" + data_factory_name = "${azurerm_data_factory.test.name}" + connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" + annotations = ["test1", "test2"] + description = "test description 2" + parameters { + "foo" = "test1" + "bar" = "test2" + "buzz" = "test3" + } + additional_properties { + "foo" = "test1" + } +} +`, rInt, location, rInt, rInt) +} diff --git a/azurerm/resource_arm_data_factory_linked_service_sql_server.go b/azurerm/resource_arm_data_factory_linked_service_sql_server.go index 145deade7b21..feb4899780c2 100644 --- a/azurerm/resource_arm_data_factory_linked_service_sql_server.go +++ b/azurerm/resource_arm_data_factory_linked_service_sql_server.go @@ -4,8 +4,6 @@ import ( "fmt" "log" "regexp" - "sort" - "strings" "github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory" "github.com/hashicorp/terraform/helper/schema" @@ -103,7 +101,7 @@ func resourceArmDataFactoryLinkedServiceSQLServerCreateOrUpdate(d *schema.Resour } if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_factory_sql_server_linked_service", *existing.ID) + return tf.ImportAsExistsError("azurerm_data_factory_linked_service_sql_server", *existing.ID) } } @@ -248,51 +246,3 @@ func resourceArmDataFactoryLinkedServiceSQLServerDelete(d *schema.ResourceData, return nil } - -// Because the password isn't returned from the api in the connection string, we'll check all -// but the password string and return true if they match. -func azureRmDataFactoryLinkedServiceConnectionStringDiff(k, old string, new string, d *schema.ResourceData) bool { - oldSplit := strings.Split(strings.ToLower(old), ";") - newSplit := strings.Split(strings.ToLower(new), ";") - - sort.Strings(oldSplit) - sort.Strings(newSplit) - - // We need to remove the password from the new string since it isn't returned from the api - for i, v := range newSplit { - if strings.HasPrefix(v, "password") { - newSplit = append(newSplit[:i], newSplit[i+1:]...) - } - } - - if len(oldSplit) != len(newSplit) { - return false - } - - // We'll error out if we find any differences between the old and the new connection strings - for i := range oldSplit { - if !strings.EqualFold(oldSplit[i], newSplit[i]) { - return false - } - } - - return true -} - -func validateAzureRMDataFactoryLinkedServiceDatasetName(v interface{}, k string) (warnings []string, errors []error) { - value := v.(string) - if regexp.MustCompile(`^[-.+?/<>*%&:\\]+$`).MatchString(value) { - errors = append(errors, fmt.Errorf("any of '-' '.', '+', '?', '/', '<', '>', '*', '%%', '&', ':', '\\', are not allowed in %q: %q", k, value)) - } - - return warnings, errors -} - -func expandDataFactoryLinkedServiceIntegrationRuntime(integrationRuntimeName string) *datafactory.IntegrationRuntimeReference { - typeString := "IntegrationRuntimeReference" - - return &datafactory.IntegrationRuntimeReference{ - ReferenceName: &integrationRuntimeName, - Type: &typeString, - } -} diff --git a/azurerm/resource_arm_data_factory_linked_service_sql_server_test.go b/azurerm/resource_arm_data_factory_linked_service_sql_server_test.go index a2d7503aba00..ed2f02f81393 100644 --- a/azurerm/resource_arm_data_factory_linked_service_sql_server_test.go +++ b/azurerm/resource_arm_data_factory_linked_service_sql_server_test.go @@ -12,43 +12,6 @@ import ( "github.com/hashicorp/terraform/helper/acctest" ) -func TestAzureRmDataFactoryLinkedServiceConnectionStringDiff(t *testing.T) { - cases := []struct { - Old string - New string - NoDiff bool - }{ - { - Old: "", - New: "", - NoDiff: true, - }, - { - Old: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test", - New: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test", - NoDiff: true, - }, - { - Old: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test", - New: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test", - NoDiff: true, - }, - { - Old: "Integrated Security=False;Data Source=test2;Initial Catalog=test;User ID=test", - New: "Integrated Security=False;Data Source=test;Initial Catalog=test;User ID=test;Password=test", - NoDiff: false, - }, - } - - for _, tc := range cases { - noDiff := azureRmDataFactoryLinkedServiceConnectionStringDiff("", tc.Old, tc.New, nil) - - if noDiff != tc.NoDiff { - t.Fatalf("Expected azureRmDataFactoryLinkedServiceConnectionStringDiff to be '%t' for '%s' '%s' - got '%t'", tc.NoDiff, tc.Old, tc.New, noDiff) - } - } -} - func TestAccAzureRMDataFactoryLinkedServiceSQLServer_basic(t *testing.T) { ri := acctest.RandInt() config := testAccAzureRMDataFactoryLinkedServiceSQLServer_basic(ri, testLocation()) diff --git a/website/azurerm.erb b/website/azurerm.erb index a9a57d1f889c..e2222b403bf5 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -735,6 +735,12 @@ > azurerm_data_factory_dataset_sql_server_table + > + azurerm_data_factory_pipeline + + > + azurerm_data_factory_linked_service_mysql + > azurerm_data_factory_linked_service_sql_server diff --git a/website/docs/r/data_factory_linked_service_mysql.html.markdown b/website/docs/r/data_factory_linked_service_mysql.html.markdown new file mode 100644 index 000000000000..d9cd4bfe4fe6 --- /dev/null +++ b/website/docs/r/data_factory_linked_service_mysql.html.markdown @@ -0,0 +1,71 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_factory_linked_service_mysql" +sidebar_current: "docs-azurerm-resource-data-factory-linked-service-mysql" +description: |- + Manage a Linked Service (connection) between MySQL and Azure Data Factory. +--- + +# azurerm_data_factory_linked_service_mysql + +Manage a Linked Service (connection) between MySQL and Azure Data Factory. + +~> **Note:** All arguments including the connection_string 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" + 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_mysql" "example" { + name = "example" + resource_group_name = "${azurerm_resource_group.test.name}" + data_factory_name = "${azurerm_data_factory.test.name}" + connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Data Factory Linked Service MySQL. 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 MySQL. 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 MySQL. + +* `description` - (Optional) The description for the Data Factory Linked Service MySQL. + +* `integration_runtime_name` - (Optional) The integration runtime reference to associate with the Data Factory Linked Service MySQL. + +* `annotations` - (Optional) List of tags that can be used for describing the Data Factory Linked Service MySQL. + +* `parameters` - (Optional) A map of parameters to associate with the Data Factory Linked Service MySQL. + +* `additional_properties` - (Optional) A map of additional properties to associate with the Data Factory Linked Service MySQL. + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Data Factory Linked Service. + +## Import + +Data Factory Linked Service MySQL can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_data_factory_linked_service_mysql.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.DataFactory/factories/example/linkedservices/example +```