From 5028d9943d087e2bc208d2f184a53a0bc8ecb240 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 16 Apr 2019 13:14:56 -0600 Subject: [PATCH 1/2] Adding mysql dataset --- azurerm/data_factory.go | 54 +++ azurerm/provider.go | 1 + ...resource_arm_data_factory_dataset_mysql.go | 315 ++++++++++++++++++ ...rce_arm_data_factory_dataset_mysql_test.go | 273 +++++++++++++++ ...m_data_factory_dataset_sql_server_table.go | 54 --- website/azurerm.erb | 3 + .../data_factory_dataset_mysql.html.markdown | 91 +++++ 7 files changed, 737 insertions(+), 54 deletions(-) create mode 100644 azurerm/resource_arm_data_factory_dataset_mysql.go create mode 100644 azurerm/resource_arm_data_factory_dataset_mysql_test.go create mode 100644 website/docs/r/data_factory_dataset_mysql.html.markdown diff --git a/azurerm/data_factory.go b/azurerm/data_factory.go index 893f48c7b147..ac2d9c7be8b4 100644 --- a/azurerm/data_factory.go +++ b/azurerm/data_factory.go @@ -136,3 +136,57 @@ func flattenDataFactoryVariables(input map[string]*datafactory.VariableSpecifica return output } + +// DatasetColumn describes the attributes needed to specify a structure column for a dataset +type DatasetColumn struct { + Name string `json:"name,omitempty"` + Description string `json:"description,omitempty"` + Type string `json:"type,omitempty"` +} + +func expandDataFactoryDatasetStructure(input []interface{}) interface{} { + columns := make([]DatasetColumn, 0) + for _, column := range input { + attrs := column.(map[string]interface{}) + + datasetColumn := DatasetColumn{ + Name: attrs["name"].(string), + } + if attrs["description"] != nil { + datasetColumn.Description = attrs["description"].(string) + } + if attrs["type"] != nil { + datasetColumn.Type = attrs["type"].(string) + } + columns = append(columns, datasetColumn) + } + return columns +} + +func flattenDataFactoryStructureColumns(input interface{}) []interface{} { + output := make([]interface{}, 0) + + columns, ok := input.([]interface{}) + if !ok { + return columns + } + + for _, v := range columns { + column, ok := v.(map[string]interface{}) + if !ok { + continue + } + result := make(map[string]interface{}) + if column["name"] != nil { + result["name"] = column["name"] + } + if column["type"] != nil { + result["type"] = column["type"] + } + if column["description"] != nil { + result["description"] = column["description"] + } + output = append(output, result) + } + return output +} diff --git a/azurerm/provider.go b/azurerm/provider.go index 0e58c4d90b17..58cc11939475 100644 --- a/azurerm/provider.go +++ b/azurerm/provider.go @@ -221,6 +221,7 @@ func Provider() terraform.ResourceProvider { "azurerm_container_service": resourceArmContainerService(), "azurerm_cosmosdb_account": resourceArmCosmosDBAccount(), "azurerm_data_factory": resourceArmDataFactory(), + "azurerm_data_factory_dataset_mysql": resourceArmDataFactoryDatasetMySQL(), "azurerm_data_factory_dataset_sql_server_table": resourceArmDataFactoryDatasetSQLServerTable(), "azurerm_data_factory_linked_service_mysql": resourceArmDataFactoryLinkedServiceMySQL(), "azurerm_data_factory_linked_service_sql_server": resourceArmDataFactoryLinkedServiceSQLServer(), diff --git a/azurerm/resource_arm_data_factory_dataset_mysql.go b/azurerm/resource_arm_data_factory_dataset_mysql.go new file mode 100644 index 000000000000..8a64b79054c2 --- /dev/null +++ b/azurerm/resource_arm_data_factory_dataset_mysql.go @@ -0,0 +1,315 @@ +package azurerm + +import ( + "fmt" + "log" + "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 resourceArmDataFactoryDatasetMySQL() *schema.Resource { + return &schema.Resource{ + Create: resourceArmDataFactoryDatasetMySQLCreateOrUpdate, + Read: resourceArmDataFactoryDatasetMySQLRead, + Update: resourceArmDataFactoryDatasetMySQLCreateOrUpdate, + Delete: resourceArmDataFactoryDatasetMySQLDelete, + + 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(), + + "linked_service_name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "table_name": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "parameters": { + Type: schema.TypeMap, + Optional: true, + }, + + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "annotations": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Schema{ + Type: schema.TypeString, + }, + }, + + "folder": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, + }, + + "additional_properties": { + Type: schema.TypeMap, + Optional: true, + }, + + "schema_column": { + Type: schema.TypeList, + Optional: true, + Elem: &schema.Resource{ + Schema: map[string]*schema.Schema{ + "name": { + Type: schema.TypeString, + Required: true, + ValidateFunc: validate.NoEmptyStrings, + }, + "type": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validation.StringInSlice([]string{ + "Byte", + "Byte[]", + "Boolean", + "Date", + "DateTime", + "DateTimeOffset", + "Decimal", + "Double", + "Guid", + "Int16", + "Int32", + "Int64", + "Single", + "String", + "TimeSpan", + }, false), + }, + "description": { + Type: schema.TypeString, + Optional: true, + ValidateFunc: validate.NoEmptyStrings, + }, + }, + }, + }, + }, + } +} + +func resourceArmDataFactoryDatasetMySQLCreateOrUpdate(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataFactoryDatasetClient + 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 Dataset MySQL %q (Data Factory %q / Resource Group %q): %s", name, dataFactoryName, resourceGroup, err) + } + } + + if existing.ID != nil && *existing.ID != "" { + return tf.ImportAsExistsError("azurerm_data_factory_dataset_sql_server", *existing.ID) + } + } + + mysqlDatasetProperties := datafactory.RelationalTableDatasetTypeProperties{ + TableName: d.Get("table_name").(string), + } + + linkedServiceName := d.Get("linked_service_name").(string) + linkedServiceType := "LinkedServiceReference" + linkedService := &datafactory.LinkedServiceReference{ + ReferenceName: &linkedServiceName, + Type: &linkedServiceType, + } + + description := d.Get("description").(string) + mysqlTableset := datafactory.RelationalTableDataset{ + RelationalTableDatasetTypeProperties: &mysqlDatasetProperties, + LinkedServiceName: linkedService, + Description: &description, + } + + if v, ok := d.GetOk("folder"); ok { + name := v.(string) + mysqlTableset.Folder = &datafactory.DatasetFolder{ + Name: &name, + } + } + + if v, ok := d.GetOk("parameters"); ok { + mysqlTableset.Parameters = expandDataFactoryParameters(v.(map[string]interface{})) + } + + if v, ok := d.GetOk("annotations"); ok { + annotations := v.([]interface{}) + mysqlTableset.Annotations = &annotations + } + + if v, ok := d.GetOk("additional_properties"); ok { + mysqlTableset.AdditionalProperties = v.(map[string]interface{}) + } + + if v, ok := d.GetOk("schema_column"); ok { + mysqlTableset.Structure = expandDataFactoryDatasetStructure(v.([]interface{})) + } + + datasetType := string(datafactory.TypeSQLServerTable) + dataset := datafactory.DatasetResource{ + Properties: &mysqlTableset, + Type: &datasetType, + } + + if _, err := client.CreateOrUpdate(ctx, resourceGroup, dataFactoryName, name, dataset, ""); err != nil { + return fmt.Errorf("Error creating/updating Data Factory Dataset MySQL %q (Data Factory %q / Resource Group %q): %s", name, dataFactoryName, resourceGroup, err) + } + + resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + if err != nil { + return fmt.Errorf("Error retrieving Data Factory Dataset MySQL %q (Data Factory %q / Resource Group %q): %s", name, dataFactoryName, resourceGroup, err) + } + + if resp.ID == nil { + return fmt.Errorf("Cannot read Data Factory Dataset MySQL %q (Data Factory %q / Resource Group %q): %s", name, dataFactoryName, resourceGroup, err) + } + + d.SetId(*resp.ID) + + return resourceArmDataFactoryDatasetMySQLRead(d, meta) +} + +func resourceArmDataFactoryDatasetMySQLRead(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataFactoryDatasetClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + dataFactoryName := id.Path["factories"] + name := id.Path["datasets"] + + 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 Dataset MySQL %q (Data Factory %q / Resource Group %q): %s", name, dataFactoryName, resourceGroup, err) + } + + d.Set("name", resp.Name) + d.Set("resource_group_name", resourceGroup) + d.Set("data_factory_name", dataFactoryName) + + mysqlTable, ok := resp.Properties.AsRelationalTableDataset() + if !ok { + return fmt.Errorf("Error classifiying Data Factory Dataset MySQL %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeSQLServerTable, *resp.Type) + } + + d.Set("additional_properties", mysqlTable.AdditionalProperties) + + if mysqlTable.Description != nil { + d.Set("description", mysqlTable.Description) + } + + parameters := flattenDataFactoryParameters(mysqlTable.Parameters) + if err := d.Set("parameters", parameters); err != nil { + return fmt.Errorf("Error setting `parameters`: %+v", err) + } + + annotations := flattenDataFactoryAnnotations(mysqlTable.Annotations) + if err := d.Set("annotations", annotations); err != nil { + return fmt.Errorf("Error setting `annotations`: %+v", err) + } + + if linkedService := mysqlTable.LinkedServiceName; linkedService != nil { + if linkedService.ReferenceName != nil { + d.Set("linked_service_name", linkedService.ReferenceName) + } + } + + if properties := mysqlTable.RelationalTableDatasetTypeProperties; properties != nil { + val, ok := properties.TableName.(string) + if !ok { + log.Printf("[DEBUG] Skipping `table_name` since it's not a string") + } else { + d.Set("table_name", val) + } + } + + if folder := mysqlTable.Folder; folder != nil { + if folder.Name != nil { + d.Set("folder", folder.Name) + } + } + + structureColumns := flattenDataFactoryStructureColumns(mysqlTable.Structure) + if err := d.Set("schema_column", structureColumns); err != nil { + return fmt.Errorf("Error setting `schema_column`: %+v", err) + } + + return nil +} + +func resourceArmDataFactoryDatasetMySQLDelete(d *schema.ResourceData, meta interface{}) error { + client := meta.(*ArmClient).dataFactoryDatasetClient + ctx := meta.(*ArmClient).StopContext + + id, err := parseAzureResourceID(d.Id()) + if err != nil { + return err + } + resourceGroup := id.ResourceGroup + dataFactoryName := id.Path["factories"] + name := id.Path["datasets"] + + response, err := client.Delete(ctx, resourceGroup, dataFactoryName, name) + if err != nil { + if !utils.ResponseWasNotFound(response) { + return fmt.Errorf("Error deleting Data Factory Dataset MySQL %q (Data Factory %q / Resource Group %q): %s", name, dataFactoryName, resourceGroup, err) + } + } + + return nil +} diff --git a/azurerm/resource_arm_data_factory_dataset_mysql_test.go b/azurerm/resource_arm_data_factory_dataset_mysql_test.go new file mode 100644 index 000000000000..42d9c0b38b3f --- /dev/null +++ b/azurerm/resource_arm_data_factory_dataset_mysql_test.go @@ -0,0 +1,273 @@ +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 TestAccAzureRMDataFactoryDatasetMySQL_basic(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMDataFactoryDatasetMySQL_basic(ri, testLocation()) + resourceName := "azurerm_data_factory_dataset_mysql.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryDatasetMySQLDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryDatasetMySQLExists(resourceName), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func TestAccAzureRMDataFactoryDatasetMySQL_update(t *testing.T) { + ri := acctest.RandInt() + config := testAccAzureRMDataFactoryDatasetMySQL_update1(ri, testLocation()) + config2 := testAccAzureRMDataFactoryDatasetMySQL_update2(ri, testLocation()) + resourceName := "azurerm_data_factory_dataset_mysql.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + Providers: testAccProviders, + CheckDestroy: testCheckAzureRMDataFactoryDatasetMySQLDestroy, + Steps: []resource.TestStep{ + { + Config: config, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryDatasetMySQLExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "parameters.%", "2"), + resource.TestCheckResourceAttr(resourceName, "annotations.#", "3"), + resource.TestCheckResourceAttr(resourceName, "schema_column.#", "1"), + resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "2"), + resource.TestCheckResourceAttr(resourceName, "description", "test description"), + ), + }, + { + Config: config2, + Check: resource.ComposeTestCheckFunc( + testCheckAzureRMDataFactoryDatasetMySQLExists(resourceName), + resource.TestCheckResourceAttr(resourceName, "parameters.%", "3"), + resource.TestCheckResourceAttr(resourceName, "annotations.#", "2"), + resource.TestCheckResourceAttr(resourceName, "schema_column.#", "2"), + resource.TestCheckResourceAttr(resourceName, "additional_properties.%", "1"), + resource.TestCheckResourceAttr(resourceName, "description", "test description 2"), + ), + }, + { + ResourceName: resourceName, + ImportState: true, + ImportStateVerify: true, + }, + }, + }) +} + +func testCheckAzureRMDataFactoryDatasetMySQLExists(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).dataFactoryDatasetClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + resp, err := client.Get(ctx, resourceGroup, dataFactoryName, name, "") + if err != nil { + return fmt.Errorf("Bad: Get on dataFactoryDatasetClient: %+v", err) + } + + if utils.ResponseWasNotFound(resp.Response) { + return fmt.Errorf("Bad: Data Factory Dataset MySQL %q (data factory name: %q / resource group: %q) does not exist", name, dataFactoryName, resourceGroup) + } + + return nil + } +} + +func testCheckAzureRMDataFactoryDatasetMySQLDestroy(s *terraform.State) error { + client := testAccProvider.Meta().(*ArmClient).dataFactoryDatasetClient + ctx := testAccProvider.Meta().(*ArmClient).StopContext + + for _, rs := range s.RootModule().Resources { + if rs.Type != "azurerm_data_factory_dataset_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 Dataset MySQL still exists:\n%#v", resp.Properties) + } + } + + return nil +} + +func testAccAzureRMDataFactoryDatasetMySQL_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" +} + +resource "azurerm_data_factory_dataset_mysql" "test" { + name = "acctestds%d" + resource_group_name = "${azurerm_resource_group.test.name}" + data_factory_name = "${azurerm_data_factory.test.name}" + linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" +} +`, rInt, location, rInt, rInt, rInt) +} + +func testAccAzureRMDataFactoryDatasetMySQL_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" +} + +resource "azurerm_data_factory_dataset_mysql" "test" { + name = "acctestds%d" + resource_group_name = "${azurerm_resource_group.test.name}" + data_factory_name = "${azurerm_data_factory.test.name}" + linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" + + description = "test description" + annotations = ["test1", "test2", "test3"] + table_name = "testTable" + folder = "testFolder" + + parameters { + "foo" = "test1" + "bar" = "test2" + } + + additional_properties { + "foo" = "test1" + "bar" = "test2" + } + + schema_column { + name = "test1" + type = "Byte" + description = "description" + } +} +`, rInt, location, rInt, rInt, rInt) +} + +func testAccAzureRMDataFactoryDatasetMySQL_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" +} + +resource "azurerm_data_factory_dataset_mysql" "test" { + name = "acctestds%d" + resource_group_name = "${azurerm_resource_group.test.name}" + data_factory_name = "${azurerm_data_factory.test.name}" + linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" + + description = "test description 2" + annotations = ["test1", "test2"] + table_name = "testTable" + folder = "testFolder" + + parameters { + "foo" = "test1" + "bar" = "test2" + "buzz" = "test3" + } + + additional_properties { + "foo" = "test1" + } + + schema_column { + name = "test1" + type = "Byte" + description = "description" + } + + schema_column { + name = "test2" + type = "Byte" + description = "description" + } +} +`, rInt, location, rInt, rInt, rInt) +} diff --git a/azurerm/resource_arm_data_factory_dataset_sql_server_table.go b/azurerm/resource_arm_data_factory_dataset_sql_server_table.go index 454e1e7c0fc9..1278b43826d5 100644 --- a/azurerm/resource_arm_data_factory_dataset_sql_server_table.go +++ b/azurerm/resource_arm_data_factory_dataset_sql_server_table.go @@ -313,57 +313,3 @@ func resourceArmDataFactoryDatasetSQLServerTableDelete(d *schema.ResourceData, m return nil } - -// DatasetColumn describes the attributes needed to specify a structure column for a dataset -type DatasetColumn struct { - Name string `json:"name,omitempty"` - Description string `json:"description,omitempty"` - Type string `json:"type,omitempty"` -} - -func expandDataFactoryDatasetStructure(input []interface{}) interface{} { - columns := make([]DatasetColumn, 0) - for _, column := range input { - attrs := column.(map[string]interface{}) - - datasetColumn := DatasetColumn{ - Name: attrs["name"].(string), - } - if attrs["description"] != nil { - datasetColumn.Description = attrs["description"].(string) - } - if attrs["type"] != nil { - datasetColumn.Type = attrs["type"].(string) - } - columns = append(columns, datasetColumn) - } - return columns -} - -func flattenDataFactoryStructureColumns(input interface{}) []interface{} { - output := make([]interface{}, 0) - - columns, ok := input.([]interface{}) - if !ok { - return columns - } - - for _, v := range columns { - column, ok := v.(map[string]interface{}) - if !ok { - continue - } - result := make(map[string]interface{}) - if column["name"] != nil { - result["name"] = column["name"] - } - if column["type"] != nil { - result["type"] = column["type"] - } - if column["description"] != nil { - result["description"] = column["description"] - } - output = append(output, result) - } - return output -} diff --git a/website/azurerm.erb b/website/azurerm.erb index e2222b403bf5..006d603d05e7 100644 --- a/website/azurerm.erb +++ b/website/azurerm.erb @@ -732,6 +732,9 @@ > azurerm_data_factory + > + azurerm_data_factory_dataset_mysql + > azurerm_data_factory_dataset_sql_server_table diff --git a/website/docs/r/data_factory_dataset_mysql.html.markdown b/website/docs/r/data_factory_dataset_mysql.html.markdown new file mode 100644 index 000000000000..f8cac592783d --- /dev/null +++ b/website/docs/r/data_factory_dataset_mysql.html.markdown @@ -0,0 +1,91 @@ +--- +layout: "azurerm" +page_title: "Azure Resource Manager: azurerm_data_factory_dataset_mysql" +sidebar_current: "docs-azurerm-resource-data-factory-dataset-mysql" +description: |- + Manage a MySQL Dataset inside a Azure Data Factory. +--- + +# azurerm_data_factory_dataset_mysql + +Manage a MySQL Dataset inside a Azure Data Factory. + +## 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.example.name}" + data_factory_name = "${azurerm_data_factory.example.name}" + connection_string = "Server=test;Port=3306;Database=test;User=test;SSLMode=1;UseSystemTrustStore=0;Password=test" +} + +resource "azurerm_data_factory_dataset_mysql" "example" { + name = "example" + resource_group_name = "${azurerm_resource_group.example.name}" + data_factory_name = "${azurerm_data_factory.example.name}" + linked_service_name = "${azurerm_data_factory_linked_service_mysql.test.name}" +} +``` + +## Argument Reference + +The following arguments are supported: + +* `name` - (Required) Specifies the name of the Data Factory Dataset 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 Dataset MySQL. Changing this forces a new resource + +* `data_factory_name` - (Required) The Data Factory name in which to associate the Dataset with. Changing this forces a new resource. + +* `linked_service_name` - (Required) The Data Factory Linked Service name in which to associate the Dataset with. + +* `table_name` - (Optional) The table name of the Data Factory Dataset MySQL. + +* `folder` - (Optional) The folder that this Dataset is in. If not specified, the Dataset will appear at the root level. + +* `schema_column` - (Optional) A `schema_column` block as defined below. + +* `description` - (Optional) The description for the Data Factory Dataset MySQL. + +* `annotations` - (Optional) List of tags that can be used for describing the Data Factory Dataset MySQL. + +* `parameters` - (Optional) A map of parameters to associate with the Data Factory Dataset MySQL. + +* `additional_properties` - (Optional) A map of additional properties to associate with the Data Factory Dataset MySQL. + +--- + +A `schema_column` block supports the following: + +* `name` - (Required) The name of the column. + +* `type` - (Optional) Type of the column. Valid values are `Byte`, `Byte[]`, `Boolean`, `Date`, `DateTime`,`DateTimeOffset`, `Decimal`, `Double`, `Guid`, `Int16`, `Int32`, `Int64`, `Single`, `String`, `TimeSpan`. Please note these values are case sensitive. + +* `description` - (Optional) The description of the column. + + +## Attributes Reference + +The following attributes are exported: + +* `id` - The ID of the Data Factory Dataset. + +## Import + +Data Factory Dataset MySQL can be imported using the `resource id`, e.g. + +```shell +terraform import azurerm_data_factory_dataset_mysql.example /subscriptions/00000000-0000-0000-0000-000000000000/resourceGroups/example/providers/Microsoft.DataFactory/factories/example/datasets/example +``` From 60ac8a078b697ed86d611ccdcff53c2d1c1f30a4 Mon Sep 17 00:00:00 2001 From: Matthew Frahry Date: Tue, 16 Apr 2019 13:17:42 -0600 Subject: [PATCH 2/2] Address types --- azurerm/resource_arm_data_factory_dataset_mysql.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/azurerm/resource_arm_data_factory_dataset_mysql.go b/azurerm/resource_arm_data_factory_dataset_mysql.go index 8a64b79054c2..b72d7f3217b6 100644 --- a/azurerm/resource_arm_data_factory_dataset_mysql.go +++ b/azurerm/resource_arm_data_factory_dataset_mysql.go @@ -146,7 +146,7 @@ func resourceArmDataFactoryDatasetMySQLCreateOrUpdate(d *schema.ResourceData, me } if existing.ID != nil && *existing.ID != "" { - return tf.ImportAsExistsError("azurerm_data_factory_dataset_sql_server", *existing.ID) + return tf.ImportAsExistsError("azurerm_data_factory_dataset_mysql", *existing.ID) } } @@ -192,7 +192,7 @@ func resourceArmDataFactoryDatasetMySQLCreateOrUpdate(d *schema.ResourceData, me mysqlTableset.Structure = expandDataFactoryDatasetStructure(v.([]interface{})) } - datasetType := string(datafactory.TypeSQLServerTable) + datasetType := string(datafactory.TypeRelationalTable) dataset := datafactory.DatasetResource{ Properties: &mysqlTableset, Type: &datasetType, @@ -244,7 +244,7 @@ func resourceArmDataFactoryDatasetMySQLRead(d *schema.ResourceData, meta interfa mysqlTable, ok := resp.Properties.AsRelationalTableDataset() if !ok { - return fmt.Errorf("Error classifiying Data Factory Dataset MySQL %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeSQLServerTable, *resp.Type) + return fmt.Errorf("Error classifiying Data Factory Dataset MySQL %q (Data Factory %q / Resource Group %q): Expected: %q Received: %q", name, dataFactoryName, resourceGroup, datafactory.TypeRelationalTable, *resp.Type) } d.Set("additional_properties", mysqlTable.AdditionalProperties)