Share via

postgres database not getting created in the below template, how to fix this?

Uday Kiran Reddy 11 Reputation points
2022-01-30T12:18:54.277+00:00

I am creating a postgres server and postgres database using terraform.

postgres server and database part of template:

resource "azurerm_postgresql_flexible_server" "example" {
  name                   = "${azurerm_resource_group.postgres_rg.name}-${var.environment}"
  resource_group_name    = azurerm_resource_group.postgres_rg.name
  location               = azurerm_resource_group.postgres_rg.location
  version                = "13"
  delegated_subnet_id    = azurerm_subnet.example2.id
  private_dns_zone_id    = azurerm_private_dns_zone.example.id
  administrator_login    = var.administrator_login
  administrator_password = var.administrator_password
  zone                   = "3"

  storage_mb = 131072

  sku_name   = var.postgres_sku #"GP_Standard_D2s_v3"
  depends_on = [azurerm_private_dns_zone_virtual_network_link.example]

}

resource "azurerm_postgresql_database" "example" {
  name                = "martdatabase"
  resource_group_name = azurerm_resource_group.postgres_rg.name
  server_name         = azurerm_postgresql_flexible_server.example.name
  collation = "en_US.utf8"
  charset   = "utf8"
  depends_on          = [azurerm_postgresql_flexible_server.example]
}

Server got created and even I cross checked in the azure portal.
But during database creation, getting below error.

