Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Terraform Module to deploy a PostgreSQL Server, PostgreSQL Database other optional resources.

License

NotificationsYou must be signed in to change notification settings

kumarvna/terraform-azurerm-postgresql-db

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

20 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Azure Database for PostgreSQL Single Server is a fully managed database service with minimal requirements for customizations of database. The single server platform is designed to handle most of the database management functions such as patching, backups, high availability, security with minimal user configuration and control. The architecture is optimized for built-in high availability with 99.99% availability on single availability zone. It supports community version of PostgreSQL 9.5, 9,6, 10, and 11.

Resources supported

module"postgresql-db" {source="kumarvna/postgresql-db/azurerm"version="1.1.0"# By default, this module will create a resource group# proivde a name to use an existing resource group and set the argument# to `create_resource_group = false` if you want to existing resoruce group.# If you use existing resrouce group location will be the same as existing RG.create_resource_group=falseresource_group_name="rg-shared-westeurope-01"location="westeurope"# PostgreSQL Server and Database settingspostgresql_server_name="mypostgresdbsrv01"postgresql_server_settings={    sku_name="GP_Gen5_8"    storage_mb=640000    version="9.6"# default admin user `postgresadmin` and can be specified as per the choice here# by default random password created by this module. required password can be specified here    admin_username="postgresadmin"    admin_password="H@Sh1CoR3!"# Database name, charset and collection arguments    database_name="demo-postgres-db"    charset="UTF8"    collation="English_United States.1252"# Storage Profile and other optional arguments    auto_grow_enabled=true    backup_retention_days=7    geo_redundant_backup_enabled=true    public_network_access_enabled=true    ssl_enforcement_enabled=true    ssl_minimal_tls_version_enforced="TLS1_2"  }# PostgreSQL Server Parameters# For more information: https://bit.ly/3dbYTtBpostgresql_configuration={    backslash_quote="on"  }# Use Virtual Network service endpoints and rules for Azure Database for PostgreSQLsubnet_id=var.subnet_id# The URL to a Key Vault custom managed keykey_vault_key_id=var.key_vault_key_id# To enable Azure Defender for database set `enable_threat_detection_policy` to trueenable_threat_detection_policy=truelog_retention_days=30email_addresses_for_alerts=["user@example.com","firstname.lastname@example.com"]# AD administrator for an Azure database for PostgreSQL# Allows you to set a user or group as the AD administrator for PostgreSQL serverad_admin_login_name="firstname.lastname@example.com"# (Optional) To enable Azure Monitoring for Azure PostgreSQL database# (Optional) Specify `storage_account_name` to save monitoring logs to storage.log_analytics_workspace_name="loganalytics-we-sharedtest2"# Creating Private Endpoint requires, VNet name and address prefix to create a subnet# By default this will create a `privatelink.mysql.database.azure.com` DNS zone.# To use existing private DNS zone specify `existing_private_dns_zone` with valid zone nameenable_private_endpoint=truevirtual_network_name="vnet-shared-hub-westeurope-001"private_subnet_address_prefix=["10.1.5.0/29"]#  existing_private_dns_zone     = "demo.example.com"# Firewall Rules to allow azure and external clients and specific Ip address/ranges.firewall_rules={    access-to-azure= {      start_ip_address="0.0.0.0"      end_ip_address="0.0.0.0"    },    desktop-ip= {      start_ip_address="49.204.228.223"      end_ip_address="49.204.228.223"    }  }# Tags for Azure Resourcestags={    Terraform="true"    Environment="dev"    Owner="test-user"  }}

Default Local Administrator and the Password

This module utilizespostgresadmin as a local administrator on PostgreSQL server. If you want to you use custom username, then specify the same by setting up the argumentadmin_username with a valid user string.

By default, this module generates a strong password for PostgreSQL server also allows you to change the length of the random password (currently 24) using therandom_password_length variable. If you want to set the custom password, specify the argumentadmin_password with a valid string.

postgresql_server_settings - Setting up your PostgreSQL Server

This object helps you setup desired PostgreSQL server and support following arguments.

ArgumentDescription
sku_nameSpecifies the SKU Name for this PostgreSQL Server. The name of the SKU, follows the tier + family + cores pattern (e.g.B_Gen4_1,GP_Gen5_8). Valid values areB_Gen4_1,B_Gen4_2,B_Gen5_1,B_Gen5_2,GP_Gen4_2,GP_Gen4_4,GP_Gen4_8,GP_Gen4_16,GP_Gen4_32,GP_Gen5_2,GP_Gen5_4,GP_Gen5_8,GP_Gen5_16,GP_Gen5_32,GP_Gen5_64,MO_Gen5_2,MO_Gen5_4,MO_Gen5_8,MO_Gen5_16,MO_Gen5_32.
storage_mbMax storage allowed for a server. Possible values are between5120 MB(5GB) and1048576 MB(1TB) for the Basic SKU and between5120 MB(5GB) and16777216 MB(16TB) for General Purpose/Memory Optimized SKUs.
versionSpecifies the version of PostgreSQL to use. Valid values are9.5,9.6,10,10.0, and11.
database_nameSpecifies the name of the PostgreSQL Database, which needsto be a valid PostgreSQL identifier.
charsetSpecifies the Charset for the PostgreSQL Database, which needsto be a valid PostgreSQL Charset..
collationSpecifies the Collation for the PostgreSQL Database, which needsto be a valid PostgreSQL Collation. Note that Microsoft uses differentnotation - en-US instead of en_US.
admin_usernameThe Administrator Login for the PostgreSQL Server. Required whencreate_mode isDefault.
admin_passwordThe Password associated with theadmin_username for the PostgreSQL Server. Required whencreate_mode isDefault
auto_grow_enabledEnable/Disable auto-growing of the storage. Storage auto-grow prevents your server from running out of storage and becoming read-only. If storage auto grow is enabled, the storage automatically grows without impacting the workload. The default value if not explicitly specified istrue
backup_retention_daysBackup retention days for the server, supported values are between7 and35 days.
geo_redundant_backup_enabledTurn Geo-redundant server backups on/off. This allows you to choose between locally redundant or geo-redundant backup storage in the General Purpose and Memory Optimized tiers. When the backups are stored in geo-redundant backup storage, they are not only stored within the region in which your server is hosted, but are also replicated to a paired data center. This provides better protection and ability to restore your server in a different region in the event of a disaster. This is not support for the Basic tier.
infrastructure_encryption_enabledWhether or not infrastructure is encrypted for this server. This property is currently still in development and not supported by Microsoft. If theinfrastructure_encryption_enabled attribute is set totrue the postgreSQL instance will incur a substantial performance degradation due to a second encryption pass on top of the existing default encryption that is already provided by Azure Storage. It is strongly suggested to leave this valuefalse as not doing so can lead to unclear error messages. Defaults tofalse
public_network_access_enabledWhether or not public network access is allowed for this server. Defaults totrue.
ssl_enforcement_enabledSpecifies if SSL should be enforced on connections. Possible values aretrue andfalse
ssl_minimal_tls_version_enforcedThe minimum TLS version to support on the sever. Possible values areTLSEnforcementDisabled,TLS1_0,TLS1_1, andTLS1_2. Defaults toTLSEnforcementDisabled.

Advanced Usage of the Module

postgresql_configuration - Configure PostgreSQL Server Parameters

The PostgreSQL server maintains many system variables that configure its operation. Each system variable has a default value. System variables can be set at server startup using options on the command line or in an option file. Most of them can be changed dynamically at runtime using the SET statement, which enables you to modify operation of the server without having to stop and restart it. You can also use system variable values in expressions.

A few Supported parameters are here for your reference. you can find all theseServer Paramter section in PostgreSQL server. Also checkPostgreSQL website for more details.

Parameter nameDescriptionParameter TypeDefault Value
connection_throttlingEnables temporary connection throttling per IP for too many invalid password login failures. Valid values areON andOFFDynamicON
deadlock_timeoutSets the amount of time, in milliseconds, to wait on a lock before checking for deadlock. Allowed value should be: 1-2147483647Dynamic1000
log_min_error_statementCauses all statements generating error at or above this level to be logged.DynamicERROR
old_snapshot_thresholdTime before a snapshot is too old to read pages changed after the snapshot was taken. Any change requires server restart.Static-1

PostgreSQL Virtual Network Rule

A virtual network rule for your Azure Database for PostgreSQL server is a subnet that is listed in the access control list (ACL) of your Azure Database for PostgreSQL server. To be in the ACL for your Azure Database for PostgreSQL server, the subnet must contain theMicrosoft.Sql type name. To enable this feature, add asubnet_id with valid resource id.

This feature is available in all regions of Azure public cloud where Azure Database for PostgreSQL is deployed for General Purpose and Memory Optimized servers. In case of VNet peering, if traffic is flowing through a common VNet Gateway with service endpoints and is supposed to flow to the peer, please create an ACL/VNet rule to allow Azure Virtual Machines in the Gateway VNet to access the Azure Database for PostgreSQL server.

Data Encryption with a Customer-managed Key

Data encryption with customer-managed keys for Azure Database for PostgreSQL enables you to bring your own key (BYOK) for data protection at rest. It also allows organizations to implement separation of duties in the management of keys and data.

Data encryption is set at the server-level. The customer-managed key is an asymmetric key stored in a customer-owned and customer-managed AzureKey Vault instance. To add you own key from key valut use variablekey_vault_key_id with valid key URL.

Server Firewall Rules

Firewalls prevent all access to your database server until you specify which computers have permission. To configure a firewall, create firewall rules that specify ranges of acceptable IP addresses.

By default, no external access to your PostgreSQL Database will be allowed until you explicitly assign permission by creating a firewall rule. To add the firewall rules to the PostgreSQL database, specify the list offirewall_rules with valid IP addresses.

Adding Active Directory Administrator to PostgreSQL Database

Azure Active Directory authentication is a mechanism of connecting to Microsoft Azure database for PostgreSQL by using identities in Azure Active Directory (Azure AD). This module adds the provided Azure Active Directory user/group to PostgreSQL Database as an administrator so that the user can login to this database with Azure AD authentication.

By default, this feature not enabled on this module. To add the Active Directory Administrator, set the argumentad_admin_login_name with a valid Azure AD user/group login name.

Threat detection policy AKA Server Security Alerts Policy

Advanced Threat Detection for Azure Database for PostgreSQL server detects anomalous activities indicating unusual and potentially harmful attempts to access or exploit databases and it can trigger the following alerts:

  • Access from unusual location
  • Access from unusual Azure data center
  • Access from unfamiliar principal
  • Access from a potentially harmful application
  • Brute force login credentials

By default, this feature not enabled on this module. Enable threat detection policy setting up the variablesenable_threat_detection_policy,log_retention_days andemail_addresses_for_alerts with valid values.

Note: Enablingthreat_detection_policy features on SQL servers and database going to create a storage account to keep all audit logs by this module. Log retention policy to be configured to keep the size within limits for this storage account. Note that this module creates resources that can cost money.

Recommended naming and tagging conventions

Applying tags to your Azure resources, resource groups, and subscriptions to logically organize them into a taxonomy. Each tag consists of a name and a value pair. For example, you can apply the nameEnvironment and the valueProduction to all the resources in production.For recommendations on how to implement a tagging strategy, see Resource naming and tagging decision guide.

Important :Tag names are case-insensitive for operations. A tag with a tag name, regardless of the casing, is updated or retrieved. However, the resource provider might keep the casing you provide for the tag name. You'll see that casing in cost reports.Tag values are case-sensitive.

An effective naming convention assembles resource names by using important resource information as parts of a resource's name. For example, using theserecommended naming conventions, a public IP resource for a production SharePoint workload is named like this:pip-sharepoint-prod-westus-001.

Requirements

NameVersion
terraform>= 0.13
azurerm>= 2.59.0

Providers

NameVersion
azurerm>= 2.59.0
random>= 3.1.0

Inputs

NameDescriptionTypeDefault
create_resource_groupWhether to create resource group and use it for all networking resourcesstring"false"
resource_group_nameThe name of the resource group in which resources are createdstring""
locationThe location of the resource group in which resources are createdstring""
log_analytics_workspace_nameThe name of log analytics workspace namestringnull
random_password_lengthThe desired length of random password created by this modulestring24
subnet_idThe resource ID of the subnetstringnull
postgresql_server_namePostgreSQL server Namestring""
admin_usernameThe username of the local administrator used for the PostgreSQL Serverstring"postgresadmin"
admin_passwordThe Password which should be used for the local-administrator on this PostgreSQL Serverstringnull
identityIf you want your PostgreSQL Server to have an managed identity. Defaults to falsestringfalse
postgresql_server_settingsPostgreSQL server settingsobject({}){}
create_modeThe creation mode. Can be used to restore or replicate existing servers. Possible values areDefault,Replica,GeoRestore, andPointInTimeRestorestringDefault
creation_source_server_idFor creation modes ot her thanDefault, the source server ID to usestringnull
restore_point_in_timeWhencreate_mode isPointInTimeRestore, specifies the point in time to restore fromcreation_source_server_idstringnull
storage_account_nameThe name of the storage account namestringnull
enable_threat_detection_policyThreat detection policy configuration, known in the API as Server Security Alerts Policystringfalse
email_addresses_for_alertsAccount administrators email for alertslist(any)""
disabled_alertsSpecifies a list of alerts which should be disabled. Possible values includeAccess_Anomaly,Sql_Injection andSql_Injection_Vulnerabilitylist(any)[]
log_retention_daysSpecifies the number of days to keep in the Threat Detection audit logsnumber30
postgresql_configurationSets a PostgreSQL Configuration value on a PostgreSQL Servermap(string){}
firewall_rulesRange of IP addresses to allow firewall connectionsmap(object({}))null
ad_admin_login_nameThe login name of the principal to set as the server administratorstringnull
key_vault_key_idThe URL to a Key Vault custom managed keystringnull
enable_private_endpointAzure Private Endpoint is a network interface that connects you privately and securely to a service powered by Azure Private Linkstring"false"
virtual_network_nameThe name of the virtual networkstring""
private_subnet_address_prefixA list of subnets address prefixes inside virtual networklist[]
existing_private_dns_zoneName of the existing private DNS zonestringnull
TagsA map of tags to add to all resourcesmap{}

Outputs

NameDescription
resource_group_nameThe name of the resource group in which resources are created
resource_group_locationThe location of the resource group in which resources are created
storage_account_idThe resource ID of the storage account
storage_account_nameThe name of the storage account
postgresql_server_idThe resource ID of the PostgreSQL Server
postgresql_server_fqdnThe FQDN of the PostgreSQL Server
postgresql_database_idThe ID of the PostgreSQL Database
postgresql_server_private_endpointid of the PostgreSQL server Private Endpoint
postgresql_server_private_dns_zone_domainDNS zone name of PostgreSQL server Private endpoints dns name records
postgresql_server_private_endpoint_ipPostgreSQL server private endpoint IPv4 Addresses
postgresql_server_private_endpoint_fqdnPostgreSQL server private endpoint FQDN Addresses

Resource Graph

Resource Graph

Authors

Originally created byKumaraswamy Vithanala

Other resources


[8]ページ先頭

©2009-2025 Movatter.jp