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

Error: Provider produced inconsistent result after apply. azurerm_management_lock produced an unexpected new value: Root resource was present, but now absent. #25674

Open
1 task done
ahosni-axon opened this issue Apr 18, 2024 · 2 comments

Comments

@ahosni-axon
Copy link

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 and review the contribution guide to help.

Terraform Version

=0.14

AzureRM Provider Version

2.99.0

Affected Resource(s)/Data Source(s)

azurerm_management_lock

Terraform Configuration Files

resource "azurerm_mssql_database" "db" {
  name           = var.name
  server_id      = var.server_id
  license_type   = var.license_type
  collation      = var.collation
  max_size_gb    = var.max_size_gb
  read_scale     = var.read_scale
  zone_redundant = var.zone_redundant

  create_mode                 = var.create_mode
  creation_source_database_id = var.creation_source_database_id

  sku_name        = var.elastic_pool_id == null ? var.sku_name : "ElasticPool"
  elastic_pool_id = var.elastic_pool_id

  short_term_retention_policy {
    retention_days = var.backup_settings.short_term_retention_days
  }

  long_term_retention_policy {
    week_of_year      = var.backup_settings.long_term_weekofyear == null ? 1 : var.backup_settings.long_term_weekofyear
    weekly_retention  = var.backup_settings.long_term_retention_weeks == "" ? null : var.backup_settings.long_term_retention_weeks
    monthly_retention = var.backup_settings.long_term_retention_months == "" ? null : var.backup_settings.long_term_retention_months
    yearly_retention  = var.backup_settings.long_term_retention_years == "" ? null : var.backup_settings.long_term_retention_years
  }

  tags = var.tags

  lifecycle {
    ignore_changes = [
      license_type,
      collation,
      long_term_retention_policy,
      create_mode,
      creation_source_database_id
    ]
  }
}

resource "azurerm_management_lock" "db" {
  count = var.lock ? 1 : 0

  name       = "${var.name}-lock"
  scope      = azurerm_mssql_database.db.id
  lock_level = "CanNotDelete"
  notes      = "Locked to prevent accidental deletion."
}

Debug Output/Panic Output

╷
│ Error: Provider produced inconsistent result after apply
│ 
│ When applying changes to
│ module.db["photobook"].azurerm_management_lock.db[0], provider
│ "provider[\"registry.terraform.io/hashicorp/azurerm\"]" produced an
│ unexpected new value: Root resource was present, but now absent.
│ 
│ This is a bug in the provider, which should be reported in the provider's
│ own issue tracker.

Expected Behaviour

The resource lock should have been created. The resource lock should have been added to the terraform state. The terraform apply should have completed successfully.

Actual Behaviour

The terraform apply created the DB successfully, but failed to create the lock. When the lock failed to create the terraform apply errored and stopped.

Steps to Reproduce

No response

Important Factoids

No response

References

#25667 Is a potentially related issue, as it provided the same error, however this issue is on a different version of terraform and the azurerm provider, as well as being caused by a different resource.

@sinbai
Copy link
Contributor

sinbai commented Apr 19, 2024

Hi @ahosni-axon thanks for opening this issue. However, I could not reproduce this issue with the following TF config using the latest version of the Terraform provider. Could you please try using the following TF config in the latest version to see if the issue still exists?


terraform {
  required_providers {
    azurerm = {
      source = "hashicorp/azurerm"
      version = "3.99.0"
    }
  }
}

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-mssql-25674"
  location = "eastus"
}

resource "azurerm_mssql_server" "test" {
  name                         = "acctest-sqlserver-25674"
  resource_group_name          = azurerm_resource_group.test.name
  location                     = azurerm_resource_group.test.location
  version                      = "12.0"
  administrator_login          = "mradministrator"
  administrator_login_password = "thisIsDog11"
}

resource "azurerm_mssql_database" "test" {
  name      = "acctest-db-25674"
  server_id = azurerm_mssql_server.test.id
}

resource "azurerm_management_lock" "db" {
  name       = "25674-lock"
  scope      = azurerm_mssql_database.test.id
  lock_level = "CanNotDelete"
  notes      = "Locked to prevent accidental deletion."
}

Acutal:
image

@ahosni-axon
Copy link
Author

Thanks for the the info. I will test this out shortly and let you know the results. Thank you.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants