diff --git a/CHANGELOG.md b/CHANGELOG.md index 0191d994..dbcd4c94 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,12 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 ## [Unreleased] +## [0.9.1] + +### Added + +- Add support for GitHub Pages configuration in repositories + ## [0.9.0] ### Added @@ -244,12 +250,13 @@ Please review plans and report regressions and issues asap so we can improve doc -[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.9.0...HEAD -[0.9.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.8.0...v0.9.0 -[0.8.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.7.0...v0.8.0 +[unreleased]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.9.1...HEAD +[0.9.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.9.0...v0.9.1 +[0.9.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.8.0...v0.9.0 +[0.8.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.7.0...v0.8.0 [0.7.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.1...v0.7.0 [0.6.1]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.6.0...v0.6.1 [0.6.0]: https://github.com/mineiros-io/terraform-github-repository/compare/v0.5.1...v0.6.0 diff --git a/README.md b/README.md index 6a39be9f..a5f8b094 100644 --- a/README.md +++ b/README.md @@ -35,6 +35,7 @@ _Version `>= 0.8.0` of this module is compatible with `mineiros-io/team/github > - [Secrets Configuration](#secrets-configuration) - [`defaults` Object Attributes](#defaults-object-attributes) - [`template` Object Attributes](#template-object-attributes) + - [`pages` Object Attributes](#pages-object-attributes) - [`deploy_key` Object Attributes](#deploy_key-object-attributes) - [`branch_protection` Object Attributes](#branch_protection-object-attributes) - [`required_status_checks` Object Attributes](#required_status_checks-object-attributes) @@ -128,6 +129,12 @@ See [variables.tf] and [examples/] for details and use-cases. See below for a list of supported arguments. Default is `{}` - use module defaults as described in the README. +- **[`pages`](#pages-object-attributes)**: _(Optional `object`)_ + + A object of settings to configure GitHub Pages in this repository. + See below for a list of supported arguments. + Default is `null`. + - **`allow_merge_commit`**: _(Optional `bool`)_ Set to `false` to disable merge commits on the repository. @@ -459,6 +466,26 @@ Module defaults are used for all arguments that are not set in `defaults`. Using top level arguments override defaults set by this argument. Default is `{}`. +#### [`pages`](#pages-object-attributes) Object Attributes + +This block is used for configuring GitHub Pages for the repository. +The following top-level arguments must be set to configure GitHub Pages for +the repository: + +- **`branch`**: **_(Required `string`)_** + + The repository branch used to publish the site's source files. + +- **`path`**: **_(Optional `string`)_** + + The repository directory from which the site publishes. + +- **`cname`**: **_(Optional `string`)_** + + The custom domain for the repository. This can only be set after the + repository has been created. + Default is `null`. + #### [`template`](#repository-creation-configuration) Object Attributes - **`owner`**: **_(Required `string`)_** diff --git a/main.tf b/main.tf index 7c65354d..4df9d2fd 100644 --- a/main.tf +++ b/main.tf @@ -118,6 +118,18 @@ resource "github_repository" "repository" { } } + dynamic "pages" { + for_each = var.pages != null ? [true] : [] + + content { + source { + branch = var.pages.branch + path = try(var.pages.path, "/") + } + cname = try(var.pages.cname, null) + } + } + lifecycle { ignore_changes = [ auto_init, diff --git a/test/unit-complete/main.tf b/test/unit-complete/main.tf index 06fe231d..f22928de 100644 --- a/test/unit-complete/main.tf +++ b/test/unit-complete/main.tf @@ -66,6 +66,11 @@ module "repository" { (var.secret_name) = var.secret_text } + pages = { + branch = "main" + path = "/" + } + webhooks = [{ active = var.webhook_active events = var.webhook_events diff --git a/variables.tf b/variables.tf index 47615891..cae5080f 100644 --- a/variables.tf +++ b/variables.tf @@ -4,7 +4,7 @@ # --------------------------------------------------------------------------------------------------------------------- variable "name" { - description = "The name of the repository." + description = "(Required) The name of the repository." type = string } @@ -14,7 +14,7 @@ variable "name" { # --------------------------------------------------------------------------------------------------------------------- variable "defaults" { - description = "Overwrite defaults for various repository settings" + description = "(Optional) Overwrite defaults for various repository settings" type = any # Example: @@ -40,127 +40,138 @@ variable "defaults" { } variable "description" { - description = "A description of the repository." + description = "(Optional) A description of the repository." type = string default = "" } variable "homepage_url" { - description = "The website of the repository." + description = "(Optional) The website of the repository." type = string default = null } variable "private" { - description = "(DEPRECATED: use visibility)" + description = "(Optional) (DEPRECATED: use visibility)" type = bool default = null } variable "visibility" { - description = "Can be 'public', 'private' or 'internal' (GHE only).The visibility parameter overrides the private parameter. Defaults to 'private' if neither private nor visibility are set, default to state of private parameter if it is set." + description = "(Optional) Can be 'public', 'private' or 'internal' (GHE only).The visibility parameter overrides the private parameter. Defaults to 'private' if neither private nor visibility are set, default to state of private parameter if it is set." type = string default = null } variable "has_issues" { - description = "Set to true to enable the GitHub Issues features on the repository. (Default: false)" + description = "(Optional) Set to true to enable the GitHub Issues features on the repository. (Default: false)" type = bool default = null } variable "has_projects" { - description = "Set to true to enable the GitHub Projects features on the repository. Per the github documentation when in an organization that has disabled repository projects it will default to false and will otherwise default to true. If you specify true when it has been disabled it will return an error. (Default: false)" + description = "(Optional) Set to true to enable the GitHub Projects features on the repository. Per the github documentation when in an organization that has disabled repository projects it will default to false and will otherwise default to true. If you specify true when it has been disabled it will return an error. (Default: false)" type = bool default = null } variable "has_wiki" { - description = "Set to true to enable the GitHub Wiki features on the repository. (Default: false)" + description = "(Optional) Set to true to enable the GitHub Wiki features on the repository. (Default: false)" type = bool default = null } variable "allow_merge_commit" { - description = "Set to false to disable merge commits on the repository. (Default: true)" + description = "(Optional) Set to false to disable merge commits on the repository. (Default: true)" type = bool default = null } variable "allow_squash_merge" { - description = "Set to true to enable squash merges on the repository. (Default: false)" + description = "(Optional) Set to true to enable squash merges on the repository. (Default: false)" type = bool default = null } variable "allow_rebase_merge" { - description = "Set to true to enable rebase merges on the repository. (Default: false)" + description = "(Optional) Set to true to enable rebase merges on the repository. (Default: false)" type = bool default = null } variable "delete_branch_on_merge" { - description = "Whether or not to delete the merged branch after merging a pull request. (Default: false)" + description = "(Optional) Whether or not to delete the merged branch after merging a pull request. (Default: false)" type = bool default = null } variable "has_downloads" { - description = "Set to true to enable the (deprecated) downloads features on the repository. (Default: false)" + description = "(Optional) Set to true to enable the (deprecated) downloads features on the repository. (Default: false)" type = bool default = null } variable "auto_init" { - description = "Wether or not to produce an initial commit in the repository. (Default: true)" + description = "(Optional) Wether or not to produce an initial commit in the repository. (Default: true)" type = bool default = null } +variable "pages" { + description = "(Optional) The repository's GitHub Pages configuration. (Default: {})" + # type = object({ + # branch = string + # path = string + # cname = string + # }) + type = any + default = null +} + variable "gitignore_template" { - description = "Use the name of the template without the extension. For example, Haskell. Available templates: https://github.com/github/gitignore" + description = "(Optional) Use the name of the template without the extension. For example, Haskell. Available templates: https://github.com/github/gitignore" type = string default = null } variable "is_template" { - description = "Whether or not to tell GitHub that this is a template repository. ( Default: false)" + description = "(Optional) Whether or not to tell GitHub that this is a template repository. ( Default: false)" type = bool default = null } variable "license_template" { - description = "Use the name of the template without the extension. For example, 'mit' or 'mpl-2.0'. Available licences: https://github.com/github/choosealicense.com/tree/gh-pages/_licenses" + description = "(Optional) Use the name of the template without the extension. For example, 'mit' or 'mpl-2.0'. Available licences: https://github.com/github/choosealicense.com/tree/gh-pages/_licenses" type = string default = null } variable "default_branch" { - description = "The name of the default branch of the repository. NOTE: This can only be set after a repository has already been created, and after a correct reference has been created for the target branch inside the repository. This means a user will have to omit this parameter from the initial repository creation and create the target branch inside of the repository prior to setting this attribute." + description = "(Optional) The name of the default branch of the repository. NOTE: This can only be set after a repository has already been created, and after a correct reference has been created for the target branch inside the repository. This means a user will have to omit this parameter from the initial repository creation and create the target branch inside of the repository prior to setting this attribute." type = string default = null } variable "archived" { - description = "Specifies if the repository should be archived. (Default: false)" + description = "(Optional) Specifies if the repository should be archived. (Default: false)" type = bool default = false } variable "topics" { - description = "The list of topics of the repository. (Default: [])" + description = "(Optional) The list of topics of the repository. (Default: [])" type = list(string) default = null } variable "extra_topics" { - description = "The list of additional topics of the repository. (Default: [])" + description = "(Optional) The list of additional topics of the repository. (Default: [])" type = list(string) default = [] } variable "template" { - description = "Template repository to use. (Default: {})" + description = "(Optional) Template repository to use. (Default: {})" type = object({ owner = string repository = string @@ -169,91 +180,91 @@ variable "template" { } variable "admin_collaborators" { - description = "A list of users to add as collaborators granting them admin (full) permission." + description = "(Optional) A list of users to add as collaborators granting them admin (full) permission." type = list(string) default = [] } variable "push_collaborators" { - description = "A list of users to add as collaborators granting them push (read-write) permission." + description = "(Optional) A list of users to add as collaborators granting them push (read-write) permission." type = list(string) default = [] } variable "pull_collaborators" { - description = "A list of users to add as collaborators granting them pull (read-only) permission." + description = "(Optional) A list of users to add as collaborators granting them pull (read-only) permission." type = list(string) default = [] } variable "triage_collaborators" { - description = "A list of users to add as collaborators granting them triage permission." + description = "(Optional) A list of users to add as collaborators granting them triage permission." type = list(string) default = [] } variable "maintain_collaborators" { - description = "A list of users to add as collaborators granting them maintain permission." + description = "(Optional) A list of users to add as collaborators granting them maintain permission." type = list(string) default = [] } variable "admin_team_ids" { - description = "A list of teams (by id) to grant admin (full) permission to." + description = "(Optional) A list of teams (by id) to grant admin (full) permission to." type = list(string) default = [] } variable "push_team_ids" { - description = "A list of teams (by id) to grant push (read-write) permission to." + description = "(Optional) A list of teams (by id) to grant push (read-write) permission to." type = list(string) default = [] } variable "pull_team_ids" { - description = "A list of teams (by id) to grant pull (read-only) permission to." + description = "(Optional) A list of teams (by id) to grant pull (read-only) permission to." type = list(string) default = [] } variable "triage_team_ids" { - description = "A list of teams (by id) to grant triage permission to." + description = "(Optional) A list of teams (by id) to grant triage permission to." type = list(string) default = [] } variable "maintain_team_ids" { - description = "A list of teams (by id) to grant maintain permission to." + description = "(Optional) A list of teams (by id) to grant maintain permission to." type = list(string) default = [] } variable "admin_teams" { - description = "A list of teams (by name/slug) to grant admin (full) permission to." + description = "(Optional) A list of teams (by name/slug) to grant admin (full) permission to." type = list(string) default = [] } variable "push_teams" { - description = "A list of teams (by name/slug) to grant push (read-write) permission to." + description = "(Optional) A list of teams (by name/slug) to grant push (read-write) permission to." type = list(string) default = [] } variable "pull_teams" { - description = "A list of teams (by name/slug) to grant pull (read-only) permission to." + description = "(Optional) A list of teams (by name/slug) to grant pull (read-only) permission to." type = list(string) default = [] } variable "triage_teams" { - description = "A list of teams (by name/slug) to grant triage permission to." + description = "(Optional) A list of teams (by name/slug) to grant triage permission to." type = list(string) default = [] } variable "maintain_teams" { - description = "A list of teams (by name/slug) to grant maintain permission to." + description = "(Optional) A list of teams (by name/slug) to grant maintain permission to." type = list(string) default = [] } @@ -265,7 +276,7 @@ variable "branch_protections" { } variable "branch_protections_v3" { - description = "A list of branch protections to apply to the repository. Default is [] unless branch_protections is set." + description = "(Optional) A list of branch protections to apply to the repository. Default is [] unless branch_protections is set." type = any # We can't use a detailed type specification due to a terraform limitation. However, this might be changed in a future @@ -323,19 +334,19 @@ variable "branch_protections_v3" { } variable "issue_labels_merge_with_github_labels" { - description = "Specify if you want to merge and control githubs default set of issue labels." + description = "(Optional) Specify if you want to merge and control githubs default set of issue labels." type = bool default = null } variable "issue_labels_create" { - description = "Specify whether you want to force or suppress the creation of issues labels." + description = "(Optional) Specify whether you want to force or suppress the creation of issues labels." type = bool default = null } variable "issue_labels" { - description = "Configure a GitHub issue label resource." + description = "(Optional) Configure a GitHub issue label resource." type = list(object({ name = string description = string @@ -360,7 +371,7 @@ variable "issue_labels" { } variable "deploy_keys" { - description = "Configure a deploy key ( SSH key ) that grants access to a single GitHub repository. This key is attached directly to the repository instead of to a personal user account." + description = "(Optional) Configure a deploy key ( SSH key ) that grants access to a single GitHub repository. This key is attached directly to the repository instead of to a personal user account." type = any # Example: @@ -381,7 +392,7 @@ variable "deploy_keys" { } variable "deploy_keys_computed" { - description = "Configure a deploy key ( SSH key ) that grants access to a single GitHub repository. This key is attached directly to the repository instead of to a personal user account." + description = "(Optional) Configure a deploy key ( SSH key ) that grants access to a single GitHub repository. This key is attached directly to the repository instead of to a personal user account." type = any # Example: @@ -397,7 +408,7 @@ variable "deploy_keys_computed" { } variable "projects" { - description = "Create and manage projects for GitHub repository." + description = "(Optional) Create and manage projects for GitHub repository." type = list(object({ name = string body = string @@ -414,14 +425,8 @@ variable "projects" { default = [] } -variable "module_depends_on" { - type = any - description = "Define resources this module indirectly depends_on." - default = [] -} - variable "webhooks" { - description = "Configuring webhooks. For details please check: https://www.terraform.io/docs/providers/github/r/repository_webhook.html" + description = "(Optional) Configuring webhooks. For details please check: https://www.terraform.io/docs/providers/github/r/repository_webhook.html" type = any # We can't use a detailed type specification due to a terraform limitation. However, this might be changed in a future @@ -450,7 +455,7 @@ variable "webhooks" { } variable "plaintext_secrets" { - description = "Configuring actions secrets. For details please check: https://www.terraform.io/docs/providers/github/r/actions_secret.html" + description = "(Optional) Configuring actions secrets. For details please check: https://www.terraform.io/docs/providers/github/r/actions_secret.html" type = map(string) # Example: @@ -473,3 +478,14 @@ variable "archive_on_destroy" { description = "(Optional) Set to `false` to not archive the repository instead of deleting on destroy." default = true } + +# ------------------------------------------------------------------------------ +# MODULE CONFIGURATION PARAMETERS +# These variables are used to configure the module. +# ------------------------------------------------------------------------------ + +variable "module_depends_on" { + type = any + description = "(Optional) Define resources this module indirectly depends_on." + default = [] +} diff --git a/versions.tf b/versions.tf index 1a52a26f..3f6f3797 100644 --- a/versions.tf +++ b/versions.tf @@ -5,8 +5,8 @@ terraform { required_version = ">= 0.12.20, < 0.16" - # 4.7.0 to 4.9.1 has a security regression: new repositories created via a template have a public visibility - # fixed in 4.9.2 + # 4.7.0 to 4.9.1 has a security regression: new repositories created via a + # template have a public visibility. Has been fixed in 4.9.2. required_providers { github = ">= 4.5, < 5.0, != 4.7.0, != 4.8.0, != 4.9.0, != 4.9.1" }