Last active
May 17, 2018 06:13
-
-
Save aerostitch/40828c5c2a4bd8430fefb4795a9059fe to your computer and use it in GitHub Desktop.
Import github resources in terraform
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export ORG=VEVO | |
# generate import commands for users in the org | |
# /!\ Note the parge_arg, this one looks for the page number 2 of the list | |
export page_arg="page=2" | |
curl -s -H "Authorization: token ${GITHUB_AUTH_TOKEN}" https://api.github.com/orgs/VEVO/members?${page_arg} | jq -r '.[]| "terraform import github_membership.\(.login) VEVO:\(.login)"' | |
# generate import commands for teams in the org | |
# /!\ Note the parge_arg, this one looks for the page number 2 of the list | |
export page_arg="page=2" | |
curl -s -H "Authorization: token ${GITHUB_AUTH_TOKEN}" https://api.github.com/orgs/${ORG}/teams?${page_arg} | jq -r '.[]| "terraform import github_team.\(.slug) \(.id)"' | |
# generate import commands for team memberships | |
curl -s -H "Authorization: token ${GITHUB_AUTH_TOKEN}" https://api.github.com/orgs/${ORG}/teams | jq -r '.[] | "\(.id) \(.slug)"' | while read -r teamId teamSlug ; do | |
# Be careful, you only get the 1st page here! | |
curl -s -H "Authorization: token ${GITHUB_AUTH_TOKEN}" https://api.github.com/teams/${teamId}/members | jq -r '.[] | "terraform import github_team_membership.\(.login)-'${teamSlug}' '${teamId}':\(.login)"'; | |
done | |
curl -s -H "Authorization: token ${GITHUB_AUTH_TOKEN}" https://api.github.com/orgs/${ORG}/teams | jq -r '.[] | "\(.id) \(.slug)"' | while read -r teamId teamSlug ; do | |
# get 3 pages all the time | |
for i in $(seq 1 3); do | |
page_arg="page=${i}" | |
curl -s -H "Authorization: token ${GITHUB_AUTH_TOKEN}" https://api.github.com/teams/${teamId}/members?${page_arg} | jq -r '.[] | "terraform import github_team_membership.\(.login)-'${teamSlug}' '${teamId}':\(.login)"'; | |
done | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment