Deploying PostgreSQL using Terraform – Cloud Support

Create main.tf file

  1. Added providers

provider “azurerm” {

    features {

    }

}

2. Added resource group which is already create.
data “azurerm_resource_group” “rg”{

    name = “jasdemo”

}

3. Add random resource to generate random password for PostgreSQL
resource “random_password” “postgresql-pass” {

  length = 8

  min_special = 2

}

4. Add resource Key vault which is already created. Also added secret resource and random password will be assigned to this secret.

data “azurerm_key_vault” “vault”{

    name = “postgresql83”

    resource_group_name = “jasdemo”

}

data “azurerm_key_vault_secret” “postgress-secret”{

    key_vault_id = data.azurerm_key_vault.vault.id

    name = “postgrespassword”

}

5. Add resource PostgreSQL with details to deploy

resource “azurerm_postgresql_server” “post-db” {

  location = data.azurerm_resource_group.rg.location

  name  = “postdb786”

  resource_group_name = data.azurerm_resource_group.rg.name

  sku_name = “GP_Gen5_4”

  version = var.postgress_version

  administrator_login = “jasdemo”

  administrator_login_password = data.azurerm_key_vault_secret.postgress-secret.value

  ssl_enforcement_enabled = true

}  
 

6. Uploaded main.tf  and var.tf to cloud shell and run below command

7. Run terraform plan

8. Finally terraform apply for deployment.

9. Validate the resource deployed on the portal.

Leave a Reply

Your email address will not be published.