Skip to content

Latest commit

 

History

History
120 lines (73 loc) · 5.8 KB

deploy-postgresql-flexible-server-database.md

File metadata and controls

120 lines (73 loc) · 5.8 KB
title description keywords ms.topic service ms.service ms.date ms.custom
Deploy a PostgreSQL Flexible Server Database using Terraform
Learn how to deploy a PostgreSQL Flexible Server Database using Terraform
azure, devops, terraform, postgresql, flexible server, database
how-to
postgresql
postgresql
10/26/2023
devx-track-terraform

Deploy a PostgreSQL Flexible Server Database using Terraform

Article tested with the following Terraform and Terraform provider versions:

[!INCLUDE Terraform abstract]

This article shows how to deploy a PostgreSQL Flexible Server Database using Terraform.

In this article, you learn how to:

[!div class="checklist"]

Note

The example code in this article is located in the Azure Terraform GitHub repo.

1. Configure your environment

[!INCLUDE open-source-devops-prereqs-azure-subscription.md]

[!INCLUDE configure-terraform.md]

2. Implement the Terraform code

  1. Create a directory in which to test and run the sample Terraform code and make it the current directory.

  2. Create a file named providers.tf and insert the following code:

    [!code-terraformmaster]

  3. Create a file named main.tf and insert the following code to deploy the PostgreSQL Flexible Server on which the database runs.

    [!code-terraformmaster]

  4. Create a file named postgresql-fs-db.tf and insert the following code to instantiate the database:

    [!code-terraformmaster]

  5. Create a file named variables.tf and insert the following code:

    [!code-terraformmaster]

  6. Create a file named outputs.tf and insert the following code to output the resource group name, Azure PostgreSQL server name, and Azure PostgreSQL database name:

    [!code-terraformmaster]

3. Initialize Terraform

[!INCLUDE terraform-init.md]

4. Create a Terraform execution plan

[!INCLUDE terraform-plan.md]

5. Apply a Terraform execution plan

[!INCLUDE terraform-apply-plan.md]

6. Verify the results

Run az postgres flexible-server db show to display the Azure PostgreSQL database.

az postgres flexible-server db show --resource-group <resource_group_name> --server-name <server_name> --database-name <database_name>

Key points:

  • The values for the <resource_group_name>, <server_name>, and <database_name> are displayed in the terraform apply output.

Run Get-AzPostgreSqlFlexibleServerDatabase to display the Azure PostgreSQL database.

Get-AzPostgreSqlFlexibleServerDatabase -ResourceGroupName <resource_group_name> -ServerName <server_name> -Name <database_name>

Key points:

  • The values for the <resource_group_name>, <server_name>, and <database_name> are displayed in the terraform apply output.

7. Clean up resources

[!INCLUDE terraform-plan-destroy.md]

Troubleshoot Terraform on Azure

Troubleshoot common problems when using Terraform on Azure

Next steps

[!div class="nextstepaction"] Learn more about PostgreSQL Flexible Server