Skip to content

Commit

Permalink
update code
Browse files Browse the repository at this point in the history
  • Loading branch information
sinbai committed Dec 18, 2024
1 parent d5f2908 commit cd74e7e
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 8 deletions.
9 changes: 5 additions & 4 deletions internal/services/mssql/mssql_database_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -1894,18 +1894,19 @@ func resourceMsSqlDatabaseSchema() map[string]*pluginsdk.Schema {
}

func calculateMaxSizeBytes(v float64) (*int64, error) {
maxSizeBytes := int64(0)
var maxSizeBytes int64
integer := isPositiveInteger(v)
if integer {
maxSizeBytes = int64(math.Round(v)) * 1073741824
} else {
// When `max_size_gb` is below 1GB, the API only accepts 100MB and 500MB. 100MB is 104857600, and 500MB is 524288000.
// Since 100MB != 0.1 * 1073741824 and 500MB != 0.5 * 1073741824, directly specify the Bytes when `max_size_gb` is specified `0.1` or `0.5`.
if int64(math.Round(v*10)) == 1 {
switch int64(math.Round(v * 10)) {
case 1:
maxSizeBytes = 104857600
} else if int64(math.Round(v*10)) == 5 {
case 5:
maxSizeBytes = 524288000
} else {
default:
return nil, fmt.Errorf("`max_size_gb` allows `0.1`, `0.5` and positive integers greater than or equal to 1")
}
}
Expand Down
8 changes: 4 additions & 4 deletions internal/services/mssql/mssql_database_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2409,10 +2409,10 @@ func (r MsSqlDatabaseResource) maxSizeGB(data acceptance.TestData, maxSizeGb flo
%[1]s
resource "azurerm_mssql_database" "test" {
name = "acctest-db-%[2]d"
server_id = azurerm_mssql_server.test.id
sku_name = "Basic"
max_size_gb = %[3]f
name = "acctest-db-%[2]d"
server_id = azurerm_mssql_server.test.id
sku_name = "Basic"
max_size_gb = %[3]f
}
`, r.template(data), data.RandomInteger, maxSizeGb)
}

0 comments on commit cd74e7e

Please sign in to comment.