From bcbcc65f7da996b9ed148541aa6cdb062acd2e44 Mon Sep 17 00:00:00 2001 From: James Bardin Date: Wed, 22 Mar 2017 09:01:54 -0400 Subject: [PATCH] add terraform config merge logic to config.Merge --- config/append_test.go | 1 + config/merge.go | 10 +++++++--- config/merge_test.go | 25 +++++++++++++++++++++++++ 3 files changed, 33 insertions(+), 3 deletions(-) diff --git a/config/append_test.go b/config/append_test.go index 8c81ed91d..17cca25b7 100644 --- a/config/append_test.go +++ b/config/append_test.go @@ -119,6 +119,7 @@ func TestAppend(t *testing.T) { false, }, + // appending configs merges terraform blocks { &Config{ Terraform: &Terraform{ diff --git a/config/merge.go b/config/merge.go index 2e7686594..db214be45 100644 --- a/config/merge.go +++ b/config/merge.go @@ -32,9 +32,13 @@ func Merge(c1, c2 *Config) (*Config, error) { c.Atlas = c2.Atlas } - // Merge the Terraform configuration, which is a complete overwrite. - c.Terraform = c1.Terraform - if c2.Terraform != nil { + // Merge the Terraform configuration + if c1.Terraform != nil { + c.Terraform = c1.Terraform + if c2.Terraform != nil { + c.Terraform.Merge(c2.Terraform) + } + } else { c.Terraform = c2.Terraform } diff --git a/config/merge_test.go b/config/merge_test.go index b1d27b6db..5cd87aca6 100644 --- a/config/merge_test.go +++ b/config/merge_test.go @@ -434,6 +434,31 @@ func TestMerge(t *testing.T) { }, false, }, + + // terraform blocks are merged, not overwritten + { + &Config{ + Terraform: &Terraform{ + RequiredVersion: "A", + }, + }, + &Config{ + Terraform: &Terraform{ + Backend: &Backend{ + Type: "test", + }, + }, + }, + &Config{ + Terraform: &Terraform{ + RequiredVersion: "A", + Backend: &Backend{ + Type: "test", + }, + }, + }, + false, + }, } for i, tc := range cases {