Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

azurerm_mssql_server_dns_alias plan fails if resource deleted manually #18614

Closed
1 task done
turkenh opened this issue Oct 3, 2022 · 2 comments · Fixed by #18619
Closed
1 task done

azurerm_mssql_server_dns_alias plan fails if resource deleted manually #18614

turkenh opened this issue Oct 3, 2022 · 2 comments · Fixed by #18619
Labels
Milestone

Comments

@turkenh
Copy link
Contributor

turkenh commented Oct 3, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Community Note

  • Please vote on this issue by adding a 👍 reaction to the original issue to help the community and maintainers prioritize this request
  • Please do not leave "+1" or "me too" comments, they generate extra noise for issue followers and do not help prioritize the request
  • If you are interested in working on this issue or have submitted a pull request, please leave a comment

Terraform Version

v1.2.1

AzureRM Provider Version

3.25.0

Affected Resource(s)/Data Source(s)

azurerm_mssql_server_dns_alias

Terraform Configuration Files

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "example" {
  name     = "example-resources"
  location = "West Europe"
}

resource "azurerm_mssql_server" "example" {
  name                         = "example-sqlserver"
  resource_group_name          = azurerm_resource_group.example.name
  location                     = azurerm_resource_group.example.location
  version                      = "12.0"
  administrator_login          = "missadministrator"
  administrator_login_password = "AdminPassword123!"
}

resource "azurerm_mssql_server_dns_alias" "example" {
  name            = "example-dns-alias"
  mssql_server_id = azurerm_mssql_server.example.id
}

Debug Output/Panic Output

terraform plan
azurerm_mssql_server_dns_alias.example: Refreshing state... [id=/subscriptions/REDACTED/resourceGroups/hasan-example/providers/Microsoft.Sql/servers/hasan-example/dnsAliases/example-dns-alias]
╷
│ Error: sql.ServerDNSAliasesClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned an error. Status=404 Code="ResourceNotFound" Message="The requested resource of type 'Microsoft.Sql/servers/dnsAliases' with name 'example-dns-alias' was not found."
│
│   with azurerm_mssql_server_dns_alias.example,
│   on main.tf line 5, in resource "azurerm_mssql_server_dns_alias" "example":
│    5: resource "azurerm_mssql_server_dns_alias" "example" {
│
│ sql.ServerDNSAliasesClient#Get: Failure responding to request: StatusCode=404 -- Original Error: autorest/azure: Service returned
│ an error. Status=404 Code="ResourceNotFound" Message="The requested resource of type 'Microsoft.Sql/servers/dnsAliases' with name
│ 'example-dns-alias' was not found."

Expected Behaviour

terraform plan should notice that resource deleted externally and plan it to be added back.

https://learn.hashicorp.com/tutorials/terraform/provider-setup#implement-read

When you create something in Terraform but delete it manually, Terraform should gracefully handle it. If the API returns an error when the resource doesn't exist, the read function should check to see if the resource is available first. If the resource isn't available, the function should set the ID to an empty string so Terraform "destroys" the resource in state. The following code snippet is an example of how this can be implemented; you do not need to add this to your configuration for this tutorial.

Actual Behaviour

error thrown and requires manual interaction with tfstate file.

Steps to Reproduce

  1. terraform apply with provided manifests above.
  2. Delete alias using azure cli
az sql server dns-alias delete example-dns-alias --resource-group hasan-example --server hasan-example
  1. Run terraform plan

Important Factoids

No response

References

No response

@turkenh turkenh added the bug label Oct 3, 2022
@github-actions github-actions bot removed the bug label Oct 3, 2022
@turkenh turkenh changed the title azurerm_mssql_server_dns_alias plan fails if resource deleted externally azurerm_mssql_server_dns_alias plan fails if resource deleted manually Oct 3, 2022
turkenh added a commit to turkenh/terraform-provider-azurerm that referenced this issue Oct 3, 2022
@github-actions github-actions bot added this to the v3.26.0 milestone Oct 3, 2022
@github-actions
Copy link

This functionality has been released in v3.26.0 of the Terraform Provider. Please see the Terraform documentation on provider versioning or reach out if you need any assistance upgrading.

For further feature requests or bug reports with this functionality, please create a new GitHub issue following the template. Thank you!

@github-actions
Copy link

I'm going to lock this issue because it has been closed for 30 days ⏳. This helps our maintainers find and focus on the active issues.
If you have found a problem that seems similar to this, please open a new issue and complete the issue template so we can capture all the details necessary to investigate further.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 11, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants