Skip to content

Latest commit

 

History

History
45 lines (36 loc) · 1.49 KB

File metadata and controls

45 lines (36 loc) · 1.49 KB

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