Having a hard time figuring out how to create an A...
# azure
a
Having a hard time figuring out how to create an Azure SQL Database by importing a bacpac file stored in a storage account. The Azure API has an endpoint for that: https://learn.microsoft.com/en-us/rest/api/sql/2022-05-01-preview/databases/import?tabs=HTTP Which is different than the create/update endpoint: https://learn.microsoft.com/en-us/rest/api/sql/2022-05-01-preview/databases/create-or-update?tabs=HTTP I'm using Python and have tried: •
pulumi_azure_native
◦ 1.103.0 ◦ 2.0.0b2 • Providing a blob URI to different parameters on
sql.Database
but those only accept Azure resource IDs ◦
source_database_id
source_resource_id
• Multiple Azure API versions Furthermore, searching for the specific parameter names exposed by the
/import
endpoint in the
pulumi_azure_native.sql
module didn't give me anything: • storageKey / storage_key • storageUri / storage_uri • blobUri / blob_uri Is this API not represented in the SDK or do you know how to go about using
sql.Database
to do this?
r
I needed to solve a similar problem a while back and could not find a way to do what you describe (C# azure-native). What I ended up doing instead was creating an Azure database from the bapac manually, and using it as a source like you already pointed out. It seems that cloning speed is not related to database tier, so you can get away with a very cheap instance.
One workaround (although complicated) I can think of is a solution with a storage account, poweshell/other script and container instances. If you upload your bacpac to a storage account you should be able to mount it in a container instance together with a script that could run your database import/creation
i
I’d consider using Pulumi to manage the DB / infra itself, but use some other script/automation to orchestrate loading the data into the database (CI/CD, etc)).
a
@icy-doctor-13719 @rapid-engineer-94232 - Yeah I ended up spinning up an empty Azure SQL DB with Pulumi and then restored the bacpac with a script using the
sqlpackage
cli. There's a caveat though, as bacpac imports have to be done during the initial provisioning of the DB as it has to be completely empty. The workaround to be able to restore from bacpac on a newly/already provisioned Azure SQL DB, as described here, is to drop all triggers, procedures, functions, tables, views etc. before running the sqlpackage bacpac import. A bit hacky IMO but worked out ok...