`terraform add -out` append to existing config

This commit is contained in:
magodo 2021-07-24 11:34:58 +08:00
parent b9c0cbb1fd
commit dea645797a
No known key found for this signature in database
GPG Key ID: 2A3C3526EE99038E
1 changed files with 8 additions and 1 deletions

View File

@ -74,7 +74,14 @@ func (v *addHuman) Resource(addr addrs.AbsResourceInstance, schema *configschema
} else { } else {
// The Println call above adds this final newline automatically; we add it manually here. // The Println call above adds this final newline automatically; we add it manually here.
formatted = append(formatted, '\n') 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
} }
} }