Skip to content

Instantly share code, notes, and snippets.

@macropin
Created February 28, 2019 03:15
Show Gist options
  • Save macropin/49f8a3c72afc157fa0d81688d26af677 to your computer and use it in GitHub Desktop.
Save macropin/49f8a3c72afc157fa0d81688d26af677 to your computer and use it in GitHub Desktop.
#!/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