hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.52k stars 4.6k forks source link

sometimes, azurerm_mssql_database get the error when applying TDE #22367

Open shnmorimoto opened 1 year ago

shnmorimoto commented 1 year ago

Is there an existing issue for this?

Community Note

Terraform Version

1.4.6

AzureRM Provider Version

3.63.0

Affected Resource(s)/Data Source(s)

azurerm_mssql_database

Terraform Configuration Files

resource "azurerm_mssql_database" "main" {
  name                        = "sample"
  server_id                   = "<server id>"
  create_mode                 = "PointInTimeRestore"
  creation_source_database_id = "<database id>"
  restore_point_in_time       = timeadd(timestamp(), "-5h")
  collation                   = "Japanese_CI_AS"
  elastic_pool_id             = "<elastic pool id>"
}

Debug Output/Panic Output

│ Error: while enabling Transparent Data Encryption for "Database: (Name \"<Database Name>\" / Server Name \"<SQL Server Name>\" / Resource Group \"<Resource Group Name>\")": sql.TransparentDataEncryptionsClient#CreateOrUpdate: Failure sending request: StatusCode=409 -- Original Error: autorest/azure: Service returned an error. Status=<nil> <nil>
│
│   with azurerm_mssql_database.main,
│   on main.tf line 22, in resource "azurerm_mssql_database" "main":
│   22: resource "azurerm_mssql_database" "main" {
│
╵

Expected Behaviour

Successful creation with no errors

Actual Behaviour

Sometimes, azure api returns error when applying TDE. see Debug Output/Panic Output. On terraform, an error occurs, but the DB is created successfully. However, there is a difference on the state file. It seems to happen especially between 1 am and 5 am UTC.

Steps to Reproduce

terraform apply

Important Factoids

No response

References

No response

neil-yechenwei commented 1 year ago

Thanks for raising this issue. Before creating the PITR resource, suggest to wait at least 15 minutes until all related components are ready.

shnmorimoto commented 1 year ago

Thanks for suggestion!

It works well for my case.

iamsoorya commented 1 year ago

I have the same issue. where do we wait for 15 minutes?

shnmorimoto commented 1 year ago

In my case, the only dependency is the azurerm_mssql_elasticpool . Therefore, the following is currently working well. (3.5m works fine too.) And, you may need the time provider. https://registry.terraform.io/providers/hashicorp/time/latest/docs

resource "azurerm_mssql_elasticpool" "main" {
  name                = "sample"
  resource_group_name = "<resource group>"
  location            = "japanwest"
  server_name         = "<server name>"
  max_size_gb         = 1024

  sku {
    name     = "StandardPool"
    tier     = "Standard"
    capacity = 200
  }

  per_database_settings {
    min_capacity = 0
    max_capacity = 200
  }
}

resource "time_sleep" "main" {
  create_duration = "3.5m"

  triggers = {
    peer = azurerm_mssql_elasticpool.main.id
  }
}

resource "azurerm_mssql_database" "main" {
  name                        = "sample"
  server_id                   = "<server id>"
  create_mode                 = "PointInTimeRestore"
  creation_source_database_id = "<database id>"
  restore_point_in_time       = timeadd(timestamp(), "-5h")
  collation                   = "Japanese_CI_AS"
  elastic_pool_id             = "<elastic pool id>"

  depends_on = [
    time_sleep.main
  ]
}
iamsoorya commented 1 year ago

I do not have any dependency except the existing server.

All resources are pre-created and running.

module "PITR-SQL-DB-LGRI-ALPS" { source = "./TerraModules/18.SqlDbModule" #"../00.TerraformModules/18.SqlDbModule"
location = var.location
sqldb_name = "${var.sqldb_name_base}-${lower(random_string.random_str.result)}" sqldb_server_id = data.azurerm_mssql_server.sql_server.id sqldb_sku_name = "S2" sqldb_max_size_gb = 500 sqldb_collation = "SQL_LATIN1_GENERAL_CP1_CS_AS" sqldb_readscale = false st_account_type = "Local" zone_redundant = false sqldb_retention_days = 35 sqldb_create_mode = "PointInTimeRestore" sqldb_restore_point_in_time = var.src_pitr sqldb_creation_source_database_id = var.src_db_id tags_common = local.tags_sql }

Netkracker commented 1 year ago

We at @swisspost miss the possibility to use TDE reliably, without having to include an delay after sql server creation.

are there any news on this ?

TechnicallyJoe commented 7 months ago

Still happening here. Only setting up a mssql_server and a mssql_database. No other dependencies.

Any progress?