Skip to content

Instantly share code, notes, and snippets.

@adrienthebo
Last active October 2, 2018 02:23
Show Gist options
  • Save adrienthebo/ce839deec750725af7bc3243d23b1832 to your computer and use it in GitHub Desktop.
Save adrienthebo/ce839deec750725af7bc3243d23b1832 to your computer and use it in GitHub Desktop.
OUTPUT_OBJECT_PATTERN = re.compile(r"""
^output\s+ # Terraform `output` object declaration
"(?P<objname>.*?)"\s* # Variable name, within quotes - non-greedy match within quotes
\{\s* # Opening brace
(?: # Order independent matching of variable fields
(?: # Attempt to extract the description field
description\s* # Match 'description' literal
=\s* # Match '=' literal
"(?P<desc>.*?)"\s* # Match and capture quoted string
)
|
(?: # Attempt to extract the value field
value\s* # Match 'value' literal
=\s* # Match '=' literal
"(?P<value>.*?)"\s* # Match and capture quoted string
)
|
.*? # Match and discard other fields
){0,2} # Match this group up two two times, letting us perform two passes/captures
\s*
\}\s*
""")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment