Skip to content

Instantly share code, notes, and snippets.

@mjroeleveld
Last active January 11, 2022 14:02
Show Gist options
  • Save mjroeleveld/27592424a08740c6f9a3c4727c73516b to your computer and use it in GitHub Desktop.
Save mjroeleveld/27592424a08740c6f9a3c4727c73516b to your computer and use it in GitHub Desktop.
Convert Terraform string to multiline string
# 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