From dea645797ae26d08032f03611b9c055dd3800a41 Mon Sep 17 00:00:00 2001 From: magodo Date: Sat, 24 Jul 2021 11:34:58 +0800 Subject: [PATCH] `terraform add -out` append to existing config --- internal/command/views/add.go | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/internal/command/views/add.go b/internal/command/views/add.go index 4b1c96d70..d181e1909 100644 --- a/internal/command/views/add.go +++ b/internal/command/views/add.go @@ -74,7 +74,14 @@ func (v *addHuman) Resource(addr addrs.AbsResourceInstance, schema *configschema } else { // The Println call above adds this final newline automatically; we add it manually here. formatted = append(formatted, '\n') - return os.WriteFile(v.outPath, formatted, 0600) + + f, err := os.OpenFile(v.outPath, os.O_APPEND|os.O_WRONLY|os.O_CREATE, 0600) + if err != nil { + return err + } + defer f.Close() + _, err = f.Write(formatted) + return err } }