Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CM-27 - Add Kubernetes modules and MySQL, PostGresql public flexible server #313

Merged
merged 54 commits into from
Apr 25, 2023
Merged
Show file tree
Hide file tree
Changes from 51 commits
Commits
Show all changes
54 commits
Select commit Hold shift + click to select a range
a14019b
CM-27 - Add basic K8S-modules
Apr 19, 2023
123c7f3
CM-27 - Remove optional types
Apr 19, 2023
515c6a1
CM-27 - Change replica type specification and add Dependabot definition
Apr 19, 2023
4ec6663
CM-27 - Lint
Apr 19, 2023
90ffac9
CM-27 - Add host property
Apr 19, 2023
a27b26a
CM-27 - Add public Postgresql server
Apr 19, 2023
6da8891
CM-27 - Add PVC module
Apr 19, 2023
a7abb31
CM-27 - Do not specify zone
Apr 19, 2023
059451b
CM-27 - Revert change
Apr 19, 2023
0a453d0
CM-27 - Rename volume entity
Apr 19, 2023
ba80a56
CM-27 - Use v1
Apr 19, 2023
2bb12b2
CM-27 - Add config path option
Apr 19, 2023
34217e9
CM-27 - Ignore label changes
Apr 19, 2023
1313b8e
CM-27 - Add MySQL flexible public
Apr 19, 2023
bc3a0c0
CM-27 - Remove wrong references
Apr 20, 2023
f6e8f34
CM-27 - Increase default retention
Apr 20, 2023
8e98ae9
CM-27 - Add prevent destroy
Apr 20, 2023
f5e2dac
CM-27 - Update linting and add container port
Apr 20, 2023
0c456ab
CM-27 - Update firewall rule
Apr 20, 2023
9471ad7
CM-27 - Mark as sensitive
Apr 20, 2023
0c825c9
CM-27 - Add test for volume
Apr 20, 2023
213698f
CM-27 - Update replica checks
Apr 20, 2023
d244d98
CM-27 - Update probes
Apr 20, 2023
a3aa2fc
CM-27 - Update probes
Apr 20, 2023
4d2ff59
CM-27 - Add env references
Apr 20, 2023
4a0569b
CM-27 - Update label
Apr 20, 2023
d173d6e
CM-27 - Update output
Apr 20, 2023
de7a004
CM-27 - Update administrator login
Apr 20, 2023
71d5c5c
CM-27 - Update label
Apr 20, 2023
4b0694a
CM-27 - Add service port as output
Apr 20, 2023
b0c2d20
CM-27 - Add service port as output
Apr 20, 2023
d59c88e
CM-27 - Update paths
Apr 20, 2023
08225ab
CM-27 - Add scaler proxy
Apr 20, 2023
fbcc430
CM-27 - Add scaler proxy
Apr 20, 2023
b3ab518
CM-27 - Tweak
Apr 20, 2023
20c0c9a
CM-27 - Tweak
Apr 20, 2023
9bff980
CM-27 - Update value
Apr 20, 2023
8fd8e6e
CM-27 - Add resource scaler
Apr 21, 2023
771bc6a
CM-27 - Add probe properties
Apr 21, 2023
ec60a50
CM-27 - Add probe properties
Apr 21, 2023
a57be4b
CM-27 - Add probe properties
Apr 21, 2023
873e88a
CM-27 - Add probe properties
Apr 21, 2023
33c9dff
CM-27 - Support no scaler
Apr 21, 2023
c8556d0
CM-27 - Support no scaler
Apr 21, 2023
daf737a
CM-27 - Support no scaler
Apr 21, 2023
1b9ea2f
CM-27 - Support no scaler
Apr 21, 2023
9c59d52
CM-27 - Support no scaler
Apr 21, 2023
97bffae
CM-27 - Support no scaler
Apr 21, 2023
579cae1
CM-27 - Add env variable
Apr 21, 2023
746b6c0
CM-27 - Add env variable
Apr 21, 2023
8f31cb4
CM-27 - Allow conditional enabling of Ingress
Apr 21, 2023
57dfa21
Update modules/kubernetes/secret/main.tf
Apr 25, 2023
c57eeb3
Update modules/kubernetes/configmap/main.tf
Apr 25, 2023
4fac76e
Apply suggestions from code review
Apr 25, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions .github/dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -332,6 +332,11 @@ updates:
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/azure/mysql_flexible_server_public"
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/azure/network_security_group"
schedule:
Expand All @@ -342,6 +347,11 @@ updates:
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/azure/postgresql_public"
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/azure/private_dns_zone"
schedule:
Expand Down Expand Up @@ -501,3 +511,28 @@ updates:
directory: "/modules/other/password_generator"
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/kubernetes/configmap"
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/kubernetes/deployment_with_service"
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/kubernetes/ingress"
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/kubernetes/secret"
schedule:
interval: "daily"

- package-ecosystem: "terraform"
directory: "/modules/kubernetes/pvc"
schedule:
interval: "daily"
5 changes: 3 additions & 2 deletions .github/workflows/validate.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
name: Validate
on:
push:
pull_request:
branches:
- '**'
- main
- develop

jobs:
validate-terraform:
Expand Down
4 changes: 2 additions & 2 deletions modules/azure/mysql_flexible_server/variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ variable "storage_auto_grow_enabled" {
variable "backup_retention_days" {
type = number
description = "Backup retention days for the mysql server."
default = 7
default = 30
}

variable "geo_redundant_backup_enabled" {
Expand Down Expand Up @@ -101,4 +101,4 @@ variable "slow_query_log" {
variable "private_dns_zone_id" {
type = string
description = "ID of the private dns zone"
}
}
117 changes: 117 additions & 0 deletions modules/azure/mysql_flexible_server_public/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,117 @@
terraform {
required_version = "~> 1.3"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 3.48"
}
}

backend "azurerm" {}
}

