Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Jun 30, 2022
1 parent 742f353 commit 0205f87
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 22 deletions.
8 changes: 4 additions & 4 deletions internal/services/mssql/mssql_server_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -150,6 +150,7 @@ func resourceMsSqlServer() *pluginsdk.Resource {
"1.0",
"1.1",
"1.2",
"Disabled",
}, false),
},

Expand Down Expand Up @@ -257,7 +258,7 @@ func resourceMsSqlServerCreate(d *pluginsdk.ResourceData, meta interface{}) erro
props.ServerProperties.RestrictOutboundNetworkAccess = sql.ServerNetworkAccessFlagEnabled
}

if v := d.Get("minimum_tls_version"); v.(string) != "" {
if v := d.Get("minimum_tls_version"); v.(string) != "Disabled" {
props.ServerProperties.MinimalTLSVersion = utils.String(v.(string))
}

Expand Down Expand Up @@ -347,7 +348,7 @@ func resourceMsSqlServerUpdate(d *pluginsdk.ResourceData, meta interface{}) erro
props.ServerProperties.AdministratorLoginPassword = utils.String(adminPassword)
}

if v := d.Get("minimum_tls_version"); v.(string) != "" {
if v := d.Get("minimum_tls_version"); v.(string) != "Disabled" {
props.ServerProperties.MinimalTLSVersion = utils.String(v.(string))
}

Expand Down Expand Up @@ -467,7 +468,6 @@ func resourceMsSqlServerRead(d *pluginsdk.ResourceData, meta interface{}) error
d.Set("version", props.Version)
d.Set("administrator_login", props.AdministratorLogin)
d.Set("fully_qualified_domain_name", props.FullyQualifiedDomainName)
d.Set("minimum_tls_version", props.MinimalTLSVersion)
d.Set("public_network_access_enabled", props.PublicNetworkAccess == sql.ServerNetworkAccessFlagEnabled)
d.Set("outbound_network_restriction_enabled", props.RestrictOutboundNetworkAccess == sql.ServerNetworkAccessFlagEnabled)
primaryUserAssignedIdentityID := ""
Expand Down Expand Up @@ -682,7 +682,7 @@ func flattenSqlServerRestorableDatabases(resp sql.RestorableDroppedDatabaseListR

func msSqlMinimumTLSVersionDiff(ctx context.Context, d *pluginsdk.ResourceDiff, _ interface{}) (err error) {
old, new := d.GetChange("minimum_tls_version")
if old != "" && new == "" {
if old != "" && old != "Disabled" && new == "Disabled" {
err = fmt.Errorf("`minimum_tls_version` cannot be removed once set, please set a valid value for this property")
}
return
Expand Down
74 changes: 58 additions & 16 deletions internal/services/mssql/mssql_server_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ func TestAccMsSqlServer_basic(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand All @@ -41,7 +41,22 @@ func TestAccMsSqlServer_complete(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

func TestAccMsSqlServer_minimumTLSVersionDisabled(t *testing.T) {
data := acceptance.BuildTestData(t, "azurerm_mssql_server", "test")
r := MsSqlServerResource{}

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

Expand Down Expand Up @@ -71,28 +86,28 @@ func TestAccMsSqlServer_update(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
{
Config: r.complete(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
{
Config: r.completeUpdate(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
{
Config: r.basicWithMinimumTLSVersion(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand All @@ -107,7 +122,7 @@ func TestAccMsSqlServer_systemAssignedIdentity(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand All @@ -122,7 +137,7 @@ func TestAccMsSqlServer_userAssignedIdentity(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand All @@ -137,7 +152,7 @@ func TestAccMsSqlServer_azureadAdmin(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand All @@ -152,28 +167,28 @@ func TestAccMsSqlServer_azureadAdminUpdate(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
{
Config: r.aadAdmin(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
{
Config: r.basic(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
{
Config: r.aadAdminWithAADAuthOnly(data),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand All @@ -188,7 +203,7 @@ func TestAccMsSqlServer_azureadAdminWithAADAuthOnly(t *testing.T) {
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand All @@ -203,14 +218,14 @@ func TestAccMsSqlServer_updateAzureadAuthenticationOnlyWithIdentity(t *testing.T
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
{
Config: r.updateAzureadAuthenticationOnlyWithIdentity(data, true),
Check: acceptance.ComposeTestCheckFunc(
check.That(data.ResourceName).ExistsInAzure(r),
),
},
data.ImportStep("administrator_login_password"),
data.ImportStep("administrator_login_password", "minimum_tls_version"),
})
}

Expand Down Expand Up @@ -255,6 +270,33 @@ resource "azurerm_mssql_server" "test" {
`, data.RandomInteger, data.Locations.Primary)
}

func (MsSqlServerResource) basicWithMinimumTLSVersionDisabled(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
features {}
}
resource "azurerm_resource_group" "test" {
name = "acctestRG-mssql-%[1]d"
location = "%[2]s"
}
resource "azurerm_mssql_server" "test" {
name = "acctestsqlserver%[1]d"
resource_group_name = azurerm_resource_group.test.name
location = azurerm_resource_group.test.location
version = "12.0"
administrator_login = "missadministrator"
administrator_login_password = "thisIsKat11"
minimum_tls_version = "Disabled"
identity {
type = "SystemAssigned"
}
}
`, data.RandomInteger, data.Locations.Primary)
}

func (MsSqlServerResource) basicWithMinimumTLSVersion(data acceptance.TestData) string {
return fmt.Sprintf(`
provider "azurerm" {
Expand Down
4 changes: 2 additions & 2 deletions website/docs/r/mssql_server.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -63,9 +63,9 @@ The following arguments are supported:

* `identity` - (Optional) An `identity` block as defined below.

* `minimum_tls_version` - (Optional) The Minimum TLS Version for all SQL Database and SQL Data Warehouse databases associated with the server. Valid values are: `1.0`, `1.1` and `1.2`.
* `minimum_tls_version` - (Optional) The Minimum TLS Version for all SQL Database and SQL Data Warehouse databases associated with the server. Valid values are: `1.0`, `1.1` , `1.2` and `Disabled`. Defaults to `1.2`.

~> **NOTE:** Once `minimum_tls_version` is set it is not possible to remove this setting and must be given a valid value for any further updates to the resource.
~> **NOTE:** The `minimum_tls_version` is set to `Disabled` means all TLS versions are allowed. After you enforce a version of `minimum_tls_version`, it's not possible to revert to `Disabled`.

* `public_network_access_enabled` - (Optional) Whether public network access is allowed for this server. Defaults to `true`.

Expand Down

0 comments on commit 0205f87

Please sign in to comment.