https://pulumi.com logo
#general
Title
# general
a

adorable-analyst-27426

07/03/2023, 8:30 AM
does anyone know how to avoid to delete database and bypass the error
azure-native:sql:Database (xxxx-api-sql-db):
error: Preview failed: refusing to delete protected resource 'urn:pulumi:xxxx-apixxazure-native:sql:Database::xxxx-api-sql-db'
l

little-cartoon-10569

07/03/2023, 8:57 AM
You need to remove the protected flag. Put the code back, so that the resource isn't being deleted. Remove the protected flag. Run
pulumi up
. Then you can delete the resource in the normal way.
e

echoing-dinner-19531

07/03/2023, 10:22 AM
You can also use
pulumi state unprotect
a

adorable-analyst-27426

07/03/2023, 10:44 AM
removing the flag will wipes out the datbase right, which is not desired.
e

echoing-dinner-19531

07/03/2023, 10:46 AM
Oh you want to add the RetainOnDelete resource property
a

adorable-analyst-27426

07/03/2023, 10:46 AM
@little-cartoon-10569 @echoing-dinner-19531 is there a way not removing the database and the pulumi accept the change code as its const database = azure.sql.Database.get(mi`sql-db`, { databaseName: mi`sql-db`, resourceGroupName, location, serverName: server.name, sku: envDBSku, autoPauseDelay: serverless ? 60 : undefined, readScale: serverless ? 'Disabled' : 'Enabled', highAvailabilityReplicaCount: 0, });
e

echoing-dinner-19531

07/03/2023, 10:47 AM
If you've already removed it from the code, and don't want it actually delete you could just rm it from state (
pulumi state delete
)
a

adorable-analyst-27426

07/03/2023, 10:48 AM
what could be the value of it, `const database = azure.sql.Database(mi`sql-db`, {` `databaseName: mi`sql-db`,`
resourceGroupName,
location,
serverName: server.name,
sku: envDBSku,
autoPauseDelay: serverless ? 60 : undefined,
readScale: serverless ? 'Disabled' : 'Enabled',
highAvailabilityReplicaCount: 0,
}, {
retainOnDelete: true
});
or can we use something like so, rather creating database, getting the database : `const database = azure.sql.Database.get(mi`sql-db`, {` `name: mi`sql-db`,`
resourceGroupName,
serverName: server.name,
});
e

echoing-dinner-19531

07/03/2023, 10:55 AM
Either, sometimes you want the stack to create the database but just not delete it, sometimes something else should have created it and you just need to get it.
a

adorable-analyst-27426

07/03/2023, 10:56 AM
you are right, i am looking to get it rather than creatign it
what is the best option using typescript
e

echoing-dinner-19531

07/03/2023, 11:09 AM
Probably just using
get
as above then
12 Views