provider "azurerm" {
features {}
}

resource "random_password" "mysql_admin_password" {
length = 16
special = true
override_special = "_%@"
keepers = var.password_keeper
}

resource "azurerm_mysql_flexible_server" "mysql_flexible_server" {
name = var.server_name
location = var.location
resource_group_name = var.resource_group_name

administrator_login = var.admin_username
administrator_password = random_password.mysql_admin_password.result

backup_retention_days = var.backup_retention_days
geo_redundant_backup_enabled = var.geo_redundant_backup_enabled

sku_name = var.server_sku
version = var.server_version

storage {
auto_grow_enabled = var.storage_auto_grow_enabled
size_gb = var.server_storage_max
}

lifecycle {
ignore_changes = [zone]
prevent_destroy = true
}
}

resource "azurerm_mysql_flexible_database" "mysql_flexible_database" {
name = var.database_name
resource_group_name = var.resource_group_name
server_name = azurerm_mysql_flexible_server.mysql_flexible_server.name
charset = var.database_charset
collation = var.database_collation
}

resource "azurerm_mysql_flexible_server_configuration" "mysql_flexible_server_configuration" {
name = "slow_query_log"
resource_group_name = var.resource_group_name
server_name = azurerm_mysql_flexible_server.mysql_flexible_server.name
value = var.slow_query_log
}

data "azurerm_monitor_diagnostic_categories" "diagnostic_categories" {
count = var.log_analytics_workspace_id == null ? 0 : 1
resource_id = azurerm_mysql_flexible_server.mysql_flexible_server.id
}

resource "azurerm_monitor_diagnostic_setting" "diagnostic_setting" {
count = var.log_analytics_workspace_id == null ? 0 : 1
name = "diag-${var.server_name}"
target_resource_id = azurerm_mysql_flexible_server.mysql_flexible_server.id
log_analytics_workspace_id = var.log_analytics_workspace_id

dynamic "enabled_log" {
for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories[0].log_category_types

content {
category = enabled_log.value

retention_policy {
enabled = false
}
}
}

dynamic "metric" {
for_each = data.azurerm_monitor_diagnostic_categories.diagnostic_categories[0].metrics

content {
category = metric.value
enabled = true

retention_policy {
enabled = false
}
}
}

// TODO: not yet implemented by Azure
// log_analytics_destination_type = "Dedicated"
lifecycle {
ignore_changes = [log_analytics_destination_type]
}
}

resource "azurerm_mysql_flexible_server_firewall_rule" "rule" {
for_each = var.whitelist_ip_addresses

name = "fw-${var.server_name}-${replace(each.value, ".", "-")}"
resource_group_name = var.resource_group_name
server_name = azurerm_mysql_flexible_server.mysql_flexible_server.name
start_ip_address = each.value
end_ip_address = each.value
}

21 changes: 21 additions & 0 deletions modules/azure/mysql_flexible_server_public/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
output "id" {
value = azurerm_mysql_flexible_server.mysql_flexible_server.id
}

output "fqdn" {
value = azurerm_mysql_flexible_server.mysql_flexible_server.fqdn
}

output "database_name" {
value = azurerm_mysql_flexible_database.mysql_flexible_database.name
}

output "admin_username" {
value = azurerm_mysql_flexible_server.mysql_flexible_server.administrator_login
sensitive = true
}

output "admin_password" {
value = azurerm_mysql_flexible_server.mysql_flexible_server.administrator_password
sensitive = true
}
94 changes: 94 additions & 0 deletions modules/azure/mysql_flexible_server_public/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
variable "location" {
type = string
description = "A datacenter location in Azure."
}

variable "resource_group_name" {
type = string
description = "Name of the resource group."
}

variable "server_name" {
type = string
description = "Name of the mysql server."
}

variable "server_sku" {
type = string
description = "Specifies the sku for the mysql server"
default = "GP_Standard_D2ds_v4"
}

variable "server_storage_max" {
type = number
description = "Max storage allowed in GB for the mysql server."
default = 20
}

variable "server_version" {
type = string
description = "Mysql server version."
}

variable "storage_auto_grow_enabled" {
type = bool
description = "Enables auto-growing of mysql server storage."
default = true
}

variable "backup_retention_days" {
type = number
description = "Backup retention days for the mysql server."
default = 30
}

variable "geo_redundant_backup_enabled" {
type = bool
description = "Enables geo-redundant mysql server backups."
default = true
}

variable "database_name" {
type = string
description = "Name of the mysql database."
}

variable "database_charset" {
type = string
description = "Specifies the charset for the mysql database."
default = "utf8mb3"
}

variable "database_collation" {
type = string
description = "Specifies the collation for the mysql database."
default = "utf8mb3_unicode_ci"
}

variable "admin_username" {
type = string
description = "The administrator login username for the mysql server."
}

variable "password_keeper" {
type = map(string)
description = "Random map of strings, when changed the mysql admin password will rotate."
}

variable "log_analytics_workspace_id" {
type = string
description = "ID of a log analytics workspace (optional)."
default = null
}

variable "slow_query_log" {
type = string
description = "Slow query log. ON or OFF (default)"
default = "OFF"
}

variable "whitelist_ip_addresses" {
type = set(string)
description = "List of IP addresses to whitelist."
default = []
}
Loading