Home > OS >  restore Azure SQL to poin-in-time using Terraform?
restore Azure SQL to poin-in-time using Terraform?

Time:12-07

I have an Azure SQL Database in test and QA environment that we constantly have to restore from point-in-time backup from pre-production environment.

Is it possible to automate the process using Terraform?

Thank you

CodePudding user response:

You can use Create mode = PointInTimeRestore and then specify the creation_source_database_id which is the reference database resource id & restore_point_in_time which will be the point in time in ISO8601 format of the source database that will be restored to create the new database.

With the basic requirement the azurerm_mssql_database block will be something like below , you can modify it with other parameters as per your requirement:

resource "azurerm_mssql_database" "sql_db" {
  name                        = var.name
  server_id                   = var.server_id
  collation                   = var.collation
  license_type                = "BasePrice"
  max_size_gb                 = var.max_size_gb
  read_scale                  = var.read_scale
  sku_name                    = var.sku_name
  zone_redundant              = var.zone_redundant
  auto_pause_delay_in_minutes = var.auto_pause_delay_in_minutes
  create_mode                 = "PointInTimeRestore"
  creation_source_database_id = var.creation_source_database_id
  min_capacity                = var.min_capacity
  restore_point_in_time       = "2021-12-06T01:57:37Z"
}

Reference :

Terraform Registry

  • Related