Skip to content

feat: update .#6

Open
asarkar157 wants to merge 1 commit into
mainfrom
terraform-bot/issue-2-root-a48ea8b94d0a409b
Open

feat: update .#6
asarkar157 wants to merge 1 commit into
mainfrom
terraform-bot/issue-2-root-a48ea8b94d0a409b

Conversation

@asarkar157

Copy link
Copy Markdown
Contributor

Summary

azure_tf_sql_database

Motivation

Closes #2

What's included

  • Updates under .
    • M README.md
    • M main.tf
    • M variables.tf

Terraform resources

  • azurerm_mssql_database
  • azurerm_mssql_firewall_rule
  • azurerm_mssql_server

Validation

Check Result
terraform fmt ✅ PASS
terraform validate ✅ PASS
terraform test ✅ PASS
Module quality PASS

Reviewer notes

  • Generated by the terraform-module-update workflow (StackGen terraform-bot).
  • Please confirm variable defaults, security constraints, and any org-specific wiring before merge.

@asarkar157

Copy link
Copy Markdown
Contributor Author

Module Review — Grade: 🟡 C

Grade C — Moderate issues requiring polish before org-wide distribution. The module is fundamentally sound with correct resource patterns, proper this naming, good output coverage, and sensitive handling of credentials. However, it has zero test coverage (caps at B maximum), zero validation blocks across all 13 variables (including ISO 8601 duration strings that are easy to misformat), no terraform { required_providers {} } block (consumers cannot pin azurerm version — LTR features need >= 3.x), workspace-specific defaults (se-rg, workshopdb) that make it unsuitable for reuse, no tags merge pattern, public_network_access_enabled defaults to true, no auditing or threat detection policies, and the firewall rule is always created with no variable to disable it. No critical security failures, which keeps it above D. The LTR feature addition itself is well-implemented with sensible defaults.


📋 Variable Classification

Variable Type Classification Issue Status
server_name string REQUIRED Missing validation block (1-63 chars, lowercase alphanumeric + hyphens) ⚠️
database_name string OPTIONAL Default workshopdb is workshop-specific — not suitable for reusable module ⚠️
resource_group_name string OPTIONAL Default se-rg is workspace-specific — should be REQUIRED (no default)
location string OPTIONAL Default westus2 is an opinionated regional assumption ⚠️
admin_login string REQUIRED Missing validation (Azure disallows admin, administrator, sa, etc.) ⚠️
admin_password string REQUIRED Has sensitive = true ✅ — missing complexity validation (>=8 chars, 3-of-4 classes) ⚠️
sku_name string OPTIONAL Missing validation for allowed SKU values ⚠️
max_size_gb number OPTIONAL Missing bounds validation ⚠️
tags map(string) OPTIONAL No issues
ltr_weekly_retention string OPTIONAL Missing ISO 8601 duration format validation ⚠️
ltr_monthly_retention string OPTIONAL Good default P13M; missing ISO 8601 duration format validation ⚠️
ltr_yearly_retention string OPTIONAL Missing ISO 8601 duration format validation ⚠️
ltr_week_of_year number OPTIONAL Missing validation (must be 1–52) ⚠️

🏗️ Module Structure

  • ✅ Resource naming convention — all resources use this
  • ✅ Tightly-coupled resource pattern — server, database, firewall rule appropriately grouped
  • ❌ Tag merge pattern — no locals block; tags passed as raw var.tags with no module-managed tags (Name, managed-by)
  • ✅ No provider blocks in module
  • ❌ No terraform { required_providers {} } block — consumers cannot pin azurerm version; LTR features need azurerm >= 3.x
  • ✅ Outputs expose useful attributes (server_id, server_fqdn, database_id, database_name, connection_string)
  • ✅ All outputs have descriptions
  • ✅ README.md exists with features section and LTR override example
  • ❌ No tests — zero *.tftest.hcl or *_test.go files in repo
  • ⚠️ Workspace-specific defaults (se-rg, workshopdb) come from variables but are not suitable for org distribution

🔒 Security Defaults

  • ⚠️ Encryption at rest (TDE) — platform default, not explicitly set (acceptable but could be explicit)
  • ✅ Encryption in transit — minimum_tls_version = "1.2" hardcoded
  • ✅ Admin password handling — sensitive = true
  • public_network_access_enabled — defaults to true (should default to false for safer posture)
  • ⚠️ Firewall rule 0.0.0.0 — Azure-services convention but always created with no variable to disable
  • ❌ No auditing policy (azurerm_mssql_server_extended_auditing_policy)
  • ❌ No threat detection / security alert policy (azurerm_mssql_server_security_alert_policy)
  • ⚠️ connection_string output embeds admin credentials — architectural concern
  • ⚠️ SQL authentication only — no Azure AD authentication support
  • ⚠️ No lifecycle { prevent_destroy = true } on stateful resources

