Skip to content

Commit a4ae97f

Browse files
authored
Merge pull request #284058 from markingmyname/uuf
[PostgreSQL] New create Virtual Endpoint via Terraform
2 parents e0d01a5 + 8939adc commit a4ae97f

File tree

3 files changed

+129
-2
lines changed

3 files changed

+129
-2
lines changed

articles/postgresql/TOC.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -504,7 +504,8 @@
504504
items:
505505
- name: Azure portal, CLI, REST API
506506
href: flexible-server/how-to-read-replicas-portal.md
507-
displayName: replica
507+
- name: Read replica with Terraform
508+
href: flexible-server/how-to-read-replicas-virtual-endpoints-terraform.md
508509
- name: Extensions
509510
items:
510511
- name: Overview

articles/postgresql/flexible-server/concepts-read-replicas-virtual-endpoints.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -77,9 +77,10 @@ This section explains how to use Virtual Endpoints in Azure Database for Postgre
7777

7878
## Related content
7979

80-
- [create virtual endpoints](how-to-read-replicas-portal.md#create-virtual-endpoints).
80+
- [Create virtual endpoints](how-to-read-replicas-portal.md#create-virtual-endpoints).
8181
- [Read replicas - overview](concepts-read-replicas.md)
8282
- [Geo-replication](concepts-read-replicas-geo.md)
8383
- [Promote read replicas](concepts-read-replicas-promote.md)
8484
- [Create and manage read replicas in the Azure portal](how-to-read-replicas-portal.md)
8585
- [Cross-region replication with virtual network](concepts-networking.md#replication-across-azure-regions-and-virtual-networks-with-private-networking)
86+
- [Create virtual endpoints for read replicas with Terraform](how-to-read-replicas-virtual-endpoints-terraform.md)
Lines changed: 125 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,125 @@
1+
---
2+
title: Create virtual endpoints for read replicas with Terraform
3+
description: This article describes the virtual endpoints for read replica feature using Terraform for Azure Database for PostgreSQL - Flexible Server.
4+
author: akashraokm
5+
ms.author: akashrao
6+
ms.reviewer: maghan
7+
ms.date: 08/08/2024
8+
ms.service: azure-database-postgresql
9+
ms.subservice: flexible-server
10+
ms.topic: how-to
11+
ai.usage: ai-assisted
12+
---
13+
14+
# Create virtual endpoints for read replicas with Terraform
15+
16+
Using Terraform, you can create and manage virtual endpoints for read replicas in Azure Database for PostgreSQL—Flexible Server. Terraform is an open-source infrastructure-as-code tool that allows you to define and provision infrastructure using a high-level configuration language.
17+
18+
## Prerequisites
19+
20+
Before you begin, ensure you have the following:
21+
22+
- An Azure account with the necessary permissions.
23+
- Terraform installed on your local machine. You can download it from the [official Terraform website](https://www.terraform.io/downloads.html).
24+
- Azure CLI installed and authenticated. Instructions are in the [Azure CLI documentation](/cli/azure/install-azure-cli).
25+
26+
Ensure you have a basic understanding of Terraform syntax and Azure resource provisioning.
27+
28+
Step-by-Step Terraform Configuration: Provide a step-by-step guide on configuring virtual endpoints for read replicas using Terraform.
29+
30+
## Configuring virtual endpoints
31+
32+
Follow these steps to create virtual endpoints for read replicas in Azure Database for PostgreSQL - Flexible Server:
33+
34+
### Initialize the Terraform configuration
35+
36+
Create a `main.tf` file and define the Azure provider.
37+
38+
```terraform
39+
provider "azurerm" {
40+
features {}
41+
}
42+
43+
resource "azurerm_resource_group" "example" {
44+
name = "example-resources"
45+
location = "East US"
46+
}
47+
```
48+
49+
### Create the primary Azure Database for PostgreSQL
50+
51+
Define the primary PostgreSQL server resource.
52+
53+
```terraform
54+
resource "azurerm_postgresql_flexible_server" "primary" {
55+
name = "primary-server"
56+
resource_group_name = azurerm_resource_group.example.name
57+
location = azurerm_resource_group.example.location
58+
version = "12"
59+
administrator_login = "adminuser"
60+
administrator_password = "password"
61+
sku_name = "Standard_D4s_v3"
62+
63+
storage_mb = 32768
64+
backup_retention_days = 7
65+
geo_redundant_backup = "Disabled"
66+
high_availability {
67+
mode = "ZoneRedundant"
68+
}
69+
}
70+
```
71+
72+
### Create read replicas
73+
74+
Define the read replicas for the primary server.
75+
76+
```terraform
77+
resource "azurerm_postgresql_flexible_server_replica" "replica" {
78+
name = "replica-server"
79+
resource_group_name = azurerm_resource_group.example.name
80+
location = azurerm_resource_group.example.location
81+
source_server_id = azurerm_postgresql_flexible_server.primary.id
82+
}
83+
```
84+
85+
### Configure virtual endpoints
86+
87+
Define the necessary resources to configure virtual endpoints.
88+
89+
```terraform
90+
resource "azurerm_private_endpoint" "example" {
91+
name = "example-private-endpoint"
92+
location = azurerm_resource_group.example.location
93+
resource_group_name = azurerm_resource_group.example.name
94+
subnet_id = azurerm_subnet.example.id
95+
96+
private_service_connection {
97+
name = "example-privateserviceconnection"
98+
private_connection_resource_id = azurerm_postgresql_flexible_server.primary.id
99+
is_manual_connection = false
100+
subresource_names = ["postgresqlServer"]
101+
}
102+
}
103+
```
104+
105+
### Apply the configuration
106+
107+
Initialize Terraform and apply the configuration.
108+
109+
`terraform init`
110+
`terraform apply`
111+
112+
Confirm the apply action when prompted. Terraform provisions the resources and configure the virtual endpoints as specified.
113+
114+
115+
For additional info about Virtual endpoints, refer to [create virtual endpoints](how-to-read-replicas-portal.md#create-virtual-endpoints)
116+
117+
## Related content
118+
119+
- [Create virtual endpoints](how-to-read-replicas-portal.md#create-virtual-endpoints)
120+
- [Read replicas - overview](concepts-read-replicas.md)
121+
- [Geo-replication](concepts-read-replicas-geo.md)
122+
- [Promote read replicas](concepts-read-replicas-promote.md)
123+
- [Create and manage read replicas in the Azure portal](how-to-read-replicas-portal.md)
124+
- [Cross-region replication with virtual network](concepts-networking.md#replication-across-azure-regions-and-virtual-networks-with-private-networking)
125+
- [Terraform Azure provider documentation](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs)

0 commit comments

Comments
 (0)