A RetroSearch Logo

Home - News ( United States | United Kingdom | Italy | Germany ) - Football scores

Search Query:

Showing content from https://www.w3resource.com/PostgreSQL/snippets/azurerm-postgresql-flexible-server.php below:

Website Navigation


Guide to Azure PostgreSQL Flexible Server Deployment

Guide to Azure PostgreSQL Flexible Server DeploymentLast update on December 31 2024 13:03:34 (UTC/GMT +8 hours)

Deploying PostgreSQL Flexible Server Using azurerm_postgresql_flexible_server

The azurerm_postgresql_flexible_server is a Terraform resource used to deploy and manage a PostgreSQL Flexible Server on Microsoft Azure. Flexible Server is a versatile PostgreSQL deployment option that offers greater control over server configuration, scaling, and maintenance. It supports features like zone redundancy, customizable storage, and automated backups.

This guide walks you through the process of creating a PostgreSQL Flexible Server with Terraform, explaining its syntax, key attributes, and an example configuration.

Syntax:

resource "azurerm_postgresql_flexible_server" "example" {
  name                = "example-server"             # Server name
  location            = "East US"                   # Azure region
  resource_group_name = azurerm_resource_group.example.name
  administrator_login = "adminuser"                 # Admin username
  administrator_password = "StrongP@ssw0rd"          # Admin password

  sku_name   = "Standard_B2ms"                      # Instance size
  storage_mb = 32768                                # Storage size in MB
  version    = "13"                                 # PostgreSQL version

  high_availability {
    mode = "ZoneRedundant"                          # HA mode (Optional)
  }

  backup {
    retention_days = 7                              # Backup retention period
  }

  network {
    delegated_subnet_id = azurerm_subnet.example.id # Subnet configuration
    private_dns_zone_id = azurerm_private_dns_zone.example.id
  }

  tags = {                                          # Metadata tags
    environment = "production"
  }
}

Key Attributes

Step-by-Step Example

Step 1: Create a Resource Group

Code:

# Create a resource group for the server
resource "azurerm_resource_group" "example" {
  name     = "example-rg"        # Resource group name
  location = "East US"           # Region
}

Step 2: Define the Virtual Network and Subnet

Code:

# Define a virtual network
resource "azurerm_virtual_network" "example" {
  name                = "example-vnet"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  address_space       = ["10.0.0.0/16"]            # Address space
}

# Define a subnet within the VNet
resource "azurerm_subnet" "example" {
  name                 = "example-subnet"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = ["10.0.1.0/24"]           # Subnet range
}

Step 3: Configure and Deploy the PostgreSQL Flexible Server

Code:

# Deploy the PostgreSQL Flexible Server
resource "azurerm_postgresql_flexible_server" "example" {
  name                = "example-server"
  location            = azurerm_resource_group.example.location
  resource_group_name = azurerm_resource_group.example.name
  administrator_login = "adminuser"
  administrator_password = "StrongP@ssw0rd"

  sku_name   = "Standard_B2ms"
  storage_mb = 32768
  version    = "13"

  high_availability {
    mode = "ZoneRedundant"
  }

  backup {
    retention_days = 7
  }

  network {
    delegated_subnet_id = azurerm_subnet.example.id
  }

  tags = {
    environment = "production"
  }
}

Explanation:

Benefits of PostgreSQL Flexible Server

All PostgreSQL Questions, Answers, and Code Snippets Collection.


RetroSearch is an open source project built by @garambo | Open a GitHub Issue

Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo

HTML: 3.2 | Encoding: UTF-8 | Version: 0.7.4