│ Error: creating/updating Database: (Name "martdatabase" / Server Name "deletek8s-del-postgres-del" / Resource Group "deletek8s-del-postgres"): postgresql.DatabasesClient#CreateOrUpdate: Failure sending request: StatusCode=404 -- Original Error: Code="ResourceNotFound" Message="The Resource 'Microsoft.DBforPostgreSQL/servers/deletek8s-del-postgres-del' under resource group 'deletek8s-del-postgres' was not found. For more details please go to https://aka.ms/ARMResourceNotFoundFix"
│
│   with azurerm_postgresql_database.example,
│   on 12-postgres.tf line 33, in resource "azurerm_postgresql_database" "example":
│   33: resource "azurerm_postgresql_database" "example" {

I even reapplied, to cross check if any delay in updation, but same errror.

Azure Database for PostgreSQL

6 answers

Sort by: Most helpful
  1. Marcel Fuhrmann 5 Reputation points
    2023-02-20T08:27:36.8166667+00:00

    I'm also facing a simlar Issue when creating databases on flexible postgresql server

    Error: creating Database (Subscription: "subscription-id"
    Resource Group Name: "example-rg-postgresql-dev"
    Flexible Server Name: "example-psql-01-dev-primary-s5a43j"
    Database Name: "example_db"): polling after Create: Code="InternalServerError" Message="An unexpected error occured while processing the request. Tracking ID: '90bfjad9-02b6-4575-b395-73fc42a8ad44'" 
       with module.postgresql["psql-01"].azurerm_postgresql_flexible_server_database.databases["example_db"],
       on .terraform/modules/postgresql/terraform/modules/postgresql/main.tf line 46, in resource "azurerm_postgresql_flexible_server_database" "databases":
       46: resource "azurerm_postgresql_flexible_server_database" "databases" {
    

    My Terraform code looks like the following:

    resource "azurerm_postgresql_flexible_server" "psql_server" {
      name                = var.psql_server_name
      location            = var.location
      resource_group_name = var.resource_group_name
    
      administrator_login    = var.psql_admin
      administrator_password = var.psql_admin_password
      zone                   = "1"
    
      sku_name   = var.psql_sku_name
      version    = var.psql_version
      storage_mb = var.psql_storage
    
      backup_retention_days        = 7
      geo_redundant_backup_enabled = false
    
      delegated_subnet_id = var.psql_subnet_id
      private_dns_zone_id = azurerm_private_dns_zone.psql_endpoint_dns_private_zone.id
    
      tags = merge(
        var.additional_tags,
        {
          instance   = var.psql_server_name
          created-by = "terraform"
        },
      )
    }
    
    resource "azurerm_postgresql_flexible_server_database" "databases" {
      for_each  = var.psql_databases
      name      = each.value
      server_id = azurerm_postgresql_flexible_server.psql_server.id
      charset   = "utf8"
      collation = "utf8_unicode_ci"
    }
    

    Was this answer helpful?

    1 person found this answer helpful.

  2. Sander van den Berg 0 Reputation points
    2023-04-13T13:29:32.1966667+00:00

    Hello, just replying to share my solution to, as it seems, the same error

    Flexible Server Name: "psql-test-dimp"): polling after Create: Code="InternalServerError" Message="An unexpected error occured while processing the request. Tracking ID

    We also try to set a 'zone' (was in our case 1).
    I went to Azure portal to see if manual creation was possible under the RG we wanted to use.
    And it wasn't, only 2 & 3 were available Changed the zone in our code to 2, and the deploy was succesfull. Greetings,
    Sander

    Was this answer helpful?

    0 comments No comments

  3. Parmar, Suresh 30 Reputation points
    2023-02-01T18:29:28.7666667+00:00

    I have 'similar problem.

    null_resource.next: Creating...

    null_resource.next: Creation complete after 0s [id=715078475]

    azurerm_postgresql_flexible_server.dev-postgre: Creating...

    azurerm_postgresql_flexible_server.dev-postgre: Still creating... [10s elapsed]

    azurerm_postgresql_flexible_server.dev-postgre: Still creating... [20s elapsed]

    azurerm_postgresql_flexible_server.dev-postgre: Still creating... [30s elapsed]

    azurerm_postgresql_flexible_server.dev-postgre: Still creating... [40s elapsed]

    azurerm_postgresql_flexible_server.dev-postgre: Still creating... [50s elapsed]

    azurerm_postgresql_flexible_server.dev-postgre: Still creating... [1m0s elapsed]

    │ Error: creating Flexible Server (Subscription: "f34fd8e9-b1ba-44ed-8a37-da7cc57361de"

    │ Resource Group Name: "RG_300000000056685_CEC_Smart_Cities_LZ"

    │ Flexible Server Name: "dev-psqlfs"): polling after Create: Code="InternalServerError" Message="An unexpected error occured while processing the request. Tracking ID: 'de947b9a-ed82-4a69-b0b1-fe8f7bc072d5'"

    │ with azurerm_postgresql_flexible_server.dev-postgre,

    │ on main.tf line 69, in resource "azurerm_postgresql_flexible_server" "dev-postgre":

    │ 69: resource "azurerm_postgresql_flexible_server" "dev-postgre" {

    │Would be really grateful for help please.

    My code :

    # This resource will destroy (potentially immediately) after null_resource.next
    resource "null_resource" "previous" {}
    
    resource "time_sleep" "wait_4_min" {
      depends_on = [null_resource.previous]
    
      create_duration = "4m"
    }
    
    resource "null_resource" "next" {
      depends_on = [time_sleep.wait_4_min]
    }
    
    
    resource "azurerm_postgresql_flexible_server" "dev-postgre" {
      name                   = "dev-psqlfs"
      resource_group_name    = azurerm_resource_group.resource_group.name
      location               = var.location
      version                = "13"
      delegated_subnet_id    = azurerm_subnet.Data.id
      private_dns_zone_id    = azurerm_private_dns_zone.dev-dns.id
      administrator_login    = "psqladmin"
      administrator_password = "SIabc360"
      zone                   = "1"
      storage_mb = 32768
      sku_name   = "GP_Standard_D4s_v3"
      #collation = "en_US.utf8"
      #charset = "utf8"
      depends_on = [azurerm_private_dns_zone_virtual_network_link.dev-dns-vnl,time_sleep.wait_4_min]
      timeouts{
        create = "4m"
        }
    }
    

    Was this answer helpful?


  4. Uday Kiran Reddy (ureddy) 96 Reputation points
    2022-02-07T07:31:54.19+00:00

    Thanks geetha, it is working with the one you shared.

    resource "azurerm_postgresql_flexible_server_database" "example" {
    name = var.databasename
    server_id = azurerm_postgresql_flexible_server.example.id
    collation = "en_US.utf8"
    charset = "utf8"
    depends_on = [azurerm_postgresql_flexible_server.example,time_sleep.wait_4_min]
    timeouts{
    create = "4m"
    }
    }

    Was this answer helpful?


  5. GeethaThatipatri-MSFT 29,597 Reputation points Microsoft Employee Moderator
    2022-02-06T01:10:06.303+00:00

    Hi, @Uday Kiran Reddy As per the product team this resource that you have commented out is wrong. I am assuming that it is commented out because it does not work. you need to use this resource instead I hope you are using the same. For example, replace the commented-out resource with the below code and give it a try.
    171566-image.png

    Regards
    Geetha

    Was this answer helpful?


Your answer

Answers can be marked as 'Accepted' by the question author and 'Recommended' by moderators, which helps users know the answer solved the author's problem.