Skip to content

Commit 7a87fc2

Browse files
committed
fix: Validate 'pages' is defined correctly. (#8)
1 parent 035f478 commit 7a87fc2

File tree

2 files changed

+31
-8
lines changed

2 files changed

+31
-8
lines changed

variables.tf

Lines changed: 30 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -122,14 +122,37 @@ variable "auto_init" {
122122

123123
variable "pages" {
124124
description = "(Optional) The repository's GitHub Pages configuration. (Default: {})"
125-
# type = object({
126-
# branch = string
127-
# path = string or null
128-
# cname = string
129-
# build_type = workflow or legacy (requires branch and optional path )
130-
# })
131-
type = any
125+
type = object({
126+
branch = optional(string)
127+
path = optional(string, null)
128+
cname = optional(string)
129+
build_type = optional(string, "legacy") # requires branch and optional path
130+
})
132131
default = null
132+
133+
validation {
134+
condition = (
135+
var.pages == null
136+
||
137+
contains(["workflow", "legacy"], try(var.pages.build_type, "legacy"))
138+
)
139+
140+
error_message = "The 'build_type' value must be either 'workflow' or 'legacy'."
141+
}
142+
143+
validation {
144+
condition = (
145+
var.pages == null
146+
||
147+
try(var.pages.build_type, "legacy") != "legacy"
148+
||
149+
(
150+
try(trim(var.pages.branch, " "), "") != ""
151+
)
152+
)
153+
154+
error_message = "When 'build_type' is 'legacy' (or default), a branch must be specified."
155+
}
133156
}
134157

135158
variable "gitignore_template" {

versions.tf

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
# ---------------------------------------------------------------------------------------------------------------------
44

55
terraform {
6-
required_version = "~> 1.0"
6+
required_version = "~> 1.3"
77

88
required_providers {
99
github = {

0 commit comments

Comments
 (0)