Script 'mail_helper' called by obssrc
Hello community,

here is the log from the commit of package terragrunt for openSUSE:Factory 
checked in at 2023-10-25 18:03:28
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Comparing /work/SRC/openSUSE:Factory/terragrunt (Old)
 and      /work/SRC/openSUSE:Factory/.terragrunt.new.24901 (New)
++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Package is "terragrunt"

Wed Oct 25 18:03:28 2023 rev:76 rq:1120150 version:0.52.5

Changes:
--------
--- /work/SRC/openSUSE:Factory/terragrunt/terragrunt.changes    2023-10-22 
21:02:43.795188449 +0200
+++ /work/SRC/openSUSE:Factory/.terragrunt.new.24901/terragrunt.changes 
2023-10-25 18:04:10.097158285 +0200
@@ -1,0 +2,6 @@
+Wed Oct 25 04:37:23 UTC 2023 - ka...@b1-systems.de
+
+- Update to version 0.52.5:
+  * feat: add read_tfvars_file function (#2757)
+
+-------------------------------------------------------------------

Old:
----
  terragrunt-0.52.4.obscpio

New:
----
  terragrunt-0.52.5.obscpio

++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++

Other differences:
------------------
++++++ terragrunt.spec ++++++
--- /var/tmp/diff_new_pack.t2RinL/_old  2023-10-25 18:04:11.153193802 +0200
+++ /var/tmp/diff_new_pack.t2RinL/_new  2023-10-25 18:04:11.153193802 +0200
@@ -19,7 +19,7 @@
 %define __arch_install_post export NO_BRP_STRIP_DEBUG=true
 
 Name:           terragrunt
-Version:        0.52.4
+Version:        0.52.5
 Release:        0
 Summary:        Thin wrapper for Terraform for working with multiple Terraform 
modules
 License:        MIT

++++++ _service ++++++
--- /var/tmp/diff_new_pack.t2RinL/_old  2023-10-25 18:04:11.185194878 +0200
+++ /var/tmp/diff_new_pack.t2RinL/_new  2023-10-25 18:04:11.189195012 +0200
@@ -3,7 +3,7 @@
     <param name="url">https://github.com/gruntwork-io/terragrunt</param>
     <param name="scm">git</param>
     <param name="exclude">.git</param>
-    <param name="revision">v0.52.4</param>
+    <param name="revision">v0.52.5</param>
     <param name="versionformat">@PARENT_TAG@</param>
     <param name="changesgenerate">enable</param>
     <param name="versionrewrite-pattern">v(.*)</param>

++++++ _servicedata ++++++
--- /var/tmp/diff_new_pack.t2RinL/_old  2023-10-25 18:04:11.209195685 +0200
+++ /var/tmp/diff_new_pack.t2RinL/_new  2023-10-25 18:04:11.213195820 +0200
@@ -1,6 +1,6 @@
 <servicedata>
 <service name="tar_scm">
                 <param 
name="url">https://github.com/gruntwork-io/terragrunt</param>
-              <param 
name="changesrevision">b8cf75fb6e88d36d43933efa40a473e242b2b77d</param></service></servicedata>
+              <param 
name="changesrevision">c996cbc70140b8507b2f73a4aeb42b84163a74b6</param></service></servicedata>
 (No newline at EOF)
 

++++++ terragrunt-0.52.4.obscpio -> terragrunt-0.52.5.obscpio ++++++
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/terragrunt-0.52.4/config/config_helpers.go 
new/terragrunt-0.52.5/config/config_helpers.go
--- old/terragrunt-0.52.4/config/config_helpers.go      2023-10-20 
18:45:34.000000000 +0200
+++ new/terragrunt-0.52.5/config/config_helpers.go      2023-10-24 
22:13:58.000000000 +0200
@@ -1,7 +1,9 @@
 package config
 
 import (
+       "encoding/json"
        "fmt"
+       "os"
        "path/filepath"
        "regexp"
        "runtime"
@@ -144,6 +146,7 @@
                "sops_decrypt_file":                            
wrapStringSliceToStringAsFuncImpl(sopsDecryptFile, extensions.TrackInclude, 
terragruntOptions),
                "get_terragrunt_source_cli_flag":               
wrapVoidToStringAsFuncImpl(getTerragruntSourceCliFlag, extensions.TrackInclude, 
terragruntOptions),
                "get_default_retryable_errors":                 
wrapVoidToStringSliceAsFuncImpl(getDefaultRetryableErrors, 
extensions.TrackInclude, terragruntOptions),
+               "read_tfvars_file":                             
wrapStringSliceToStringAsFuncImpl(readTFVarsFile, extensions.TrackInclude, 
terragruntOptions),
        }
 
        // Map with HCL functions introduced in Terraform after v0.15.3, since 
upgrade to a later version is not supported
@@ -849,7 +852,61 @@
        return false, nil
 }
 
