-
-
Notifications
You must be signed in to change notification settings - Fork 125
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[terraform/upgrade-modules] Update all module sources to latest version #95
Merged
Merged
Changes from 4 commits
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
2d3aed9
Add script to update all terraform module sources
osterman 728ffce
Merge branch 'master' into upgrade-tf-sources
osterman 3057f57
add shebang
osterman 68f8e32
Merge branch 'upgrade-tf-sources' of github.com:cloudposse/build-harn…
osterman 695c2ce
Add support for `GITHUB_TOKEN` access key. Install json2hcl.
osterman 71400a1
Merge branch 'master' into upgrade-tf-sources
aknysh File filter
Filter by extension
Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
There are no files selected for viewing
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,61 @@ | ||
#!/usr/bin/env bash | ||
|
||
function github_latest_release() { | ||
local org=$1 | ||
local repo=$2 | ||
local ref=$(curl -sSL https://api.github.com/repos/$org/$repo/releases/latest | jq .tag_name -r) | ||
if [ $? -eq 0 ]; then | ||
echo $ref | ||
fi | ||
} | ||
|
||
function upgrade_modules() { | ||
local file=$1 | ||
echo "Processing $file..." | ||
for source in $(json2hcl -reverse < $file | jq -r '.module | .[][] | first | .source' 2>/dev/null); do | ||
if [[ $source =~ github.com/ ]]; then | ||
echo "[GITHUB]: $source" | ||
if [[ $source =~ github.com/(.*?)/(.*?)\.git ]]; then | ||
org="${BASH_REMATCH[1]}" | ||
repo="${BASH_REMATCH[2]}" | ||
fi | ||
if [[ $source =~ \?ref=([0-9.]+) ]]; then | ||
ref="${BASH_REMATCH[1]}" | ||
fi | ||
if [[ $source =~ \?ref=tags/([0-9.]+) ]]; then | ||
ref="${BASH_REMATCH[1]}" | ||
fi | ||
|
||
if [ -z "$org" ] || [ -z "$repo" ] || [ -z "$ref" ]; then | ||
echo " - Failed to parse module source (org: $org, repo: $repo, ref: $ref)" | ||
else | ||
latest_ref=$(github_latest_release "$org" "$repo") | ||
latest_source="git::https://github.com/$org/$repo.git?ref=tags/$latest_ref" | ||
if [ "$latest_source" == "$source" ]; then | ||
echo " - Current: $ref" | ||
else | ||
echo " - Latest: $ref -> ${latest_ref}" | ||
echo " - Source: $latest_source" | ||
sed -i"" "s,$source,$latest_source,g" "$file" | ||
fi | ||
fi | ||
else | ||
echo "[SKIPPED]: $source" | ||
fi | ||
done | ||
} | ||
|
||
files="" | ||
if [ $# -eq 0 ]; then | ||
echo "Usage: $0 [all|file1.tf...fileN.tf]" | ||
exit 1 | ||
elif [ $1 == "all" ]; then | ||
files=$(find . -type f -name '*.tf') | ||
else | ||
files="$*" | ||
fi | ||
|
||
for file in $files; do | ||
upgrade_modules $file | ||
done | ||
|
This file contains 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
GitHub rate-limits unauthenticated calls to their api endpoint by source IP.
https://developer.github.com/changes/2012-10-14-rate-limit-changes/
I've found this kind of query works fine locally, but fails sporadically from CI. The typical workaround seems to be to create a bot user with zero access to anything, generate an access token, and then use basic auth in the curl command....
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You're right. I was just being lazy =)
I've added support for the tokens. Decided to use a header since that is less likely to show up in access logs. https://gist.github.com/caspyin/2288960#oauth