✅ Validation Results

  • terraform fmt: ✅ PASS
  • terraform init: ✅ PASS
  • terraform validate: ✅ PASS
  • terraform test: ⏭️ SKIPPED (no test files in repo)

🤖 Auto-Fixable Issues (11)

A follow-up automated fix PR can address these:

  1. Add terraform { required_providers { azurerm } } block with version constraint
  2. Add validation blocks to server_name, admin_login, admin_password
  3. Add ISO 8601 duration validation to ltr_weekly_retention, ltr_monthly_retention, ltr_yearly_retention
  4. Add range validation (1–52) to ltr_week_of_year
  5. Remove default from resource_group_name (make REQUIRED)
  6. Add locals block with tags merge pattern (module-managed Name, managed-by)
  7. Add public_network_access_enabled variable defaulting to false
  8. Make firewall rule conditional via create_azure_services_firewall_rule variable
  9. Add lifecycle { prevent_destroy = true } on stateful resources (server, database)
  10. Add validation to sku_name (allowed SKU list) and max_size_gb (bounds)
  11. Scaffold tests/ directory with basic *.tftest.hcl plan/apply coverage

👤 Needs Human Review (5)

These require organizational decisions and cannot be auto-fixed:

  1. No auditing configuration — requires org decision on storage account / Log Analytics workspace for audit logs
  2. No threat detection / security alert policy — requires org security policy decision on alert recipients and disabled alerts
  3. connection_string output embeds credentials — architectural decision on Azure AD vs SQL auth and whether modules should emit credential-bearing outputs at all
  4. No Azure AD authentication support — requires org identity strategy decision (azuread_administrator block, managed identity, etc.)
  5. Location default westus2 — requires org decision on regional strategy / whether to remove default entirely

Automated review by terraform-module-pr-review workflow · grade: C · 16 violations (11 auto-fixable, 5 need human review)

@asarkar157 asarkar157 added the review/grade-C Automated module review grade: C (moderate issues) label Jun 9, 2026

@asarkar157 asarkar157 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Automated module review complete. Grade: 🟡 C. See detailed review comment above for variable classification, structure checks, security defaults, and auto-fixable vs human-review items.

@asarkar157

Copy link
Copy Markdown
Contributor Author

Module Review — Grade: 🟡 C

Grade C — Moderate issues requiring polish before org-wide distribution. The module is fundamentally sound with correct resource patterns, proper this naming, good output coverage, and sensitive handling of credentials. However, it has zero test coverage, zero validation blocks across all 13 variables, no terraform { required_providers } block, workspace-specific defaults, and several security hardening gaps. The LTR feature addition itself is well-implemented with sensible defaults.


📋 Variable Classification

Variable Type Classification Issue Status
server_name string REQUIRED Missing validation (1-63 chars, lowercase+hyphens) ⚠️
database_name string OPTIONAL Default "workshopdb" is workshop-specific ⚠️
resource_group_name string OPTIONAL Default "se-rg" is workspace-specific — should be REQUIRED
location string OPTIONAL Default "westus2" — opinionated regional assumption ⚠️
admin_login string REQUIRED Missing validation (Azure disallows "admin", "sa", etc.) ⚠️
admin_password string REQUIRED sensitive = true ✅ — missing complexity validation ⚠️
sku_name string OPTIONAL Missing validation for allowed SKU values ⚠️
max_size_gb number OPTIONAL Missing bounds validation ⚠️
tags map(string) OPTIONAL Fine
ltr_weekly_retention string OPTIONAL Missing ISO 8601 duration validation
ltr_monthly_retention string OPTIONAL Good default "P13M" — missing ISO 8601 validation
ltr_yearly_retention string OPTIONAL Missing ISO 8601 duration validation
ltr_week_of_year number OPTIONAL Missing validation (must be 1–52)

0 of 13 variables have validation blocks.


🏗️ Module Structure

Check Result
Tightly-coupled resources ✅ PASS — server + database + firewall rule
Resource naming (this) ✅ PASS
Tags locals merge pattern ❌ FAIL — raw var.tags passthrough, no locals merge
No provider blocks ✅ PASS
No backend blocks ✅ PASS
terraform { required_providers } ❌ FAIL — missing entirely; consumers cannot pin azurerm version
Outputs complete + described ✅ PASS — 5 outputs, all described
README with usage example ✅ PASS
Tests exist ❌ FAIL — zero test files in repo

🔒 Security Defaults

