Skip to content

Instantly share code, notes, and snippets.

@YakDriver
Last active September 18, 2019 21:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save YakDriver/200f7b056685e872f58282ab513eddaa to your computer and use it in GitHub Desktop.
Save YakDriver/200f7b056685e872f58282ab513eddaa to your computer and use it in GitHub Desktop.
Helpful Visual Studio Code REGEXes to upgrade and clean up Terraform 0.12 config
Assumptions:
- Terraform 0.12 tool has already been run
- Variables fields are in the order: type, description, default (if any)
---------------------------------------------
BOOL
Transform 0.11 string booleans to native bool
---------------------------------------------
Find:(type\s+=\s*)string(\n\s+description.*\n\s+default\s+=\s+)"(false|true)"
Replace:$1bool$2$3
---------------------------------------------
NULL
Convert default empty strings to null
---------------------------------------------
Find:(type\s+=\s*string\n\s+description.*\n\s+default\s+=\s+)""
Replace:$1null
---------------------------------------------
Add Optional to Variable descriptions
---------------------------------------------
Find:(description\s+=\s")([a-z].*\n\s+default)
Replace:$1(Optional) $2
---------------------------------------------
Add Required to Variable descriptions
---------------------------------------------
Find:(description\s+=\s")([a-z0-9].*\n\s*\})
Replace:$1(Required) $2
@YakDriver
Copy link
Author

Note, this upgrades to native bools after the upgrade tool has run, which leaves bools as strings.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment