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.6k stars 4.65k forks source link

azurerm_postgresql_flexible_server is failing with "polling after Create: context deadline exceeded" error at 60 mins (during terraform apply) #27948

Open iamnothere101 opened 4 days ago

iamnothere101 commented 4 days ago

Is there an existing issue for this?

Community Note

Terraform Version

1.0.0

AzureRM Provider Version

3.105

Affected Resource(s)/Data Source(s)

avm-res-dbforpostgresql-flexibleserver

Terraform Configuration Files

module "naming" {
  source  = "Azure/naming/azurerm"
  version = "~> 0.3"
}

resource "azurerm_resource_group" "my_resource_group" {
  location = var.location
  name     = var.my_resource_group_name
}

resource "random_password" "myadminpassword" {
  length           = 16
  override_special = "_%@"
  special          = true
}

module "postgres-server" {
  depends_on = [azurerm_resource_group.my_resource_group]
  source     = "Azure/avm-res-dbforpostgresql-flexibleserver/azurerm"
  # version    = "0.1.0"

  location            = var.location
  name                = var.my_server_name
  resource_group_name = azurerm_resource_group.my_resource_group.name
  # enable_telemetry       = var.enable_telemetry
  administrator_login    = azurerm_key_vault_secret.admin_login.value
  administrator_password = random_password.myadminpassword.result
  storage_mb             = var.storage_mb
  storage_tier           = var.storage_tier
  backup_retention_days  = var.backup_retention_days
  server_version         = 16
  sku_name               = "GP_Standard_D2s_v3"
  zone                   = 1
  high_availability = {
    mode                      = "ZoneRedundant"
    standby_availability_zone = 2
  }
  tags = null
}

Debug Output/Panic Output

module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Still creating... [59m30s elapsed]
module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Still creating... [59m40s elapsed]
module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Still creating... [59m50s elapsed]
╷
│ Error: creating Flexible Server (Subscription: "***"
│ Resource Group Name: "my-resource-group"
│ Flexible Server Name: "my-postgres-server"): polling after Create: context deadline exceeded
│ 
│   with module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this,
│   on .terraform/modules/postgres-server.postgres-server/main.tf line 1, in resource "azurerm_postgresql_flexible_server" "this":
│    1: resource "azurerm_postgresql_flexible_server" "this" {
│ 
╵
Error: Terraform exited with code 1.
Error: Process completed with exit code 1.

Expected Behaviour

Postgres Module deployment should succeed.

Actual Behaviour

Terraform apply is failing at 60 mins with the error shown above.

Steps to Reproduce

I am calling the module from a parent module and running terraform apply. When I re-run the pipeline, it complains that the resource exists and I need time to import it into my state file:

module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this: Creating...
╷
│ Error: A resource with the ID "/subscriptions/***/resourceGroups/my-postgres-resource-group/providers/Microsoft.DBforPostgreSQL/flexibleServers/my-postgres-server" already exists - to be managed via Terraform this resource needs to be imported into the State. Please see the resource documentation for "azurerm_postgresql_flexible_server" for more information.
│ 
│   with module.postgres-server.module.postgres-server.azurerm_postgresql_flexible_server.this,
│   on .terraform/modules/postgres-server.postgres-server/main.tf line 1, in resource "azurerm_postgresql_flexible_server" "this":
│    1: resource "azurerm_postgresql_flexible_server" "this" {
│ 
╵
Error: Terraform exited with code 1.

Important Factoids

No response

References

No response

neil-yechenwei commented 2 days ago

Thanks for raising this issue. Seems the resource azurerm_postgresql_flexible_server is created successfully with below tf config on my local. Could you try latest azurerm provider and below tf config to see if the issue still exists? Thanks.

tf config:

provider "azurerm" {
  features {}
}

resource "azurerm_resource_group" "test" {
  name     = "acctestRG-postgresql-test01"
  location = "eastus"
}

resource "azurerm_virtual_network" "test" {
  name                = "acctest-vn-test01"
  location            = azurerm_resource_group.test.location
  resource_group_name = azurerm_resource_group.test.name
  address_space       = ["10.0.0.0/16"]
}

resource "azurerm_subnet" "test" {
  name                 = "acctest-sn-test01"
  resource_group_name  = azurerm_resource_group.test.name
  virtual_network_name = azurerm_virtual_network.test.name
  address_prefixes     = ["10.0.2.0/24"]
  service_endpoints    = ["Microsoft.Storage"]
  delegation {
    name = "fs"
    service_delegation {
      name = "Microsoft.DBforPostgreSQL/flexibleServers"
      actions = [
        "Microsoft.Network/virtualNetworks/subnets/join/action",
      ]
    }
  }
}

resource "azurerm_private_dns_zone" "test" {
  name                = "accpdztest01.postgres.database.azure.com"
  resource_group_name = azurerm_resource_group.test.name
}

resource "azurerm_private_dns_zone_virtual_network_link" "test" {
  name                  = "acctestVnetZonetest01.com"
  private_dns_zone_name = azurerm_private_dns_zone.test.name
  virtual_network_id    = azurerm_virtual_network.test.id
  resource_group_name   = azurerm_resource_group.test.name

  depends_on = [azurerm_subnet.test]
}

resource "azurerm_postgresql_flexible_server" "test" {
  name                          = "acctest-fs-test01"
  resource_group_name           = azurerm_resource_group.test.name
  location                      = azurerm_resource_group.test.location
  administrator_login           = "adminTerraform"
  administrator_password        = "QAZwsx123"
  version                       = "16"
  backup_retention_days         = 7
  storage_mb                    = 32768
  delegated_subnet_id           = azurerm_subnet.test.id
  private_dns_zone_id           = azurerm_private_dns_zone.test.id
  public_network_access_enabled = false
  sku_name                      = "GP_Standard_D2s_v3"
  zone                          = "1"

  high_availability {
    mode                      = "ZoneRedundant"
    standby_availability_zone = "2"
  }

  maintenance_window {
    day_of_week  = 0
    start_hour   = 8
    start_minute = 0
  }

  tags = {
    ENV = "Test"
  }

  depends_on = [azurerm_private_dns_zone_virtual_network_link.test]
}

tf config:

provider "azurerm" {
  features {}
}

module "naming" {
  source  = "Azure/naming/azurerm"
  version = "~> 0.4"
}

resource "azurerm_resource_group" "my_resource_group" {
  location = "eastus"
  name     = "acctest-pso-test01"
}

resource "random_password" "myadminpassword" {
  length           = 16
  override_special = "_%@"
  special          = true
}

module "postgres-server" {
  depends_on = [azurerm_resource_group.my_resource_group]
  source     = "Azure/avm-res-dbforpostgresql-flexibleserver/azurerm"
  # version    = "0.1.2"

  location               = "eastus"
  name                   = "acctest-psoss-test01"
  resource_group_name    = azurerm_resource_group.my_resource_group.name
  administrator_login    = "adminTerraform"
  administrator_password = "QAZwsx123"
  storage_mb             = 32768
  storage_tier           = "P4"
  backup_retention_days  = 7
  server_version         = 16
  sku_name               = "GP_Standard_D2s_v3"
  zone                   = 1

  high_availability = {
    mode                      = "ZoneRedundant"
    standby_availability_zone = 2
  }

  tags = null
}