Check Result
Encryption at rest (TDE) ⚠️ INFO — platform default, not explicitly set
Encryption in transit (TLS 1.2) ✅ PASS — minimum_tls_version = "1.2" hardcoded
Public network access ❌ FAIL — defaults to true (provider default); should be false
Firewall rule 0.0.0.0 ⚠️ WARN — Azure-services convention, but not controllable via variable
Admin password handling ✅ PASS — sensitive = true on variable and output
Auditing policy ❌ FAIL — no azurerm_mssql_server_extended_auditing_policy
Threat detection ❌ FAIL — no azurerm_mssql_server_security_alert_policy
connection_string output ⚠️ WARN — embeds admin credentials (sensitive, but consumers may leak)
Azure AD authentication ⚠️ WARN — SQL-auth only, no azuread_administrator block
Deletion protection ⚠️ WARN — no lifecycle { prevent_destroy } on stateful resources

🌐 Org-Distribution Readiness

Check Result
Self-contained (no relative sources) ✅ PASS
All variables have descriptions ✅ PASS
All outputs have descriptions ✅ PASS
No workspace-specific assumptions ❌ FAIL — se-rg, workshopdb defaults
Version constraints on required_providers ❌ FAIL — no terraform block at all

✅ Functional Validation

Check Result
terraform fmt ✅ PASS
terraform init ✅ PASS (azurerm v4.76.0)
terraform validate ✅ PASS — Success! The configuration is valid.
terraform test ⏭️ SKIPPED — no tests/ directory

🔧 Suggested Fixes (Priority Order)

🔴 CRITICAL (auto-fixable)

  1. Add terraform { required_version = ">= 1.3"; required_providers { azurerm = { source = "hashicorp/azurerm", version = "~> 4.0" } } } — LTR features need azurerm ≥ 3.x.
  2. Add validation blocks to all 4 LTR variables (ISO 8601 regex for durations, 1 <= week <= 52).
  3. Add at least one tests/basic.tftest.hcl smoke test exercising the LTR block.

🟠 HIGH (auto-fixable)
4. Remove workspace-specific defaults — make resource_group_name REQUIRED (no default); reconsider database_name = "workshopdb" and location = "westus2".
5. Add public_network_access_enabled variable defaulting to false.
6. Make the firewall rule conditional via var.allow_azure_services (default false) using count.
7. Introduce locals { merged_tags = merge(var.tags, { "managed-by" = "terraform", "module" = "azure_tf_sql_database" }) } and use everywhere.
8. Add validation blocks to server_name, admin_login, admin_password, sku_name, max_size_gb.

🟡 MEDIUM (needs human review)
9. Add azurerm_mssql_server_extended_auditing_policy (or make optional via variable).
10. Add azurerm_mssql_server_security_alert_policy for threat detection.
11. Support Azure AD authentication via optional azuread_administrator block.
12. Consider splitting connection_string output into credential-free + credential-bearing variants, or document the Azure AD alternative.
13. Add lifecycle { prevent_destroy = true } (or variable-gated) on server/database.


📊 Summary

  • Violations: 16 total → 11 auto-fixable, 5 need human review
  • Functional validation: all checks passed (fmt, init, validate)
  • Grade ceiling: capped at B by zero test coverage; current C reflects validation/structure/security gaps
  • Positive notes: LTR implementation is clean, credentials properly marked sensitive, TLS 1.2 enforced, no IAM wildcards, no hardcoded secrets

Labeled platform-review-suggested. Address the CRITICAL and HIGH items before merging for org-wide distribution.

@asarkar157 asarkar157 left a comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Module Review — Grade: 🟡 C

Grade C — Moderate issues requiring polish before org-wide distribution. The module is fundamentally sound with correct resource patterns, proper this naming, good output coverage, and sensitive handling of credentials. However, it has zero test coverage, zero validation blocks across all 13 variables, no terraform { required_providers } block, workspace-specific defaults, and several security hardening gaps. The LTR feature addition itself is well-implemented with sensible defaults.


📋 Variable Classification

Variable Type Classification Issue Status
server_name string REQUIRED Missing validation (1-63 chars, lowercase+hyphens) ⚠️
database_name string OPTIONAL Default "workshopdb" is workshop-specific ⚠️
resource_group_name string OPTIONAL Default "se-rg" is workspace-specific — should be REQUIRED
location string OPTIONAL Default "westus2" — opinionated regional assumption ⚠️
admin_login string REQUIRED Missing validation (Azure disallows "admin", "sa", etc.) ⚠️
admin_password string REQUIRED sensitive = true ✅ — missing complexity validation ⚠️
sku_name string OPTIONAL Missing validation for allowed SKU values ⚠️
max_size_gb number OPTIONAL Missing bounds validation ⚠️
tags map(string) OPTIONAL Fine
ltr_weekly_retention string OPTIONAL Missing ISO 8601 duration validation
ltr_monthly_retention string OPTIONAL Good default "P13M" — missing ISO 8601 validation
ltr_yearly_retention string OPTIONAL Missing ISO 8601 duration validation
ltr_week_of_year number OPTIONAL Missing validation (must be 1–52)

