diff --git a/terraform/modules/postgres/main.tf b/terraform/modules/postgres/main.tf new file mode 100644 index 00000000..9db23be9 --- /dev/null +++ b/terraform/modules/postgres/main.tf @@ -0,0 +1,37 @@ +resource "azurerm_resource_group" "sql" { + name = "${var.name}-${var.environment}-postgres" + location = var.region +} + +resource "azurerm_postgresql_server" "sql" { + name = "${var.name}-${var.environment}-sql" + location = azurerm_resource_group.sql.location + resource_group_name = azurerm_resource_group.sql.name + + sku { + name = var.sku_name + capacity = var.sku_capacity + tier = var.sku_tier + family = var.sku_family + } + + storage_profile { + storage_mb = var.storage_mb + backup_retention_days = var.storage_backup_retention_days + geo_redundant_backup = var.storage_geo_redundant_backup + auto_grow = var.stroage_auto_grow + } + + administrator_login = "sqladmindude" + administrator_login_password = "eI0l7yswwtuhHpwzoVjwRKdAcuGNsg" + version = "11" + ssl_enforcement = "Enabled" +} + +resource "azurerm_postgresql_virtual_network_rule" "sql" { + name = "postgresql-vnet-rule" + resource_group_name = azurerm_resource_group.sql.name + server_name = azurerm_postgresql_server.sql.name + subnet_id = var.subnet_id + ignore_missing_vnet_service_endpoint = true +} \ No newline at end of file diff --git a/terraform/modules/postgres/outputs.tf b/terraform/modules/postgres/outputs.tf new file mode 100644 index 00000000..e69de29b diff --git a/terraform/modules/postgres/variables.tf b/terraform/modules/postgres/variables.tf new file mode 100644 index 00000000..91af61bc --- /dev/null +++ b/terraform/modules/postgres/variables.tf @@ -0,0 +1,75 @@ +variable "region" { + type = string + description = "Region this module and resources will be created in" +} + +variable "name" { + type = string + description = "Unique name for the services in this module" +} + +variable "environment" { + type = string + description = "Environment these resources reside (prod, dev, staging, etc)" +} + +variable "owner" { + type = string + description = "Owner of the environment and resources created in this module" +} + +variable "subnet_id" { + type = string + description = "Subnet the SQL server should run" +} + +variable "sku_name" { + type = string + description = "SKU name" + default = "GP_Gen5_2" +} + +variable "sku_capacity" { + type = string + description = "SKU Capacity" + default = "2" +} + +variable "sku_tier" { + type = string + description = "SKU Tier" + default = "GeneralPurpose" + +} + +variable "sku_family" { + type = string + description = "SKU Family" + default = "Gen5" +} + +variable "storage_mb" { + type = string + description = "Size in MB of the storage used for the sql server" + default = "5000" +} + + +variable "storage_backup_retention_days" { + type = string + description = "Storage backup retention (days)" + default = "7" +} + +variable "storage_geo_redundant_backup" { + type = string + description = "Geographic redundant backup (Enabled/Disabled)" + default = "Disabled" +} + +variable "storage_auto_grow" { + type = string + description = "Auto Grow? (Enabled/Disabled)" + default = "Enabled" +} + diff --git a/terraform/providers/dev/postgres.tf b/terraform/providers/dev/postgres.tf new file mode 100644 index 00000000..89f06e0d --- /dev/null +++ b/terraform/providers/dev/postgres.tf @@ -0,0 +1,8 @@ +module "sql" { + source = "../../modules/postgres" + name = var.name + owner = var.owner + environment = var.environment + region = var.region + subnet_id = module.vpc.subnets # FIXME - Should be a map of subnets and specify private +}