Hii Muhammad Amir
Welcome to the Microsoft Q&A Platform! Thank you for asking your question here.
Run "terraform state list" to see all the resources Terraform is managing and look for your diagnostic setting in the list.
If the resource is in the state but not in Azure, you can remove it from Terraform's state using this command:
terraform state rm azurerm_monitor_diagnostic_setting.diagnostic_setting
This command tells Terraform to forget the resource, so you can run terraform apply without any errors.
After removing the missing resource from the state, just run terraform apply again. Terraform will create any resources that are missing in Azure.
After applying, check the Azure portal to confirm the diagnostic setting is created.
Sometimes resources don't appear in the Azure portal because of filters or permissions. Make sure you're in the correct subscription and resource group.
If a resource was created outside of Terraform and you want to manage it, use terraform import to bring it into Terraform.
terraform import azurerm_monitor_diagnostic_setting.diagnostic_setting <resource_id>
If you have any further queries, do let us know.
If the answer is helpful, please click "Accept Answer" and "Upvote it".