Skip to content

Instantly share code, notes, and snippets.

@pio2pio
Created May 25, 2020 12:11
Show Gist options
  • Star 3 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save pio2pio/e27f66ff4ed15221cd11519c71953501 to your computer and use it in GitHub Desktop.
Save pio2pio/e27f66ff4ed15221cd11519c71953501 to your computer and use it in GitHub Desktop.
Terraform template remove empty lines and comment lines starting with '#' symbol
variable "match_comment" { default = "/(?U)(?m)(?s)(^#.*$)/" }
variable "match_empty_line" { default = "/(?m)(?s)(^[\r\n])/" }
resource "helm_release" "myapp" {
name = "myapp"
chart = "${path.module}/charts/myapp"
values = [
replace(
replace(
templatefile("${path.module}/templates/values-override.yaml.tpl", {
nfsServer = "k8s-nfs"
}), var.match_comment, ""), var.match_empty_line, "")
]
}
# Terraform regex is using re2 library
# * Regex flags are enabled by prefixinf the search:
# ** (?m) - multi-line mode (default false)
# ** (?s) - let . match \n (default false)
# ** (?U) - ungreedy (default false), so stop matching comments at EOL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment