diff --git a/main.tf b/main.tf index 6dd06ff..a967778 100644 --- a/main.tf +++ b/main.tf @@ -58,8 +58,9 @@ resource "github_repository" "this" { dynamic "pages" { for_each = var.pages != null ? { this = var.pages } : {} content { + build_type = pages.value["build_type"] dynamic "source" { - for_each = { this = pages.value["source"] } + for_each = pages.value["build_type"] == "legacy" ? { this = pages.value["source"] } : {} content { branch = source.value["branch"] path = source.value["path"] diff --git a/variables.tf b/variables.tf index 8142b0f..8d2b465 100644 --- a/variables.tf +++ b/variables.tf @@ -224,12 +224,17 @@ variable "collaborators" { variable "pages" { type = object({ - source = object({ + build_type = optional(string, "legacy") + source = optional(object({ branch = string path = string - }) + })) }) - default = null + default = null + validation { + condition = var.pages == null ? true : var.pages.build_type == "legacy" ? try(var.pages.source.branch, "") != "" && try(var.pages.source.path, "") != "" : true + error_message = "When build type is legacy for pages source branch and path are required." + } description = "The repository's GitHub Pages configuration." }