This script was copied and adapted from the project: https://github.com/chrisanthropic/terraform-import-github-organization
- An existing Github account with a user that belongs to an organization
- A github personal access token with the following permissions:
- repo (all)
- admin:org (all)
- Terraform
- jq
-
git clone
this repo -
create a basic terraform configuration file, e.g.
main.tf
with something like:provider "github" { token = "TOKENGOESHERE" organization = "my_org" # optional, if using GitHub Enterprise base_url = "https://github.mycompany.com/api/v3/" }
-
run
terraform init
to e.g. install the GitHub provider -
configure the variables at the top of the script
GITHUB_TOKEN=...
ORG=...
- if you're using GitHub Enterprise,
API_URL_PREFIX=...
or remember to pass them in via the environment
-
run the scriptm, perhaps passing the necessary environment variables
GITHUB_TOKEN=12334...4555 ORG=my_org terraform-import-github-org.sh
-
run a terraform plan to see that everything was imported and that no changes are required.
- some manual modifications could be required since not every field supported by Terraform has been implemented by this script.
- HEADS UP - the script hardcodes user roles to "member".