A Terraform/OpenTofu module to provision a GitHub repository with GitHub Pages enabled, and to configure the necessary DNS A and CNAME records using the Spaceship provider.
- Creates a new GitHub repository with an initial commit.
- Automatically enables GitHub Pages on the
masterbranch. - Sets the repository's custom domain to your desired domain name.
- Connects to the
spaceshipprovider and creates the 4 standard GitHub Pages A records and thewwwCNAME record for the domain.
Warning
GitHub Pages requires the repository to be public for GitHub Free accounts.
According to the official documentation, "GitHub Pages is available in public repositories with GitHub Free and GitHub Free for organizations, and in public and private repositories with GitHub Pro, GitHub Team, GitHub Enterprise Cloud, and GitHub Enterprise."
Keep this in mind since the default repository_settings.visibility is set to "private"!
For personal use on a free GitHub account, you need to set the repository_settings.visibility to "public"!
Provider Bug #3450 Workaround: Due to a known bug in the GitHub Terraform Provider, the cname and https_enforced settings cannot be reliably managed by the github_repository_pages resource. This module uses a null_resource with a local-exec provisioner to configure these settings via the GitHub REST API. This workaround has specific requirements:
- System Dependencies: You must have
bash,curl, andjqinstalled on the system where Terraform is executed.
This module requires authentication with both GitHub and Spaceship:
- GitHub: You must set the
GITHUB_TOKENenvironment variable. While Terraform can authenticate using the GitHub CLI (gh auth login), thelocal-execprovisioner script used for the GitHub Pages workaround requires theGITHUB_TOKENenvironment variable to be explicitly set to interact directly with the GitHub API.- Note for Deletion: If you plan to destroy the repository using Terraform, you must have the
delete_reposcope on your token.
- Note for Deletion: If you plan to destroy the repository using Terraform, you must have the
- Spaceship: You must provide your Spaceship API credentials by setting the
SPACESHIP_API_KEYandSPACESHIP_API_SECRETenvironment variables.
module "spaceship_github_pages" {
source = "../"
domain = "example-test.com"
name = "example-test-repo"
}See the examples/ directory for more use cases.
| Name | Version |
|---|---|
| terraform | 1.15.6 |
| github | ~> 6.0 |
| null | ~> 3.0 |
| spaceship | >= 0.4.1 |
| time | ~> 0.12 |
| Name | Version |
|---|---|
| github | 6.12.1 |
| null | 3.3.0 |
| spaceship | 0.5.1 |
No modules.
| Name | Type |
|---|---|
| github_branch_default.this | resource |
| github_branch_protection.this | resource |
| github_repository.this | resource |
| github_repository_pages.this | resource |
| null_resource.configure_cname_enforce_https | resource |
| spaceship_dns_records.this | resource |
| github_user.current | data source |
| Name | Description | Type | Default | Required |
|---|---|---|---|---|
| branch_protection | Settings for the GitHub branch protection | object({ |
{} |
no |
| dns_settings | Additional custom DNS records for Spaceship | object({ |
{} |
no |
| domain | The custom domain for GitHub Pages (e.g., example.com) | string |
n/a | yes |
| name | Name of the GitHub repository to create | string |
n/a | yes |
| organization | Optional GitHub organization to create the repository in | string |
"" |
no |
| pages_settings | Settings for the GitHub Pages configuration | object({ |
{} |
no |
| repository_settings | Detailed settings for the GitHub repository | object({ |
{} |
no |
| user | Optional GitHub user to create the repository under | string |
"" |
no |
| Name | Description |
|---|---|
| domain | The configured custom domain |
| pages_url | URL of the GitHub Pages site |
| repository_name | Name of the created GitHub repository |
| repository_url | URL of the created GitHub repository |
Report issues/questions/feature requests on in the issues section.
Full contributing guidelines are covered here.
Apache 2 Licensed. See LICENSE for full details.
If you discover any security related issues, please email ivan.kornienko@gmail.com instead of using the issue tracker. All security vulnerabilities will be promptly addressed.