Created
February 28, 2019 03:15
-
-
Save macropin/49f8a3c72afc157fa0d81688d26af677 to your computer and use it in GitHub Desktop.
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
#!/usr/bin/env bash | |
# Example of how to rename repos that are terraform managed | |
set -e | |
REPO='repo1 repo2 repo3' | |
TOKEN=xxxxxxxxxxxxx # Github Personal Access Token | |
for oldName in $REPO; do | |
# Function to generate newName from oldName | |
newName="$(echo $oldName | sed -e 's@foo@bar@g')" | |
echo ">> Renaming $oldName to $newName" | |
curl \ | |
-H "Authorization: Token ${TOKEN}" \ | |
-H "Content-Type:application/json" \ | |
-H "Accept: application/json" \ | |
-X PATCH \ | |
--data "{ \"name\": \"${newName}\" }" \ | |
https://api.github.com/repos/panubo/${oldName} | |
# then fudge the TF state | |
terraform state rm module.${oldName}.github_repository.repo | |
terraform import module.${newName}.github_repository.repo ${newName} | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment