Skip to content

Commit 95e48a1

Browse files
authored
fix: for_each issue on the sql_audit_config (#340)
* fix for_each issue on the sql_audit_config * fix for_each issue on the sql_audit_config * fix for_each issue on the sql_audit_config
1 parent cf8fc4c commit 95e48a1

File tree

7 files changed

+25
-3
lines changed

7 files changed

+25
-3
lines changed

examples/mssql-public/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ This example shows how create MS SQL Server database using the Terraform module.
1010
| name | The name for Cloud SQL instance | `string` | `"tf-mssql-public"` | no |
1111
| project\_id | The project to run tests against | `string` | n/a | yes |
1212
| region | n/a | `string` | `"us-central1"` | no |
13+
| sql\_server\_audit\_config | SQL server audit config settings. | `map(string)` | `{}` | no |
1314

1415
## Outputs
1516

examples/mssql-public/main.tf

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,4 +23,6 @@ module "mssql" {
2323
user_password = "foobar"
2424

2525
deletion_protection = false
26+
27+
sql_server_audit_config = var.sql_server_audit_config
2628
}

examples/mssql-public/variables.tf

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,3 +29,9 @@ variable "region" {
2929
default = "us-central1"
3030
type = string
3131
}
32+
33+
variable "sql_server_audit_config" {
34+
description = "SQL server audit config settings."
35+
type = map(string)
36+
default = {}
37+
}

modules/mssql/README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,7 @@ The following dependency must be available for SQL Server module:
3939
| random\_instance\_name | Sets random suffix at the end of the Cloud SQL resource name | `bool` | `false` | no |
4040
| region | The region of the Cloud SQL resources | `string` | `"us-central1"` | no |
4141
| root\_password | MSSERVER password for the root user. If not set, a random one will be generated and available in the root\_password output variable. | `string` | `""` | no |
42-
| sql\_server\_audit\_config | Active domain that the SQL instance will join. | `map(string)` | `{}` | no |
42+
| sql\_server\_audit\_config | SQL server audit config settings. | `map(string)` | `{}` | no |
4343
| tier | The tier for the master instance. | `string` | `"db-custom-2-3840"` | no |
4444
| update\_timeout | The optional timeout that is applied to limit long database updates. | `string` | `"15m"` | no |
4545
| user\_labels | The key/value labels for the master instances. | `map(string)` | `{}` | no |

modules/mssql/main.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ resource "google_sql_database_instance" "default" {
111111
}
112112

113113
dynamic "sql_server_audit_config" {
114-
for_each = var.sql_server_audit_config
114+
for_each = length(var.sql_server_audit_config) != 0 ? [var.sql_server_audit_config] : []
115115
content {
116116
bucket = lookup(var.sql_server_audit_config, "bucket", null)
117117
upload_interval = lookup(var.sql_server_audit_config, "upload_interval", null)

modules/mssql/variables.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,7 +131,7 @@ variable "active_directory_config" {
131131
}
132132

133133
variable "sql_server_audit_config" {
134-
description = "Active domain that the SQL instance will join."
134+
description = "SQL server audit config settings."
135135
type = map(string)
136136
default = {}
137137
}

test/fixtures/mssql-public/main.tf

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,21 @@ locals {
3939
instance_name = "${var.name}-${random_id.instance_name_suffix.hex}"
4040
}
4141

42+
resource "google_storage_bucket" "sql_server_audit_logs" {
43+
project = var.project_id
44+
name = "sql-server-audit-${random_id.instance_name_suffix.hex}"
45+
location = "US"
46+
force_destroy = true
47+
}
48+
4249
module "mssql" {
4350
source = "../../../examples/mssql-public"
4451
name = local.instance_name
4552
project_id = var.project_id
53+
54+
sql_server_audit_config = {
55+
bucket = google_storage_bucket.sql_server_audit_logs.url
56+
upload_interval = "300s"
57+
retention_interval = "172800s" #2days
58+
}
4659
}

0 commit comments

Comments
 (0)