Is there an existing issue for this?
Community Note
- Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
- Please do not leave comments along the lines of "+1", "me too" or "any updates", they generate extra noise for issue followers and do not help prioritize the request
- If you are interested in working on this issue or have submitted a pull request, please leave a comment and review the contribution guide to help.
We are currently working on importing our Azure architecture into Terraform. The platform was build and maintained by using the Azure portal so all our resources already exists, so we need to map them.
While working on importing our SQL server and Elastic pool we were able to import the resources. But when removing the imports in our local version terraform plan crashed. As terraform had created a max_size_bytes attribute which is overflowing.
We fixed the issue by removing this variable in our remote state.
Terraform Version
v1.14.5
AzureRM Provider Version
v4.60.0
Affected Resource(s)/Data Source(s)
azurerm_mssql_elasticpool
Terraform Configuration Files
terraform.tfvars
resource_group_name = "xxx"
sql_server = {
name = "xxx"
sql_version = "12.0"
entra_group_name = "xxx"
entra_group_id = "xxx"
administrator_login = "xxx"
administrator_login_password_wo = "xxx"
express_vulnerability_assessment_enabled = true
}
sql_elasticpool = {
pool_name = "xxx-elastic-pool"
pool_size = 800
pool_min_settings = 0
pool_max_settings = 2
maintenance_configuration_name = "SQL_WestEurope_DB_2"
pool_sku = {
name = "BC_Gen5"
tier = "BusinessCritical"
family = "Gen5"
capacity = 4
}
}
variables.tf
variable "resource_group_name" {
type = string
}
variable "location" {
type = string
default = "west europe"
}
variable "sql_server" {
type = object({
name = string
sql_version = optional(string)
minimum_tls_version = optional(string)
entra_group_name = string
entra_group_id = string
administrator_login = string
administrator_login_password_wo = string
express_vulnerability_assessment_enabled = optional(bool)
tags = optional(map(string), {})
})
}
variable "sql_elasticpool" {
type = object({
pool_name = string
pool_size = number
maintenance_configuration_name = string
pool_min_settings = optional(number)
pool_max_settings = optional(number)
# mapping sub resource: azurerm_storage_container
pool_sku = object({
name = string
tier = string
family = string
capacity = number
})
})
}
module variables.tf
# sql server
variable "server_name" {
type = string
}
variable "resource_group_name" {
type = string
}
variable "location" {
type = string
default = "west europe"
}
variable "sql_version" {
type = string
default = "12.0"
}
variable "minimum_tls_version" {
type = string
default = "1.2"
}
variable "administrator_login" {
type = string
}
variable "administrator_login_password_wo" {
type = string
}
variable "entra_group_name" {
type = string
}
variable "entra_group_id" {
type = string
}
variable "express_vulnerability_assessment_enabled" {
type = bool
default = false
}
variable "tags" {
type = map(string)
default = null
}
# elasticpool
variable "pool_name" {
type = string
}
variable "pool_size" {
type = number
}
variable "pool_sku" {
type = object({
name = string
tier = string
family = string
capacity = number
})
}
variable "pool_min_settings" {
type = number
default = 0.25
}
variable "pool_max_settings" {
type = number
default = 4
}
variable "maintenance_configuration_name" {
type = string
default = "SQL_Default"
}
module main.tf
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_server.html
resource "azurerm_mssql_server" "main" {
name = var.server_name
resource_group_name = var.resource_group_name
location = var.location
version = var.sql_version
minimum_tls_version = var.minimum_tls_version
administrator_login = var.administrator_login
administrator_login_password_wo = var.administrator_login_password_wo
administrator_login_password_wo_version = 0
express_vulnerability_assessment_enabled = var.express_vulnerability_assessment_enabled
azuread_administrator {
login_username = var.entra_group_name
object_id = var.entra_group_id
}
identity {
type = "SystemAssigned"
}
tags = var.tags
}
# https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/mssql_elasticpool
resource "azurerm_mssql_elasticpool" "elasticpool" {
name = var.pool_name
resource_group_name = var.resource_group_name
location = var.location
server_name = azurerm_mssql_server.main.name
maintenance_configuration_name = var.maintenance_configuration_name
max_size_gb = var.pool_size
sku {
name = var.pool_sku.name
tier = var.pool_sku.tier
family = var.pool_sku.family
capacity = var.pool_sku.capacity
}
per_database_settings {
min_capacity = var.pool_min_settings
max_capacity = var.pool_max_settings
}
}
Debug Output/Panic Output
Planning failed. Terraform encountered an error while generating this plan.
│ Error: Plugin did not respond
│
│ with module.sql_database.azurerm_mssql_elasticpool.elasticpool,
│ on ..\..\..\modules\sql-database\main.tf line 44, in resource "azurerm_mssql_elasticpool" "elasticpool":
│ 44: resource "azurerm_mssql_elasticpool" "elasticpool" {
│
│ The plugin encountered an error, and failed to respond to the plugin.(*GRPCProvider).ReadResource call. The plugin logs may contain more details.
╵
Releasing state lock. This may take a few moments...
Stack trace from the terraform-provider-azurerm_v4.60.0_x5.exe plugin:
panic: Error reading level state: strconv.ParseInt: parsing "858993459200": value out of range
goroutine 481 [running]:
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).get(0xfd6aff0, {0xf9e4280, 0x1, 0x1}, 0x8)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.38.1/helper/schema/resource_data.go:694 +0x265
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*ResourceData).State(0xfd6aff0)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.38.1/helper/schema/resource_data.go:462 +0x487
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*Resource).ShimInstanceStateFromValue(0xf2c9d48, {{{0x84e8c40, 0xf9e40e0}}, {0x6e829e0, 0x126822c0}})
github.com/hashicorp/terraform-plugin-sdk/v2@v2.38.1/helper/schema/resource.go:741 +0x1c9
github.com/hashicorp/terraform-plugin-sdk/v2/helper/schema.(*GRPCProviderServer).ReadResource(0xee4eac0, {0x84e6e1c, 0xfc85bd8}, 0x12c13080)
github.com/hashicorp/terraform-plugin-sdk/v2@v2.38.1/helper/schema/grpc_provider.go:866 +0x682
github.com/hashicorp/terraform-plugin-mux/tf5muxserver.(*muxServer).ReadResource(0xf9a5bd0, {0x84e6e1c, 0xfc85b00}, 0x12c13080)
github.com/hashicorp/terraform-plugin-mux@v0.21.0/tf5muxserver/mux_server_ReadResource.go:35 +0x1d6
github.com/hashicorp/terraform-plugin-go/tfprotov5/tf5server.(*server).ReadResource(0xedb8050, {0x84e6e1c, 0xfc85848}, 0x12d83640)
github.com/hashicorp/terraform-plugin-go@v0.29.0/tfprotov5/tf5server/server.go:862 +0x34f
github.com/hashicorp/terraform-plugin-go/tfprotov5/internal/tfplugin5._Provider_ReadResource_Handler({0x7b200a0, 0xedb8050}, {0x84e6e1c, 0xfc85848}, 0x12d83600, 0x0)
github.com/hashicorp/terraform-plugin-go@v0.29.0/tfprotov5/internal/tfplugin5/tfplugin5_grpc.pb.go:753 +0x98
google.golang.org/grpc.(*Server).processUnaryRPC(0xe8d7048, {0x84e6e1c, 0xfc85800}, 0x12c12f60, 0xf8ee060, 0xd73ad4c, 0x0)
google.golang.org/grpc@v1.75.1/server.go:1431 +0x1019
google.golang.org/grpc.(*Server).handleStream(0xe8d7048, {0x84e8e8c, 0xfacc008}, 0x12c12f60)
google.golang.org/grpc@v1.75.1/server.go:1842 +0xe29
google.golang.org/grpc.(*Server).serveStreams.func2.1()
google.golang.org/grpc@v1.75.1/server.go:1061 +0x8a
created by google.golang.org/grpc.(*Server).serveStreams.func2 in goroutine 36
google.golang.org/grpc@v1.75.1/server.go:1072 +0x12e
Error: The terraform-provider-azurerm_v4.60.0_x5.exe plugin crashed!
This is always indicative of a bug within the plugin. It would be immensely
helpful if you could report the crash with the plugin's maintainers so that it
can be fixed. The output above should help diagnose the issue.
Expected Behaviour
$> terraform plan
module.sql_database.azurerm_mssql_server.main: Refreshing state... [id=/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Sql/servers/xxx]
module.sql_database.azurerm_mssql_elasticpool.elasticpool: Refreshing state... [id=/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Sql/servers/xxx/elasticPools/xxx]
No changes. Your infrastructure matches the configuration.
Actual Behaviour
The tfstate after the import also has a value for "max_size_bytes" which in our case is bigger then a 32 bit int, so the value overflows and Terraform crashes. In the screenshot are the values.
Steps to Reproduce
We have created both the Azure SQL server and Azure SQL elaticpool via the Azure Portal. We then imported both resources with the import {} function. And now that the state is saved, we tried removing the import from import.tf, but the state is now corrupt.
To fix the issue we removed "max_size_bytes" from our remote state, and then terraform plan worked
Important Factoids
No response
References
No response
Is there an existing issue for this?
Community Note
We are currently working on importing our Azure architecture into Terraform. The platform was build and maintained by using the Azure portal so all our resources already exists, so we need to map them.
While working on importing our SQL server and Elastic pool we were able to import the resources. But when removing the imports in our local version
terraform plancrashed. As terraform had created a max_size_bytes attribute which is overflowing.We fixed the issue by removing this variable in our remote state.
Terraform Version
v1.14.5
AzureRM Provider Version
v4.60.0
Affected Resource(s)/Data Source(s)
azurerm_mssql_elasticpool
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
$> terraform plan
module.sql_database.azurerm_mssql_server.main: Refreshing state... [id=/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Sql/servers/xxx]
module.sql_database.azurerm_mssql_elasticpool.elasticpool: Refreshing state... [id=/subscriptions/xxx/resourceGroups/xxx/providers/Microsoft.Sql/servers/xxx/elasticPools/xxx]
No changes. Your infrastructure matches the configuration.
Actual Behaviour
The tfstate after the import also has a value for "max_size_bytes" which in our case is bigger then a 32 bit int, so the value overflows and Terraform crashes. In the screenshot are the values.
Steps to Reproduce
We have created both the Azure SQL server and Azure SQL elaticpool via the Azure Portal. We then imported both resources with the import {} function. And now that the state is saved, we tried removing the import from import.tf, but the state is now corrupt.
To fix the issue we removed "max_size_bytes" from our remote state, and then terraform plan worked
Important Factoids
No response
References
No response