diff --git a/quickstart/201-postgresql-fs-db/main.tf b/quickstart/201-postgresql-fs-db/main.tf new file mode 100644 index 00000000..8ef98163 --- /dev/null +++ b/quickstart/201-postgresql-fs-db/main.tf @@ -0,0 +1,89 @@ +resource "random_pet" "rg-name" { + prefix = var.name_prefix +} + +resource "azurerm_resource_group" "default" { + name = random_pet.rg-name.id + location = var.location +} + +resource "azurerm_virtual_network" "default" { + name = "${var.name_prefix}-vnet" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + address_space = ["10.0.0.0/16"] +} + +resource "azurerm_network_security_group" "default" { + name = "${var.name_prefix}-nsg" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + + security_rule { + name = "test123" + priority = 100 + direction = "Inbound" + access = "Allow" + protocol = "Tcp" + source_port_range = "*" + destination_port_range = "*" + source_address_prefix = "*" + destination_address_prefix = "*" + } +} + +resource "azurerm_subnet" "default" { + name = "${var.name_prefix}-subnet" + virtual_network_name = azurerm_virtual_network.default.name + resource_group_name = azurerm_resource_group.default.name + address_prefixes = ["10.0.2.0/24"] + service_endpoints = ["Microsoft.Storage"] + + delegation { + name = "fs" + + service_delegation { + name = "Microsoft.DBforPostgreSQL/flexibleServers" + + actions = [ + "Microsoft.Network/virtualNetworks/subnets/join/action", + ] + } + } +} + +resource "azurerm_subnet_network_security_group_association" "default" { + subnet_id = azurerm_subnet.default.id + network_security_group_id = azurerm_network_security_group.default.id +} + +resource "azurerm_private_dns_zone" "default" { + name = "${var.name_prefix}-pdz.postgres.database.azure.com" + resource_group_name = azurerm_resource_group.default.name + + depends_on = [azurerm_subnet_network_security_group_association.default] +} + +resource "azurerm_private_dns_zone_virtual_network_link" "default" { + name = "${var.name_prefix}-pdzvnetlink.com" + private_dns_zone_name = azurerm_private_dns_zone.default.name + virtual_network_id = azurerm_virtual_network.default.id + resource_group_name = azurerm_resource_group.default.name +} + +resource "azurerm_postgresql_flexible_server" "default" { + name = "${var.name_prefix}-server" + resource_group_name = azurerm_resource_group.default.name + location = azurerm_resource_group.default.location + version = "13" + delegated_subnet_id = azurerm_subnet.default.id + private_dns_zone_id = azurerm_private_dns_zone.default.id + administrator_login = "adminTerraform" + administrator_password = "QAZwsx123" + zone = "1" + storage_mb = 32768 + sku_name = "GP_Standard_D2s_v3" + backup_retention_days = 7 + + depends_on = [azurerm_private_dns_zone_virtual_network_link.default] +} diff --git a/quickstart/201-postgresql-fs-db/output.tf b/quickstart/201-postgresql-fs-db/output.tf new file mode 100644 index 00000000..4290ac52 --- /dev/null +++ b/quickstart/201-postgresql-fs-db/output.tf @@ -0,0 +1,11 @@ +output "resource_group_name" { + value = azurerm_resource_group.default.name +} + +output "azurerm_postgresql_flexible_server" { + value = azurerm_postgresql_flexible_server.default.name +} + +output "postgresql_flexible_server_database_name" { + value = azurerm_postgresql_flexible_server_database.default.name +} diff --git a/quickstart/201-postgresql-fs-db/postgresql-fs-db.tf b/quickstart/201-postgresql-fs-db/postgresql-fs-db.tf new file mode 100644 index 00000000..de3f2cd1 --- /dev/null +++ b/quickstart/201-postgresql-fs-db/postgresql-fs-db.tf @@ -0,0 +1,6 @@ +resource "azurerm_postgresql_flexible_server_database" "default" { + name = "${var.name_prefix}-db" + server_id = azurerm_postgresql_flexible_server.default.id + collation = "en_US.UTF8" + charset = "UTF8" +} diff --git a/quickstart/201-postgresql-fs-db/providers.tf b/quickstart/201-postgresql-fs-db/providers.tf new file mode 100644 index 00000000..6fb32c2b --- /dev/null +++ b/quickstart/201-postgresql-fs-db/providers.tf @@ -0,0 +1,14 @@ +terraform { + required_version = ">=1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>2.0" + } + } +} + +provider "azurerm" { + features {} +} diff --git a/quickstart/201-postgresql-fs-db/readme.md b/quickstart/201-postgresql-fs-db/readme.md new file mode 100644 index 00000000..2c4ed610 --- /dev/null +++ b/quickstart/201-postgresql-fs-db/readme.md @@ -0,0 +1,27 @@ +# Azure PostgreSQL Flexible Server Database + +This template deploys an [Azure PostgreSQL Flexible Server Database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_database). + +## Terraform resource types + +- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) +- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) +- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network) +- [azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group) +- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet) +- [azurerm_subnet_network_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet_network_security_group_association) +- [azurerm_private_dns_zone](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone) +- [azurerm_private_dns_zone_virtual_network_link](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/private_dns_zone_virtual_network_link) +- [azurerm_postgresql_flexible_server](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server) +- [azurerm_postgresql_flexible_server_database](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/postgresql_flexible_server_database) + +## Variables + +| Name | Description | +|-|-| +| `name_prefix` | (Optional) Prefix of the resource name. Value defaults to: postgresqlfs| +| `location` | (Optional) Azure Region in which to deploy these resources. Value defaults to: eastus | + +## Example + +To see how to run this example, see [Create an Azure PostgreSQL Flexible Server Database using Terraform](https://docs.microsoft.com/azure/developer/terraform/deploy-postgresql-flexible-server-database). diff --git a/quickstart/201-postgresql-fs-db/variables.tf b/quickstart/201-postgresql-fs-db/variables.tf new file mode 100644 index 00000000..c6f361cc --- /dev/null +++ b/quickstart/201-postgresql-fs-db/variables.tf @@ -0,0 +1,9 @@ +variable "name_prefix" { + default = "postgresqlfs" + description = "Prefix of the resource name." +} + +variable "location" { + default = "eastus" + description = "Location of the resource." +} diff --git a/quickstart/README.md b/quickstart/README.md index bbb5ae7f..a225b440 100644 --- a/quickstart/README.md +++ b/quickstart/README.md @@ -31,6 +31,7 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope - [Azure Kubernetes Service with ACR](./201-aks-acr-identity/) - [Azure virtual machine scale set with jumpbox](./201-vmss-jumpbox) - [Azure virtual machine scale set with jumpbox from Packer custom image](./201-vmss-packer-jumpbox) +- [Azure PostgreSQL Flexible Server Database](./201-postgresql-fs-db) #### Advanced - [Azure Service Fabric](./301-service-fabric/)