- Notifications
You must be signed in to change notification settings - Fork1k
chore(provisioner/terraform): minimize testdata diff#16908
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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.
Already on GitHub?Sign in to your account
Conversation
It was hard to deduce whether or not changes in our terraform testdataare relevant or not, so we now have a rudimentary filter for randomlygenerated values that aren't relevant for the testdata.
162fbc3
tofea7f9e
Compareminimize_diff() { | ||
forfin*.tf*.json;do | ||
declare -A deleted=() | ||
declare -a sed_args=() | ||
whileread -r line;do | ||
# Deleted line (previous value). | ||
if [[$line= -\* ]];then | ||
key="${line#*\"}" | ||
key="${key%%\"*}" | ||
value="${line#*: }" | ||
value="${value#*\"}" | ||
value="${value%\"*}" | ||
declare deleted["$key"]="$value" | ||
# Added line (new value). | ||
elif [[$line= +\* ]];then | ||
key="${line#*\"}" | ||
key="${key%%\"*}" | ||
value="${line#*: }" | ||
value="${value#*\"}" | ||
value="${value%\"*}" | ||
# Matched key, restore the value. | ||
if [[ -v deleted["$key"] ]];then | ||
sed_args+=(-e"s|${value}|${deleted["$key"]}|g") | ||
unset deleted["$key"] | ||
fi | ||
fi | ||
if [[${#sed_args[@]}-gt 0 ]];then | ||
# Handle macOS compat. | ||
if sed -h2>&1| grep -q"\[-i extension\]";then | ||
sed -i''"${sed_args[@]}""$f" | ||
else | ||
sed -i''"${sed_args[@]}""$f" | ||
fi | ||
fi | ||
done<<( | ||
# Filter out known keys with autogenerated values. | ||
git diff --"$f"| | ||
grep -E"\"(terraform_version|id|agent_id|resource_id|token|random|timestamp)\":" | ||
) | ||
done | ||
} |
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.
I think this can be performed byjq
usingwalk
or similar?
jq 'walk(if type == "object" then with_entries(select(.key | test("(terraform_version|id|agent_id|resource_id|token|random|timestamp)") | not)) else . end)'
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.
I think that would give you the current value, but not the previous (or whether or not it changed) 🤔.
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.
stamp 👍
a1f5468
intomainUh oh!
There was an error while loading.Please reload this page.
Uh oh!
There was an error while loading.Please reload this page.
It was hard to deduce whether or not changes in our terraform testdata
are relevant or not, so we now have a rudimentary filter for randomly
generated values that aren't relevant for the testdata.
With this change we could technically run this in CI as well, I believe.