Skip to content

Commit

Permalink
refactor & clean code
Browse files Browse the repository at this point in the history
  • Loading branch information
ziyeqf committed Oct 11, 2022
1 parent 334f407 commit c809666
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 13 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@ package datafactory
import (
"fmt"
"regexp"
"strings"
"time"

"github.com/Azure/azure-sdk-for-go/services/datafactory/mgmt/2018-06-01/datafactory"
Expand Down Expand Up @@ -231,11 +230,13 @@ func resourceDataFactoryIntegrationRuntimeAzureSsis() *pluginsdk.Resource {
"BC_Gen5_2", "BC_Gen5_4", "BC_Gen5_6", "BC_Gen5_8", "BC_Gen5_10", "BC_Gen5_12", "BC_Gen5_14", "BC_Gen5_16", "BC_Gen5_18", "BC_Gen5_20", "BC_Gen5_24", "BC_Gen5_32", "BC_Gen5_40", "BC_Gen5_80",
"HS_Gen5_2", "HS_Gen5_4", "HS_Gen5_6", "HS_Gen5_8", "HS_Gen5_10", "HS_Gen5_12", "HS_Gen5_14", "HS_Gen5_16", "HS_Gen5_18", "HS_Gen5_20", "HS_Gen5_24", "HS_Gen5_32", "HS_Gen5_40", "HS_Gen5_80",
}, false),
ConflictsWith: []string{"catalog_info.0.elastic_pool_name"},
},
"elastic_pool_name": {
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: sqlValidate.ValidateMsSqlElasticPoolName,
Type: pluginsdk.TypeString,
Optional: true,
ValidateFunc: sqlValidate.ValidateMsSqlElasticPoolName,
ConflictsWith: []string{"catalog_info.0.pricing_tier"},
},
"dual_standby_pair_name": {
Type: pluginsdk.TypeString,
Expand Down Expand Up @@ -645,9 +646,10 @@ func expandDataFactoryIntegrationRuntimeAzureSsisProperties(d *pluginsdk.Resourc
if catalogInfos, ok := d.GetOk("catalog_info"); ok && len(catalogInfos.([]interface{})) > 0 {
catalogInfo := catalogInfos.([]interface{})[0].(map[string]interface{})

// the property `elastic_pool_name` and `pricing_tier` share the same prop `CatalogPricingTier` in request and response.
var pricingTier datafactory.IntegrationRuntimeSsisCatalogPricingTier
if elasticPoolName := catalogInfo["elastic_pool_name"]; elasticPoolName != nil && elasticPoolName.(string) != "" {
pricingTier = datafactory.IntegrationRuntimeSsisCatalogPricingTier(expandDataFactoryIntegrationRuntimeElasticPool(elasticPoolName.(string)))
pricingTier = datafactory.IntegrationRuntimeSsisCatalogPricingTier(formatDataFactoryIntegrationRuntimeElasticPool(elasticPoolName.(string)))
} else {
pricingTier = datafactory.IntegrationRuntimeSsisCatalogPricingTier(catalogInfo["pricing_tier"].(string))
}
Expand Down Expand Up @@ -884,11 +886,8 @@ func flattenDataFactoryIntegrationRuntimeAzureSsisCatalogInfo(ssisProperties *da
}

var pricingTier, elasticPoolName string
if strings.HasPrefix(string(ssisProperties.CatalogPricingTier), "ELASTIC_POOL") {
if result := regexp.MustCompile(`(?:name=\")([^&%\\\/?]{0,127}[^\s.&%\\\/?])(?:\")`).FindStringSubmatch(string(ssisProperties.CatalogPricingTier)); len(result) > 1 {
elasticPoolName = result[1]
}
} else {
elasticPoolName, elasticPoolNameMatched := parseDataFactoryIntegrationRuntimeElasticPool(string(ssisProperties.CatalogPricingTier))
if !elasticPoolNameMatched {
pricingTier = string(ssisProperties.CatalogPricingTier)
}

Expand Down Expand Up @@ -1136,6 +1135,14 @@ func readBackSensitiveValue(input []interface{}, propertyName string, filters ma
return ""
}

func expandDataFactoryIntegrationRuntimeElasticPool(input string) string {
func formatDataFactoryIntegrationRuntimeElasticPool(input string) string {
return fmt.Sprintf(`ELASTIC_POOL(name="%s")`, input)
}

func parseDataFactoryIntegrationRuntimeElasticPool(input string) (string, bool) {
matches := regexp.MustCompile(`^ELASTIC_POOL\(name="(.+)"\)$`).FindStringSubmatch(input)
if len(matches) != 2 {
return "", false
}
return matches[1], true
}
Original file line number Diff line number Diff line change
Expand Up @@ -79,9 +79,9 @@ A `catalog_info` block supports the following:

* `administrator_password` - (Optional) Administrator login password for the SQL Server.

* `pricing_tier` - (Optional) Pricing tier for the database that will be created for the SSIS catalog. Valid values are: `Basic`, `S0`, `S1`, `S2`, `S3`, `S4`, `S6`, `S7`, `S9`, `S12`, `P1`, `P2`, `P4`, `P6`, `P11`, `P15`, `GP_S_Gen5_1`, `GP_S_Gen5_2`, `GP_S_Gen5_4`, `GP_S_Gen5_6`, `GP_S_Gen5_8`, `GP_S_Gen5_10`, `GP_S_Gen5_12`, `GP_S_Gen5_14`, `GP_S_Gen5_16`, `GP_S_Gen5_18`, `GP_S_Gen5_20`, `GP_S_Gen5_24`, `GP_S_Gen5_32`, `GP_S_Gen5_40`, `GP_Gen5_2`, `GP_Gen5_4`, `GP_Gen5_6`, `GP_Gen5_8`, `GP_Gen5_10`, `GP_Gen5_12`, `GP_Gen5_14`, `GP_Gen5_16`, `GP_Gen5_18`, `GP_Gen5_20`, `GP_Gen5_24`, `GP_Gen5_32`, `GP_Gen5_40`, `GP_Gen5_80`, `BC_Gen5_2`, `BC_Gen5_4`, `BC_Gen5_6`, `BC_Gen5_8`, `BC_Gen5_10`, `BC_Gen5_12`, `BC_Gen5_14`, `BC_Gen5_16`, `BC_Gen5_18`, `BC_Gen5_20`, `BC_Gen5_24`, `BC_Gen5_32`, `BC_Gen5_40`, `BC_Gen5_80`, `HS_Gen5_2`, `HS_Gen5_4`, `HS_Gen5_6`, `HS_Gen5_8`, `HS_Gen5_10`, `HS_Gen5_12`, `HS_Gen5_14`, `HS_Gen5_16`, `HS_Gen5_18`, `HS_Gen5_20`, `HS_Gen5_24`, `HS_Gen5_32`, `HS_Gen5_40` and `HS_Gen5_80`. (Mutually exclusive with `elastic_pool_name`.)
* `pricing_tier` - (Optional) Pricing tier for the database that will be created for the SSIS catalog. Valid values are: `Basic`, `S0`, `S1`, `S2`, `S3`, `S4`, `S6`, `S7`, `S9`, `S12`, `P1`, `P2`, `P4`, `P6`, `P11`, `P15`, `GP_S_Gen5_1`, `GP_S_Gen5_2`, `GP_S_Gen5_4`, `GP_S_Gen5_6`, `GP_S_Gen5_8`, `GP_S_Gen5_10`, `GP_S_Gen5_12`, `GP_S_Gen5_14`, `GP_S_Gen5_16`, `GP_S_Gen5_18`, `GP_S_Gen5_20`, `GP_S_Gen5_24`, `GP_S_Gen5_32`, `GP_S_Gen5_40`, `GP_Gen5_2`, `GP_Gen5_4`, `GP_Gen5_6`, `GP_Gen5_8`, `GP_Gen5_10`, `GP_Gen5_12`, `GP_Gen5_14`, `GP_Gen5_16`, `GP_Gen5_18`, `GP_Gen5_20`, `GP_Gen5_24`, `GP_Gen5_32`, `GP_Gen5_40`, `GP_Gen5_80`, `BC_Gen5_2`, `BC_Gen5_4`, `BC_Gen5_6`, `BC_Gen5_8`, `BC_Gen5_10`, `BC_Gen5_12`, `BC_Gen5_14`, `BC_Gen5_16`, `BC_Gen5_18`, `BC_Gen5_20`, `BC_Gen5_24`, `BC_Gen5_32`, `BC_Gen5_40`, `BC_Gen5_80`, `HS_Gen5_2`, `HS_Gen5_4`, `HS_Gen5_6`, `HS_Gen5_8`, `HS_Gen5_10`, `HS_Gen5_12`, `HS_Gen5_14`, `HS_Gen5_16`, `HS_Gen5_18`, `HS_Gen5_20`, `HS_Gen5_24`, `HS_Gen5_32`, `HS_Gen5_40` and `HS_Gen5_80`. Mutually exclusive with `elastic_pool_name`.

* `elastic_pool_name` - (Optional) the name of SQL elastic pool where the database will be created for the SSIS catalog. (Mutually exclusive with `pricing_tier`.)
* `elastic_pool_name` - (Optional) the name of SQL elastic pool where the database will be created for the SSIS catalog. Mutually exclusive with `pricing_tier`.

* `dual_standby_pair_name` - (Optional) The dual standby Azure-SSIS Integration Runtime pair with SSISDB failover.

Expand Down

0 comments on commit c809666

Please sign in to comment.