Last active
January 11, 2022 14:02
-
-
Save mjroeleveld/27592424a08740c6f9a3c4727c73516b to your computer and use it in GitHub Desktop.
Convert Terraform string to multiline string
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
# First iteration: convert single line strings to EOF blocks for | |
# resource argument called filter. | |
# | |
# filter = "foo\nbar" | |
# | |
# becomes | |
# | |
# filter = <<EOF | |
# foo\nbar | |
# EOF | |
sed -E 's/filter[[:space:]]+= "(.*)"/filter = <<EOF\ | |
\1\ | |
EOF/' in.tf > out.tf | |
# Second iteration: replace newlines in EOF blocks to actual lines. | |
# | |
# filter = <<EOF | |
# foo | |
# bar | |
# EOF | |
sed -E ' /filter/,/EOF/ s/\\n/\ | |
/g' out.tf > out2.tf |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment