Skip to content

Script to fully automate Terraform import of Github Org (teams, users, and repos)

License

Notifications You must be signed in to change notification settings

jhonmike/terraform-import-github-organization

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Scripts

terraform-import-github-org.sh

This script was copied and adapted from the project: https://github.com/chrisanthropic/terraform-import-github-organization

How to use the script

Requirements

  • 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

Do it

  • 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".

About

Script to fully automate Terraform import of Github Org (teams, users, and repos)

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • Shell 70.8%
  • HCL 29.2%