Skip to content

Commit bb6ae09

Browse files
committed
Enable rotation config and topics in modules/secret-manager
1 parent 0734f00 commit bb6ae09

3 files changed

Lines changed: 38 additions & 21 deletions

File tree

modules/secret-manager/global.tf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -71,14 +71,19 @@ resource "google_secret_manager_secret" "default" {
7171
}
7272
}
7373
}
74-
# dynamic "rotation" {
75-
# for_each = try(each.value.rotation_config, null) == null ? [] : [""]
76-
# content {
77-
# next_rotation_time = each.value.rotation_config.next_time
78-
# rotation_period = each.value.rotation_config.period
79-
# }
80-
# }
81-
# topics
74+
dynamic "rotation" {
75+
for_each = try(each.value.rotation_config, null) == null ? [] : [""]
76+
content {
77+
next_rotation_time = each.value.rotation_config.next_time
78+
rotation_period = each.value.rotation_config.period
79+
}
80+
}
81+
dynamic "topics" {
82+
for_each = coalesce(try(each.value.topics, null), [])
83+
content {
84+
name = topics.value
85+
}
86+
}
8287
lifecycle {
8388
ignore_changes = [
8489
rotation[0].next_rotation_time

modules/secret-manager/regional.tf

Lines changed: 13 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -43,14 +43,19 @@ resource "google_secret_manager_regional_secret" "default" {
4343
)
4444
}
4545
}
46-
# dynamic "rotation" {
47-
# for_each = try(each.value.rotation_config, null) == null ? [] : [""]
48-
# content {
49-
# next_rotation_time = each.value.rotation_config.next_time
50-
# rotation_period = each.value.rotation_config.period
51-
# }
52-
# }
53-
# topics
46+
dynamic "rotation" {
47+
for_each = try(each.value.rotation_config, null) == null ? [] : [""]
48+
content {
49+
next_rotation_time = each.value.rotation_config.next_time
50+
rotation_period = each.value.rotation_config.period
51+
}
52+
}
53+
dynamic "topics" {
54+
for_each = coalesce(try(each.value.topics, null), [])
55+
content {
56+
name = topics.value
57+
}
58+
}
5459
lifecycle {
5560
ignore_changes = [
5661
rotation[0].next_rotation_time

modules/secret-manager/variables.tf

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,20 @@ variable "secrets" {
100100
write_only_version = optional(number)
101101
}))
102102
})), {})
103-
# rotation_config = optional(object({
104-
# next_time = string
105-
# period = number
106-
# }))
107-
# topics
103+
rotation_config = optional(object({
104+
next_time = optional(string)
105+
period = string
106+
}))
107+
topics = optional(list(string))
108108
}))
109109
default = {}
110+
validation {
111+
condition = alltrue([
112+
for k, v in var.secrets :
113+
try(v.rotation_config, null) == null || (try(length(v.topics), 0) > 0)
114+
])
115+
error_message = "At least one topic must be configured when rotation_config is set."
116+
}
110117
validation {
111118
condition = alltrue([
112119
for k, v in var.secrets :

0 commit comments

Comments
 (0)