claranet / terraform-azurerm-db-sql

Terraform module composition (feature) for Azure SQL Database (SQLServer based)
Apache License 2.0
14 stars 12 forks source link

Error with the value creation_source_database_id when create_mode = "c" Secondary [BUG] #3

Open amine7777 opened 1 year ago

amine7777 commented 1 year ago

Community Note

Terraform Version

1.4.6

AzureRM Provider Version

3.55.0

Affected Resource(s)/Data Source(s)

azurerm_mssql_server

Terraform Configuration Files

databases = [
    {
      name                        = "db1"
      max_size_gb                 = null
      create_mode                 = "c" 
      creation_source_database_id = "/subscriptions/...."
      read_replica_count          = 1
    }]

Debug Output/Panic Output

│ Error: 'creation_source_database_id' is required for create_mode Secondary

Expected Behaviour

The terraform should take the value "/subscriptions/...." of the key creation_source_database_id Since create_mode = "c" then the variable in the module doesn't provide the right value.

creation_source_database_id = can(regex("Copy|Secondary|PointInTimeRestore|Recovery|RestoreExternalBackup|Restore|RestoreExternalBackupSecondary", each.value.create_mode)) ? each.value.creation_source_database_id : null

It should be instead this

creation_source_database_id = can(regex("Copy|Secondary|PointInTimeRestore|Recovery|RestoreExternalBackup|Restore|RestoreExternalBackupSecondary", lookup(local.standard_allowed_create_mode, each.value.create_mode))) ? each.value.creation_source_database_id : null

I think it needs to be in this variable as well max_size_gb because it has the same logic I have succeeded to deploy this and it worked..

Actual Behaviour

No response

Steps to Reproduce

No response

Important Factoids

No response

References

No response

Shr3ps commented 1 year ago

Hello @amine7777

Thanks for your issue, do you think you can open a Pull-request with the fix you tested?