Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

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

Merged
mafredri merged 6 commits intomainfrommafredri/tf-testdata-minimize-diff
Mar 13, 2025

Conversation

mafredri
Copy link
Member

@mafredrimafredri commentedMar 13, 2025
edited
Loading

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.

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.
@mafredrimafredri self-assigned thisMar 13, 2025
@mafredrimafredriforce-pushed themafredri/tf-testdata-minimize-diff branch from162fbc3 tofea7f9eCompareMarch 13, 2025 16:14
Comment on lines 26 to 66
minimize_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
}
Copy link
Member

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)'

Copy link
MemberAuthor

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) 🤔.

Copy link
Member

@mtojekmtojek left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

stamp 👍

@mafredrimafredri merged commita1f5468 intomainMar 13, 2025
30 checks passed
@mafredrimafredri deleted the mafredri/tf-testdata-minimize-diff branchMarch 13, 2025 18:13
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsMar 13, 2025
Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@johnstcnjohnstcnjohnstcn approved these changes

@mtojekmtojekmtojek approved these changes

Assignees

@mafredrimafredri

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

3 participants
@mafredri@johnstcn@mtojek

[8]ページ先頭

©2009-2025 Movatter.jp