0 of 13 variables have validation blocks.


🏗️ Module Structure

Check Result
Tightly-coupled resources ✅ PASS — server + database + firewall rule
Resource naming (this) ✅ PASS
Tags locals merge pattern ❌ FAIL — raw var.tags passthrough, no locals merge
No provider blocks ✅ PASS
No backend blocks ✅ PASS
terraform { required_providers } ❌ FAIL — missing entirely; consumers cannot pin azurerm version
Outputs complete + described ✅ PASS — 5 outputs, all described
README with usage example ✅ PASS
Tests exist ❌ FAIL — zero test files in repo

🔒 Security Defaults

Check Result
Encryption at rest (TDE) ⚠️ INFO — platform default, not explicitly set
Encryption in transit (TLS 1.2) ✅ PASS — minimum_tls_version = "1.2" hardcoded
Public network access ❌ FAIL — defaults to true (provider default); should be false
Firewall rule 0.0.0.0 ⚠️ WARN — Azure-services convention, but not controllable via variable
Admin password handling ✅ PASS — sensitive = true on variable and output
Auditing policy ❌ FAIL — no azurerm_mssql_server_extended_auditing_policy
Threat detection ❌ FAIL — no azurerm_mssql_server_security_alert_policy
connection_string output ⚠️ WARN — embeds admin credentials (sensitive, but consumers may leak)
Azure AD authentication ⚠️ WARN — SQL-auth only, no azuread_administrator block
Deletion protection ⚠️ WARN — no lifecycle { prevent_destroy } on stateful resources

🌐 Org-Distribution Readiness

Check Result
Self-contained (no relative sources) ✅ PASS
All variables have descriptions ✅ PASS
All outputs have descriptions ✅ PASS
No workspace-specific assumptions ❌ FAIL — se-rg, workshopdb defaults
Version constraints on required_providers ❌ FAIL — no terraform block at all

✅ Functional Validation

Check Result
terraform fmt ✅ PASS
terraform init ✅ PASS (azurerm v4.76.0)
terraform validate ✅ PASS — Success! The configuration is valid.
terraform test ⏭️ SKIPPED — no tests/ directory

🔧 Suggested Fixes (Priority Order)

🔴 CRITICAL (auto-fixable)

  1. Add terraform { required_version = ">= 1.3"; required_providers { azurerm = { source = "hashicorp/azurerm", version = "~> 4.0" } } } — LTR features need azurerm ≥ 3.x.
  2. Add validation blocks to all 4 LTR variables (ISO 8601 regex for durations, 1 <= week <= 52).
  3. Add at least one tests/basic.tftest.hcl smoke test exercising the LTR block.

🟠 HIGH (auto-fixable)
4. Remove workspace-specific defaults — make resource_group_name REQUIRED (no default); reconsider database_name = "workshopdb" and location = "westus2".
5. Add public_network_access_enabled variable defaulting to false.
6. Make the firewall rule conditional via var.allow_azure_services (default false) using count.
7. Introduce locals { merged_tags = merge(var.tags, { "managed-by" = "terraform", "module" = "azure_tf_sql_database" }) } and use everywhere.
8. Add validation blocks to server_name, admin_login, admin_password, sku_name, max_size_gb.

🟡 MEDIUM (needs human review)
9. Add azurerm_mssql_server_extended_auditing_policy (or make optional via variable).
10. Add azurerm_mssql_server_security_alert_policy for threat detection.
11. Support Azure AD authentication via optional azuread_administrator block.
12. Consider splitting connection_string output into credential-free + credential-bearing variants, or document the Azure AD alternative.
13. Add lifecycle { prevent_destroy = true } (or variable-gated) on server/database.


📊 Summary

  • Violations: 16 total → 11 auto-fixable, 5 need human review
  • Functional validation: all checks passed (fmt, init, validate)
  • Grade ceiling: capped at B by zero test coverage; current C reflects validation/structure/security gaps
  • Positive notes: LTR implementation is clean, credentials properly marked sensitive, TLS 1.2 enforced, no IAM wildcards, no hardcoded secrets

Labeled platform-review-suggested. Address the CRITICAL and HIGH items before merging for org-wide distribution.

@asarkar157 asarkar157 added the platform-review-suggested Platform reviewer suggested changes before merge label Jun 9, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

platform-review-suggested Platform reviewer suggested changes before merge review/grade-C Automated module review grade: C (moderate issues)

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add a long term data retention policy for 13 months

1 participant