Estou usando o Terraform para gerenciar uma organização do Github. Temos um módulo padrão "repositório comum" que usamos para garantir que nossos repositórios compartilhem uma configuração comum. Gostaria de adicionar suporte para configurar páginas do GitHub, o que requer suporte para o pages
elemento , que se parece com isso:
pages {
build_type = "legacy"
cname = "example.com"
source {
branch = "master"
path = "/docs"
}
}
Tudo é opcional. Em particular, source
é necessário somente se build_type == "legacy" || build_type == null
, e o bloco inteiro pages
pode ser omitido. Não consegui descobrir como fazer source
condicional, então acabei dividindo isso em dois dynamic
blocos assim:
# There are two `dynamic "pages"` blocks here to account for the fact that `source` is only required
# if `build_type` is "legacy". The `for_each` at the top of each block will only enable the block when
# the necessary conditions are met.
dynamic "pages" {
# enable this block if `pages` is not null and `build_type` is "legacy" (or null)
for_each = var.pages == null ? [] : var.pages.build_type == "legacy" || var.pages.build_type == null ? ["enabled"] : []
content {
source {
branch = var.pages.source.branch
path = var.pages.source.path
}
cname = var.pages.cname
build_type = var.pages.build_type
}
}
dynamic "pages" {
# enable this block if `pages` is not null and `build_type` is "workflow"
for_each = var.pages == null ? [] : var.pages.build_type == "workflow" ? ["enabled"] : []
content {
cname = var.pages.cname
build_type = var.pages.build_type
}
}
Onde eu defini a pages
variável no módulo assim:
variable "pages" {
description = "Configuration for github pages"
type = object({
source = optional(object({
branch = string
path = string
}))
build_type = optional(string, "legacy")
cname = optional(string)
})
default = null
}
Existe uma maneira melhor de abordar isso?