generated from CDCgov/template
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Create postgresql server and db with relevant resources (#393)
* creating database module and resources for postgresql server and db * removed commented out code * making module headers consistent * remove azurerm_postgresql_flexible_server resources and using a single-server Postgres instance instead * update resource notes in modules/database/main.tf * save randomly created postgres db login password in azure key vault * add client_id and object_id for vault * fix errors * update database with network subnet and vault with object_id and vite_api_url * update subnet used * update how we are consuming the vite_api_url and object_id variables * remove the data.tf files from the database and vault modules, use main data.tf file under terraform * remove duplicate variables and add descriptions * fix syntax error and put variable descriptions * create subnet for db and update tf code * modify and clean up code * refactor code to fix error * update db with postgresql_flexible_server since single server will be retired in March 2025 * update note regarding retiring azurerm_postgresql_server in March 2025 * reverse postgres_flex_server changes and comment them out * update db to postgresql flexible server and add postgresql dns zone networking * remove azurerm_postgresql_server code * clean up code by removing unused and commented out code * remove more commented out code * remove variables used when working on vault module * add back client_id and tenant_id variables to support the azuread provider * update database name * reduce the sku_name to Standard_B1ms * remove unused variables * update database cidr block --------- Co-authored-by: marycrawford <[email protected]>
- Loading branch information
1 parent
3f8cc8e
commit e90afae
Showing
11 changed files
with
157 additions
and
65 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
# Azure Postgres Single Service (azurerm_postgresql_server) retires in March 2025. | ||
# As a result we are using Azure Database for PostgreSQL Flexible Server | ||
# with granular control, flexibility and better cost optimization. | ||
resource "azurerm_postgresql_flexible_server" "postgres_flexible_server" { | ||
name = "reportvisionpostgresql-flexible-server" | ||
location = var.location | ||
resource_group_name = var.resource_group_name | ||
sku_name = var.postgres_sku_name | ||
version = var.engine_version | ||
storage_mb = 32768 # 32 GB, the lowest of the valid options | ||
backup_retention_days = 7 | ||
|
||
administrator_login = var.db_username | ||
administrator_password = random_string.setup_rds_password.result | ||
delegated_subnet_id = var.subnet | ||
private_dns_zone_id = var.private_dns_zone_id | ||
|
||
# Disable Public Network Access | ||
public_network_access_enabled = false | ||
|
||
lifecycle { | ||
prevent_destroy = true | ||
} | ||
} | ||
|
||
resource "azurerm_postgresql_flexible_server_database" "postgres_db" { | ||
name = "${azurerm_postgresql_flexible_server.postgres_flexible_server.name}-db" | ||
server_id = azurerm_postgresql_flexible_server.postgres_flexible_server.id | ||
} | ||
|
||
# Random string resource for the postgres password | ||
resource "random_string" "setup_rds_password" { | ||
length = 16 # Length of the password | ||
|
||
# Character set that excludes problematic characters like quotes, backslashes, etc. | ||
override_special = "_!@#-$%^&*()[]{}" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
output "postgres_db_password" { | ||
value = azurerm_postgresql_flexible_server.postgres_flexible_server.administrator_login | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
variable "db_username" { | ||
type = string | ||
description = "Username of RDS Instance." | ||
default = "reportVisionDbUser" | ||
} | ||
|
||
variable "engine_version" { | ||
description = "Postgres DB engine version." | ||
default = "11" | ||
} | ||
|
||
variable "location" { | ||
type = string | ||
description = "Location of the resource." | ||
default = "eastus2" | ||
} | ||
|
||
variable "resource_group_name" { | ||
type = string | ||
description = "The Azure Resource Group to deploy to" | ||
} | ||
|
||
variable "postgres_sku_name" { | ||
type = string | ||
description = "value" | ||
default = "Standard_B1ms" | ||
} | ||
|
||
variable "subnet" { | ||
type = string | ||
description = "The subnet ID to associate with the PostgreSQL Flexible Server" | ||
} | ||
|
||
variable "private_dns_zone_id" { | ||
type = string | ||
description = "Private DNS Zone for PostgreSQL Flexible Server" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,9 +1,12 @@ | ||
variable "resource_group" {} | ||
variable "name" {} | ||
variable "location" {} | ||
variable "vnetcidr" {} | ||
variable "websubnetcidr" {} | ||
variable "lbsubnetcidr" {} | ||
# variable "dbsubnetcidr" {} | ||
variable "dbsubnetcidr" {} | ||
variable "appsubnetcidr" {} | ||
variable "env" {} | ||
variable "env" {} | ||
|
||
variable "location" { | ||
default = "eastus2" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,10 @@ | ||
variable "name" {} | ||
|
||
variable "sku_name" { | ||
type = string | ||
description = "The Azure Stock Keep Unit (SKU) version" | ||
} | ||
|
||
variable "resource_group_name" { | ||
description = "value of the Azure resource group to deploy to" | ||
} | ||
|
||
variable "name" {} | ||
|
||
variable "sku_name" {} |