Skip to content

Commit

Permalink
rewrite parsing logic
Browse files Browse the repository at this point in the history
  • Loading branch information
zahornyak committed Jun 2, 2023
1 parent 5f738a3 commit f2ec2bc
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 3 deletions.
2 changes: 1 addition & 1 deletion examples/parse-env-file/.env
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
DB_NAME=mysql
DB_PASSWORD=password
CERTIFICATE="dawjhjdkl;aefjhguwyidhjakenka"
SECRET="sjkbfdksnjwdjewlknfkj"
SECRET="sjkbfdksnjwdjewlknfkj"
10 changes: 8 additions & 2 deletions main.tf
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,14 @@ data "local_file" "config_file" {
}

locals {
parsed_data = var.file_path != null ? { for line in split("\n", data.local_file.config_file[0].content) :
regex("(.*?)\\s*=\\s*(.*)$", line)[0] => regex("(.*?)\\s*=\\s*(.*)$", line)[1]
# parsed_data = var.file_path != null ? {
# for line in split("\n", data.local_file.config_file[0].content) :
# split("=", line)[0] => split("=", line)[1]
# } : {}
parsed_data = var.file_path != null ? {
for line in split("\n", data.local_file.config_file[0].content) :
split("=", line)[0] => split("=", line)[1]
if can(split("=", line)[1])
} : {}
}

Expand Down

0 comments on commit f2ec2bc

Please sign in to comment.