hashicorp / terraform-provider-azurerm

Terraform provider for Azure Resource Manager
https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs
Mozilla Public License 2.0
4.59k stars 4.63k forks source link

azurerm 3.15.0: unable to parse existing azurerm_postgresql_server resource #17722

Closed lra closed 2 years ago

lra commented 2 years ago

Is there an existing issue for this?

Community Note

Terraform Version

1.2.5

AzureRM Provider Version

3.15.0

Affected Resource(s)/Data Source(s)

azurerm_postgresql_server

Terraform Configuration Files

resource "azurerm_postgresql_server" "this" {
  for_each = local.filtered_pg_instances

  administrator_login              = lookup(local.filtered_pg_instances[each.key], "administrator_login", "${replace(each.key, "-", "_")}_dba")
  administrator_login_password     = random_password.postgresql[each.key].result
  auto_grow_enabled                = true
  backup_retention_days            = lookup(local.filtered_pg_instances[each.key], "backup_retention_days", "7")
  geo_redundant_backup_enabled     = lookup(local.filtered_pg_instances[each.key], "geo_redundant_backup_enabled", substr(each.value.sku_name, 0, 2) != "B_") # Basic tier does not support geo redundant backups
  location                         = var.region
  name                             = lookup(local.filtered_pg_instances[each.key], "name", "${local.longname}-pg-${each.key}")
  resource_group_name              = lookup(local.filtered_pg_instances[each.key], "resource_group_name", azurerm_resource_group.this.name)
  sku_name                         = each.value.sku_name
  ssl_enforcement_enabled          = true
  ssl_minimal_tls_version_enforced = lookup(local.filtered_pg_instances[each.key], "ssl_minimal_tls_version_enforced", "TLS1_2")
  storage_mb                       = each.value.storage_mb
  version                          = lookup(local.filtered_pg_instances[each.key], "version", "11")

  tags = merge(
    # We start with the stack common tags
    local.tags,
    # Then we check if the PG instance has a service override. If not, pick the instance key as the service.
    { service = lookup(local.pg_instances[each.key], "service", each.key), team = module.services.service_teams[lookup(local.pg_instances[each.key], "service", each.key)] },
  )

  lifecycle {
    ignore_changes = [
      administrator_login_password,
      storage_mb,
    ]
  }
}

Debug Output/Panic Output

╷
│ Error: parsing Postgres Server ID : parsing "/subscriptions/REDACTED/resourceGroups/smc-prod-australiasoutheast/providers/Microsoft.DBForPostgreSQL/servers/REDACTED": parsing segment "staticMicrosoftDBforPostgreSQL": expected the segment "Microsoft.DBForPostgreSQL" to be "Microsoft.DBforPostgreSQL"
│ 
│   with module.stack.azurerm_postgresql_server.this["REDACTED"],
│   on ../../modules/seismic-az-stack/postgresql.tf line 135, in resource "azurerm_postgresql_server" "this":
│  135: resource "azurerm_postgresql_server" "this" {
│ 
╵

### Expected Behaviour

$ terraform plan No changes. Your infrastructure matches the configuration.


### Actual Behaviour

Getting an error when doing `terraform plan`:
╷
│ Error: parsing Postgres Server ID : parsing "/subscriptions/REDACTED/resourceGroups/smc-prod-australiasoutheast/providers/Microsoft.DBForPostgreSQL/servers/REDACTED": parsing segment "staticMicrosoftDBforPostgreSQL": expected the segment "Microsoft.DBForPostgreSQL" to be "Microsoft.DBforPostgreSQL"
│ 
│   with module.stack.azurerm_postgresql_server.this["REDACTED"],
│   on ../../modules/seismic-az-stack/postgresql.tf line 135, in resource "azurerm_postgresql_server" "this":
│  135: resource "azurerm_postgresql_server" "this" {
│ 
╵

Steps to Reproduce

  1. Set the azurerm provider to v3.15.0
  2. terraform plan

Important Factoids

It works with v3.14.0

References

No response

mbfrahry commented 2 years ago

Hey @lra, apologies for the regression here. We got a fix in with #17755 and just pushed a release out to 3.15.1. Let me know if that fixes up this issue for you!

lra commented 2 years ago

Same problem with 3.15.1 can you reopen this? See:

- Installing hashicorp/azurerm v3.15.1...
- Installed hashicorp/azurerm v3.15.1 (signed by HashiCorp)
│ Error: parsing "/subscriptions/SOME_ID/resourceGroups/smc-prod-eastus/providers/Microsoft.DBForPostgreSQL/servers/_SOME_SERVER/databases/SOME_DATABASE": parsing segment "staticMicrosoftDBforPostgreSQL": expected the segment "Microsoft.DBForPostgreSQL" to be "Microsoft.DBforPostgreSQL"
│ 
│   with module.stack.azurerm_postgresql_database.this["engagement-taskqueue"],
│   on ../../modules/***-az-stack/postgresql.tf line 204, in resource "azurerm_postgresql_database" "this":
│  204: resource "azurerm_postgresql_database" "this" {
lra commented 2 years ago

I guess the problem is now on azurerm_postgresql_database and has been fixed for azurerm_postgresql_server. Want me to open a new ticket instead?

mbfrahry commented 2 years ago

That'd be great! I imagine you've got quite a few oddities. Can you look through your all your postgres resource ids and see which resources are using Microsoft.DBForPostgreSQL instead of Microsoft.DBforPostgreSQL in their IDs?

lra commented 2 years ago

New issue: https://github.com/hashicorp/terraform-provider-azurerm/issues/17763

I tried, and we exclusively have lowercase Microsoft.DBforPostgreSQL, no Microsoft.DBForPostgreSQL (big F) at all. e.g. in one single region with a dumped state file:

$ rg DBforPostgreSQL terraform.tfstate|wc -l
    2210
$ rg DBForPostgreSQL terraform.tfstate|wc -l
       0

Same in a few other regions, so I stopped looking.

github-actions[bot] commented 2 years ago

This functionality has been released in v3.16.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[bot] commented 2 years ago

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.