Search code examples
azure-sql-databaseterraform-provider-azure

How to set Azure SQL database instance with Min 0,5 vCores with Terraform?


I have Terraform and setting up Azure SQL database.

Currently Compute Hardware are defined as in Terraform:

requested_service_objective_name = "GP_S_Gen5_4"

This will configure Compute Hardware for Max vCores 4 and Min vCores 1.

I have need to configure min vCores as 0,5. If I set up 0.5 and then deploy Terraform with "GP_S_Gen5_4", I get automatically upgraded to Min vCores 1.

Is there anything I can do to configure size as 0,5 or is 1 actual min when deployed by Terraform?

enter image description here


Solution

  • There are two terraform APIs, azurerm_mssql_database and azurerm_mssql_elasticpool.

    The azurerm_mssql_database doesn't support vCore or DTU based database configuration. Only azurerm_mssql_elasticpool v3.0 API allows for vCore and DTU based configurations.

    Therefore, to declare the vCore using terraform, you need to deploy your database in Elastic Pool and use the below example code.

    resource "azurerm_mssql_elasticpool" "example" {
      name                = "test-epool"
      resource_group_name = azurerm_resource_group.example.name
      location            = azurerm_resource_group.example.location
      server_name         = azurerm_sql_server.example.name
      license_type        = "LicenseIncluded"
      max_size_gb         = 756
    
      sku {
        name     = "BasicPool"
        tier     = "Basic"
        family   = "Gen4"
        capacity = 4
      }
    
      per_database_settings {
        min_capacity = 0.25
        max_capacity = 4
      }
    }
    

    Refer azurerm_mssql_database official document here.