Skip to content

Commit 266f14c

Browse files
authored
Merge pull request #233430 from KarlErickson/karler-xfz11
edit "Update tab name of how-to-bind-postgres #229034"
2 parents 18184e5 + 706ce22 commit 266f14c

File tree

2 files changed

+83
-3
lines changed

2 files changed

+83
-3
lines changed

articles/spring-apps/how-to-bind-postgres.md

Lines changed: 72 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ ms.topic: how-to
77
ms.date: 09/26/2022
88
ms.author: karler
99
ms.custom: passwordless-java, devx-track-java
10+
zone_pivot_group_filename: spring-apps/postgresql-zone-pivot-groups.json
11+
zone_pivot_groups: passwordless-postgresql
1012
---
1113

1214
# Bind an Azure Database for PostgreSQL to your application in Azure Spring Apps
@@ -20,6 +22,14 @@ ms.custom: passwordless-java, devx-track-java
2022

2123
With Azure Spring Apps, you can bind select Azure services to your applications automatically, instead of having to configure your Spring Boot application manually. This article shows you how to bind your application to your Azure Database for PostgreSQL instance.
2224

25+
In this article, we include two authentication methods: Azure Active Directory (Azure AD) authentication and PostgreSQL authentication. The Passwordless tab shows the Azure AD authentication and the Password tab shows the PostgreSQL authentication.
26+
27+
Azure AD authentication is a mechanism for connecting to Azure Database for PostgreSQL using identities defined in Azure AD. With Azure AD authentication, you can manage database user identities and other Microsoft services in a central location, which simplifies permission management.
28+
29+
PostgreSQL authentication uses accounts stored in PostgreSQL. If you choose to use passwords as credentials for the accounts, these credentials are stored in the user table. Because these passwords are stored in PostgreSQL, you need to manage the rotation of the passwords by yourself.
30+
31+
::: zone pivot="postgresql-passwordless-flexible-server"
32+
2333
## Prerequisites
2434

2535
* An application deployed to Azure Spring Apps. For more information, see [Quickstart: Deploy your first application to Azure Spring Apps](./quickstart.md).
@@ -49,7 +59,7 @@ Use the following steps to prepare your project.
4959

5060
## Bind your app to the Azure Database for PostgreSQL instance
5161

52-
### [Service Connector for flexible server](#tab/Passwordlessflex)
62+
### [Passwordless (Recommended)](#tab/Passwordlessflex)
5363

5464
1. Install the [Service Connector](../service-connector/overview.md) passwordless extension for the Azure CLI:
5565

@@ -71,7 +81,64 @@ Use the following steps to prepare your project.
7181
--system-identity
7282
```
7383

74-
### [Service Connector for single server](#tab/Passwordlesssingle)
84+
### [Password](#tab/Secretsflex)
85+
86+
Use the following steps to bind your app using a secret.
87+
88+
1. Note the admin username and password of your Azure Database for PostgreSQL account.
89+
90+
1. Connect to the server, create a database named **testdb** from a PostgreSQL client, and then create a new non-admin account.
91+
92+
1. Run the following command to connect to the database with admin username and password.
93+
94+
```azurecli
95+
az spring connection create postgres-flexible \
96+
--resource-group $AZ_SPRING_APPS_RESOURCE_GROUP \
97+
--service $AZ_SPRING_APPS_SERVICE_INSTANCE_NAME \
98+
--app $APP_NAME \
99+
--deployment $DEPLOYMENT_NAME \
100+
--target-resource-group $POSTGRES_RESOURCE_GROUP \
101+
--server $POSTGRES_SERVER_NAME \
102+
--database $DATABASE_NAME \
103+
--secret name=$USERNAME secret=$PASSWORD
104+
```
105+
106+
---
107+
108+
::: zone-end
109+
110+
::: zone pivot="postgresql-passwordless-single-server"
111+
112+
## Prerequisites
113+
114+
* An application deployed to Azure Spring Apps. For more information, see [Quickstart: Deploy your first application to Azure Spring Apps](./quickstart.md).
115+
* An Azure Database for PostgreSQL Single Server instance.
116+
* [Azure CLI](/cli/azure/install-azure-cli) version 2.45.0 or higher.
117+
118+
## Prepare your Java project
119+
120+
Use the following steps to prepare your project.
121+
122+
1. In your project's *pom.xml* file, add the following dependency:
123+
124+
```xml
125+
<dependency>
126+
<groupId>org.springframework.boot</groupId>
127+
<artifactId>spring-boot-starter-data-jpa</artifactId>
128+
</dependency>
129+
<dependency>
130+
<groupId>com.azure.spring</groupId>
131+
<artifactId>spring-cloud-azure-starter-jdbc-postgresql</artifactId>
132+
</dependency>
133+
```
134+
135+
1. In the *application.properties* file, remove any `spring.datasource.*` properties.
136+
137+
1. Update the current app by running `az spring app deploy`, or create a new deployment for this change by running `az spring app deployment create`.
138+
139+
## Bind your app to the Azure Database for PostgreSQL instance
140+
141+
### [Passwordless](#tab/PasswordlessSingle)
75142

76143
1. Install the [Service Connector](../service-connector/overview.md) passwordless extension for the Azure CLI:
77144

@@ -93,7 +160,7 @@ Use the following steps to prepare your project.
93160
--system-identity
94161
```
95162

96-
### [Service Connector with password](#tab/Secrets)
163+
### [Password](#tab/SecretsSingle)
97164

98165
Use the following steps to bind your app using a secret.
99166

@@ -117,6 +184,8 @@ Use the following steps to bind your app using a secret.
117184

118185
---
119186

187+
::: zone-end
188+
120189
## Next steps
121190

122191
In this article, you learned how to bind an application in Azure Spring Apps to an Azure Database for PostgreSQL instance. To learn more about binding services to an application, see [Bind an Azure Cosmos DB database to an application in Azure Spring Apps](./how-to-bind-cosmos.md).
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
# YamlMime:ZonePivotGroups
2+
groups:
3+
# Owner: xiaofanzhou
4+
- id: passwordless-postgresql
5+
title: Azure Database for PostgreSQL use passwordless connection
6+
prompt: Choose the Azure Database for PostgreSQL server to use
7+
pivots:
8+
- id: postgresql-passwordless-single-server
9+
title: Single Server
10+
- id: postgresql-passwordless-flexible-server
11+
title: Flexible Server

0 commit comments

Comments
 (0)