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

Uday Kiran Reddy 6 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
{count} votes

6 answers

Sort by: Most helpful
  1. martinez alfaya, antonio 1 Reputation point
    2023-12-14T13:04:09.5933333+00:00

    Hi!! everyone, in my case it was a parameters problem, this error:

    The resource operation completed with terminal provisioning state 'Failed'

    InternalServerError An unexpected error occured while processing the request. Tracking ID: '2c726aee-0026-4dae-9cbb-926f027630d3

    is because one or several parameters are no good.

    In my case, I tried 2 base configurations that works, use that base configuration to create the postgresql flexible server and after that try to add more parameters.

    Flexible server creation with IPs (not vnet and private dns)

    {
    
    
    	"location": "westeurope",
    	"sku": {
    		"name": "Standard_D4s_v3",
    		"tier": "GeneralPurpose"
    	},
    	"properties": {
    		"administratorLogin": "cloudsa",
    		"administratorLoginPassword": "password",
    		"availabilityZone": "1",
    		"createMode": "Default",
    		"version": "12",
    		"storage": {
    			"storageSizeGB": 512
    		}
    	}
    }
    

    Flexible server creation with vnet and private dns, note that this privatedns and vnet has to be previously created:

    {
    
    
    	"location": "westeurope",
    	"sku": {
    		"name": "Standard_D4s_v3",
    		"tier": "GeneralPurpose"
    	},
    	"properties": {
    		"administratorLogin": "cloudsa",
    		"administratorLoginPassword": "password",
    		"availabilityZone": "1",
    		"createMode": "Default",
    		"version": "12",
    		"storage": {
    			"storageSizeGB": 512
    		},
    		"network": {
    "delegatedSubnetResourceId": "/subscriptions/be316fa0-af5d-4667-b0af-c109b2c30765/resourceGroups/z0euw1cacrsg102/providers/Microsoft.Network/virtualNetworks/datahub01cpgfxdevop2-vnet/subnets/privateendpoint-subnet",
    "privateDnsZoneArmResourceId": "/subscriptions/be316fa0-af5d-4667-b0af-c109b2c30765/resourceGroups/z0euw1cacrsg102/providers/Microsoft.Network/privateDnsZones/privatelink.postgres.database.azure.com"
    		}
    	}
    }
    
    0 comments No comments