Open Aeropher opened 5 months ago
Hi @Aeropher thanks for opening this issue. However, I would like to clarify that Terraform implements CRUD management of azure resources through the Azure Rest API. The above error is actually returned by Azure Rest API, not Terraform.
For more details, please refer to the logs below extracted from TF Log after running "terraform apply -replace='azurerm_mssql_database.mynew-db' --auto-approve".
AzureRM Request:
DELETE /subscriptions/"redacted"/resourceGroups/exampleRG25621-0416/providers/Microsoft.Sql/servers/sqlserver-25621-0416/databases/mynew_testdb?api-version=2023-02-01-preview HTTP/1.1
Host: management.azure.com
User-Agent: HashiCorp/go-azure-sdk (Go-http-Client/1.1 databases/2023-02-01-preview) HashiCorp Terraform/1.6.5 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/3.99.0 pid-222c6c49-1b0a-5959-a213-6608f9eb8820
Content-Type: application/json; charset=utf-8
X-Ms-Correlation-Request-Id: 1a1ad13e-5dca-2dc2-091d-6cb86bfa0110
Accept-Encoding: gzip: timestamp="2024-04-16T15:45:57.660+0800"
AzureRM Response:
HTTP/2.0 202 Accepted
...
{"operation":"DropLogicalDatabase","startTime":"2024-04-16T07:46:00.197Z"}: timestamp="2024-04-16T15:46:00.489+0800"
AzureRM Request:
GET /subscriptions/"redacted"/resourceGroups/exampleRG25621-0416/providers/Microsoft.Sql/servers/sqlserver-25621-0416/databases/mynew_testdb?api-version=2023-02-01-preview HTTP/1.1
AzureRM Response:
HTTP/2.0 404 Not Found
...
{"error":{"code":"ResourceNotFound","message":"The requested resource of type 'Microsoft.Sql/servers/databases' with name 'mynew_testdb' was not found."}}: timestamp="2024-04-16T15:46:12.429+0800"
AzureRM Request:
GET /subscriptions/"redacted"/resourceGroups/exampleRG25621-0416/providers/Microsoft.Sql/servers/sqlserver-25621-0416/databases/mynew_testdb/replicationLinks?api-version=2021-02-01-preview HTTP/1.1
AzureRM Response:
HTTP/2.0 200 OK
...
{"value":[]}: timestamp="2024-04-16T15:46:17.131+0800"
AzureRM Request:
PUT /subscriptions/"redacted"/resourceGroups/exampleRG25621-0416/providers/Microsoft.Sql/servers/sqlserver-25621-0416/databases/mynew_testdb?api-version=2023-02-01-preview HTTP/1.1
Host: management.azure.com
User-Agent: HashiCorp/go-azure-sdk (Go-http-Client/1.1 databases/2023-02-01-preview) HashiCorp Terraform/1.6.5 (+https://www.terraform.io) Terraform Plugin SDK/2.10.1 terraform-provider-azurerm/3.99.0 pid-222c6c49-1b0a-5959-a213-6608f9eb8820
Content-Length: 613
Content-Type: application/json; charset=utf-8
X-Ms-Correlation-Request-Id: 1a1ad13e-5dca-2dc2-091d-6cb86bfa0110
Accept-Encoding: gzip
{"location":"eastus2","properties":{"autoPauseDelay":60,"collation":"SQL_Latin1_General_CP1_CI_AS","createMode":"Default","elasticPoolId":"","encryptionProtectorAutoRotation":false,"highAvailabilityReplicaCount":0,"isLedgerOn":false,"licenseType":"","maintenanceConfigurationId":"/subscriptions/"redacted"/providers/Microsoft.Maintenance/publicMaintenanceConfigurations/SQL_Default","maxSizeBytes":32212254720,"minCapacity":1,"readScale":"Disabled","requestedBackupStorageRedundancy":"Geo","sampleName":"","secondaryType":"","zoneRedundant":false},"sku":{"name":"GP_S_Gen5_8"},"tags":{}}: timestamp="2024-04-16T15:46:17.132+0800"
AzureRM Response:
HTTP/2.0 202 Accepted
...
{"operation":"CreateLogicalDatabase","startTime":"2024-04-16T07:46:19.22Z"}: timestamp="2024-04-16T15:46:19.351+0800"
AzureRM Request:
GET /subscriptions/"redacted"/resourceGroups/exampleRG25621-0416/providers/Microsoft.Sql/locations/eastus2/databaseAzureAsyncOperation/355517da-b363-4963-b66d-14e61bf7aa7b?api-version=2023-02-01-preview&t=... HTTP/1.1
AzureRM Response:
HTTP/2.0 200 OK
...
{"name":"355517da-b363-4963-b66d-14e61bf7aa7b","status":"Succeeded","startTime":"2024-04-16T07:46:19.22Z"}: timestamp="2024-04-16T15:47:26.376+0800"
AzureRM Request:
GET /subscriptions/"redacted"/resourceGroups/exampleRG25621-0416/providers/Microsoft.Sql/servers/sqlserver-25621-0416/databases/mynew_testdb?api-version=2023-02-01-preview HTTP/1.1
AzureRM Response:
HTTP/2.0 404 Not Found
...
{"error":{"code":"ResourceNotFound","message":"The Resource 'Microsoft.Sql/servers/sqlserver-25621-0416/databases/mynew_testdb' under resource group 'exampleRG25621-0416' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"}}: timestamp="2024-04-16T15:47:27.413+0800"
In step 5, the status information that mynew_testdb
was successfully re-created in step 4 has been returned. However, when getting mynew_testdb
in step 6, the API returns that the mynew_testdb
created again in step 4 does not exist. I assume that this is an Azure Rest API issue. It is recommended that you could create an issue in this repository to report the issue.
Hi, thanks so much for looking into this. So I have a few questions to make sure I am understanding this correctly.
I notice that after the initial DELETE there are 2 GET requests (steps 2&3). I assume these are the polling requests that check to see if the delete was successful. I also notice that there are 2 GET requests after the PUT request (steps 5&6) which I assume are to check to see if the creation of the database was successful.
So I can see that if the 1st GET (step 5) after the PUT is successful then one would think that the 2nd GET (step 6) would also be successful then fails which points to an issue with the Azure Response.
1) How come we do 2 GET requests and what do they do? I think I would need to spell this out in a bug report in the other repo.
2) Should we not keep making the second request until it is either successful or until we hit the timeout?
3) To be fair I think this might be a separate bug but I think the timeouts are not being respected in the logic around these API calls, is that the case?
4) How did you get those logs, they looks so useful!
Is there an existing issue for this?
Community Note
Terraform Version
1.8.0
AzureRM Provider Version
3.99.0
Affected Resource(s)/Data Source(s)
azurerm_mssql_database
Terraform Configuration Files
Debug Output/Panic Output
Expected Behaviour
Terraform will delete the resource and then create it again.
Terraform custom timeouts will be honoured.
Actual Behaviour
Steps to Reproduce
Using the terraform CLI in PowerShell or CMD, create the resources so that they already exist:
terraform apply --auto approve
Once the database resource exists run the Terraform replace command line and reference the terraform ID of the resource to replace. If you have an index in your resource ID then you must provide the quotes and escape them with a \ character. If using the code provided above then this will work:
"terraform apply -replace='azurerm_mssql_database.mynew-db' --auto-approve"
Important Factoids
No response
References
This issue looks like it has existed for some time. In the post below you can see that they are using Terraform taint but that has been deprecated.
https://github.com/hashicorp/terraform-provider-azurerm/issues/9101