+// readTFVarsFile reads a *.tfvars or *.tfvars.json file and returns the 
contents as a JSON encoded string
+func readTFVarsFile(args []string, trackInclude *TrackInclude, 
terragruntOptions *options.TerragruntOptions) (string, error) {
+
+       if len(args) != 1 {
+               return "", errors.WithStackTrace(WrongNumberOfParams{Func: 
"read_tfvars_file", Expected: "1", Actual: len(args)})
+       }
+
+       varFile := args[0]
+       varFile, err := util.CanonicalPath(varFile, 
terragruntOptions.WorkingDir)
+       if err != nil {
+               return "", errors.WithStackTrace(err)
+       }
+
+       if !util.FileExists(varFile) {
+               return "", errors.WithStackTrace(TFVarFileNotFoundError{File: 
varFile})
+       }
+
+       fileContents, err := os.ReadFile(varFile)
+       if err != nil {
+               return "", errors.WithStackTrace(fmt.Errorf("could not read 
file %q: %w", varFile, err))
+       }
+
+       if strings.HasSuffix(varFile, "json") {
+               var variables map[string]interface{}
+               // just want to be sure that the file is valid json
+               if err := json.Unmarshal(fileContents, &variables); err != nil {
+                       return "", errors.WithStackTrace(fmt.Errorf("could not 
unmarshal json body of tfvar file: %w", err))
+               }
+               return string(fileContents), nil
+       }
+
+       var variables map[string]interface{}
+       if err := ParseAndDecodeVarFile(string(fileContents), varFile, 
&variables); err != nil {
+               return "", err
+       }
+
+       data, err := json.Marshal(variables)
+       if err != nil {
+               return "", errors.WithStackTrace(fmt.Errorf("could not marshal 
json body of tfvar file: %w", err))
+       }
+
+       return string(data), nil
+}
+
 // Custom error types
+
+type TFVarFileNotFoundError struct {
+       File  string
+       Cause string
+}
+
+func (err TFVarFileNotFoundError) Error() string {
+       return fmt.Sprintf("TFVarFileNotFound: Could not find a %s. Cause: 
%s.", err.File, err.Cause)
+}
+
 type WrongNumberOfParams struct {
        Func     string
        Expected string
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' old/terragrunt-0.52.4/config/config_helpers_test.go 
new/terragrunt-0.52.5/config/config_helpers_test.go
--- old/terragrunt-0.52.4/config/config_helpers_test.go 2023-10-20 
18:45:34.000000000 +0200
+++ new/terragrunt-0.52.5/config/config_helpers_test.go 2023-10-24 
22:13:58.000000000 +0200
@@ -1128,6 +1128,28 @@
        }
 }
 
+func TestReadTFVarsFiles(t *testing.T) {
+       t.Parallel()
+
+       options := terragruntOptionsForTest(t, DefaultTerragruntConfigPath)
+       tgConfigCty, err := 
readTerragruntConfig("../test/fixture-read-tf-vars/terragrunt.hcl", nil, 
options)
+       require.NoError(t, err)
+
+       tgConfigMap, err := parseCtyValueToMap(tgConfigCty)
+       require.NoError(t, err)
+
+       locals := tgConfigMap["locals"].(map[string]interface{})
+
+       assert.Equal(t, locals["string_var"].(string), "string")
+       assert.Equal(t, locals["number_var"].(float64), float64(42))
+       assert.Equal(t, locals["bool_var"].(bool), true)
+       assert.Equal(t, locals["list_var"].([]interface{}), 
[]interface{}{"hello", "world"})
+
+       assert.Equal(t, locals["json_number_var"].(float64), float64(24))
+       assert.Equal(t, locals["json_string_var"].(string), "another string")
+       assert.Equal(t, locals["json_bool_var"].(bool), false)
+}
+
 func mockConfigWithSource(sourceUrl string) *TerragruntConfig {
        cfg := TerragruntConfig{IsPartial: true}
        cfg.Terraform = &TerraformConfig{Source: &sourceUrl}
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/terragrunt-0.52.4/docs/_docs/04_reference/built-in-functions.md 
new/terragrunt-0.52.5/docs/_docs/04_reference/built-in-functions.md
--- old/terragrunt-0.52.4/docs/_docs/04_reference/built-in-functions.md 
2023-10-20 18:45:34.000000000 +0200
+++ new/terragrunt-0.52.5/docs/_docs/04_reference/built-in-functions.md 
2023-10-24 22:13:58.000000000 +0200
@@ -64,6 +64,8 @@
 
   - [get\_terragrunt\_source\_cli\_flag()](#get_terragrunt_source_cli_flag)
 
+  - [read\_tfvars\_file()](#read_tfvars_file)
+
 ## Terraform built-in functions
 
 All [Terraform built-in 
functions](https://www.terraform.io/docs/configuration/functions.html) are 
supported in Terragrunt config files:
@@ -819,3 +821,46 @@
 - Setting debug logging when doing local development.
 - Adjusting the kubernetes provider configuration so that it targets minikube 
instead of real clusters.
 - Providing special mocks pulled in from the local dev source (e.g., something 
like `mock_outputs = 
jsondecode(file("${get_terragrunt_source_cli_arg()}/dependency_mocks/vpc.json"))`).
+
+
+## read\_tfvars\_file
+
+`read_tfvars_file(file_path)` reads a `.tfvars` or `.tfvars.json` file and 
returns a map of the variables defined in it.
+
+This is useful for reading variables from a `.tfvars` file and merging them 
into the inputs or to use them in a `locals` block:
+
+```hcl
+
+locals {
+  inputs_from_tfvars = jsondecode(read_tfvars_file("common.tfvars"))
+}
+
+inputs = merge(
+  local.inputs_from_tfvars,
+  {
+    # additional inputs
+  }
+)
+```
+
+Another example:
+
+```hcl
+
+locals {
+  backend = jsondecode(read_tfvars_file("backend.tfvars"))
+}
+
+remote_state {
+  backend = "s3"
+  config = {
+    bucket         = "${get_env("TG_BUCKET_PREFIX", 
"tf-bucket")}-${get_aws_account_id()}"
+    key            = 
"${path_relative_to_include()}/terraform-${local.aws_region}.tfstate"
+    region         = local.backend.region
+  }
+  generate = {
+    path      = "backend.tf"
+    if_exists = "overwrite_terragrunt"
+  }
+}
+```
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/terragrunt-0.52.4/test/fixture-read-tf-vars/my.tfvars 
new/terragrunt-0.52.5/test/fixture-read-tf-vars/my.tfvars
--- old/terragrunt-0.52.4/test/fixture-read-tf-vars/my.tfvars   1970-01-01 
01:00:00.000000000 +0100
+++ new/terragrunt-0.52.5/test/fixture-read-tf-vars/my.tfvars   2023-10-24 
22:13:58.000000000 +0200
@@ -0,0 +1,4 @@
+string_var = "string"
+number_var = 42
+bool_var = true
+list_var = ["hello", "world"]
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/terragrunt-0.52.4/test/fixture-read-tf-vars/my.tfvars.json 
new/terragrunt-0.52.5/test/fixture-read-tf-vars/my.tfvars.json
--- old/terragrunt-0.52.4/test/fixture-read-tf-vars/my.tfvars.json      
1970-01-01 01:00:00.000000000 +0100
+++ new/terragrunt-0.52.5/test/fixture-read-tf-vars/my.tfvars.json      
2023-10-24 22:13:58.000000000 +0200
@@ -0,0 +1,5 @@
+{
+    "string_var": "another string",
+    "number_var": 24,
+    "bool_var": false
+}
\ No newline at end of file
diff -urN '--exclude=CVS' '--exclude=.cvsignore' '--exclude=.svn' 
'--exclude=.svnignore' 
old/terragrunt-0.52.4/test/fixture-read-tf-vars/terragrunt.hcl 
new/terragrunt-0.52.5/test/fixture-read-tf-vars/terragrunt.hcl
--- old/terragrunt-0.52.4/test/fixture-read-tf-vars/terragrunt.hcl      
1970-01-01 01:00:00.000000000 +0100
+++ new/terragrunt-0.52.5/test/fixture-read-tf-vars/terragrunt.hcl      
2023-10-24 22:13:58.000000000 +0200
@@ -0,0 +1,12 @@
+locals {
+  vars       = jsondecode(read_tfvars_file("my.tfvars"))
+  json_vars = jsondecode(read_tfvars_file("my.tfvars.json"))
+  string_var = local.vars.string_var
+  bool_var   = local.vars.bool_var
+  number_var = local.vars.number_var
+  list_var   = local.vars.list_var
+
+  json_string_var = local.json_vars.string_var
+  json_bool_var   = local.json_vars.bool_var
+  json_number_var = local.json_vars.number_var
+}

++++++ terragrunt.obsinfo ++++++
--- /var/tmp/diff_new_pack.t2RinL/_old  2023-10-25 18:04:12.033223398 +0200
+++ /var/tmp/diff_new_pack.t2RinL/_new  2023-10-25 18:04:12.033223398 +0200
@@ -1,5 +1,5 @@
 name: terragrunt
-version: 0.52.4
-mtime: 1697820334
-commit: b8cf75fb6e88d36d43933efa40a473e242b2b77d
+version: 0.52.5
+mtime: 1698178438
+commit: c996cbc70140b8507b2f73a4aeb42b84163a74b6
 

++++++ vendor.tar.gz ++++++
/work/SRC/openSUSE:Factory/terragrunt/vendor.tar.gz 
/work/SRC/openSUSE:Factory/.terragrunt.new.24901/vendor.tar.gz differ: char 5, 
line 1

Reply via email to