Skip to content

Commit

Permalink
Allow UTF-8 characters in SQL pool name (#13289)
Browse files Browse the repository at this point in the history
This pull request updates the validation logic associated with Synapse SQL pool names to support UTF-8 characters and other non-alphanumeric characters that are supported by Azure.

Fixes: #11554

Output from acceptance testing:
  • Loading branch information
owenfarrell authored Sep 9, 2021
1 parent 03f6b13 commit 9c0d2f8
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 8 deletions.
33 changes: 33 additions & 0 deletions internal/services/synapse/synapse_sql_pool_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,21 @@ func TestAccSynapseSqlPool_basic(t *testing.T) {
})
}

func TestAccSynapseSqlPool_utf8(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_synapse_sql_pool", "test")
r := SynapseSqlPoolResource{}

data.ResourceTest(t, r, []acceptance.TestStep{
{
Config: r.utf8(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep(),
})
}

func TestAccSynapseSqlPool_requiresImport(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_synapse_sql_pool", "test")
r := SynapseSqlPoolResource{}
Expand Down Expand Up @@ -124,6 +139,24 @@ resource "azurerm_synapse_sql_pool" "test" {
`, template, data.RandomString)
}

func (r SynapseSqlPoolResource) utf8(data acceptance.TestData) string {
template := r.template(data)
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
%s
resource "azurerm_synapse_sql_pool" "test" {
name = "販売管理"
synapse_workspace_id = azurerm_synapse_workspace.test.id
sku_name = "DW100c"
create_mode = "Default"
}
`, template)
}

func (r SynapseSqlPoolResource) requiresImport(data acceptance.TestData) string {
config := r.basic(data)
return fmt.Sprintf(`
Expand Down
8 changes: 4 additions & 4 deletions internal/services/synapse/validate/sql_pool_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,10 +13,10 @@ func SqlPoolName(i interface{}, k string) (warnings []string, errors []error) {
}

// The name attribute rules are :
// 1. can contain only letters, numbers and underscore.
// 2. The value must be between 1 and 15 characters long

if !regexp.MustCompile(`^[a-zA-Z_\d]{1,15}$`).MatchString(v) {
// 1. can't contain '<,>,*,%,&,:,\,/,?,@,-' or control characters
// 2. can't end with '.' or ' '
// 3. The value must be between 1 and 60 characters long
if !regexp.MustCompile(`^[^<>*%&:\\\/?@-]{0,59}[^\s.<>*%&:\\\/?@-]$`).MatchString(v) {
errors = append(errors, fmt.Errorf("%s can contain only letters, numbers or underscore, The value must be between 1 and 15 characters long", k))
return
}
Expand Down
23 changes: 19 additions & 4 deletions internal/services/synapse/validate/sql_pool_name_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -19,19 +19,34 @@ func TestSqlPoolName(t *testing.T) {
input: "aBc_123",
expected: true,
},
{
// UTF-8
input: "販売管理",
expected: true,
},
{
// can't contain hyphen
input: "ab-c",
expected: false,
},
{
// 15 chars
input: "abcdefghijklmno",
// can't end with .
input: "abc.",
expected: false,
},
{
// can't end with space
input: "abc ",
expected: false,
},
{
// 60 chars
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefgh",
expected: true,
},
{
// 16 chars
input: "abcdefghijklmnop",
// 61 chars
input: "abcdefghijklmnopqrstuvwxyzabcdefghijklmnopqrstuvwxyzabcdefghi",
expected: false,
},
}
Expand Down

0 comments on commit 9c0d2f8

Please sign in to comment.