diff --git a/command/push.go b/command/push.go index 37dbf5a69..67f881522 100644 --- a/command/push.go +++ b/command/push.go @@ -203,20 +203,24 @@ func (c *PushCommand) Run(args []string) int { // Build the archiving options, which includes everything it can // by default according to VCS rules but forcing the data directory. archiveOpts := &archive.ArchiveOpts{ - VCS: archiveVCS, - Extra: map[string]string{ - DefaultDataDir: dataDirAbs, - }, + VCS: archiveVCS, + Extra: make(map[string]string), } - if !moduleUpload { - // If we're not uploading modules, then exclude the modules dir. + + // Always store the state file in here so we can find state + statePathKey := fmt.Sprintf("%s/%s", DefaultDataDir, DefaultStateFilename) + archiveOpts.Extra[statePathKey] = filepath.Join(dataDirAbs, DefaultStateFilename) + if moduleUpload { + // If we're uploading modules, explicitly add that + moduleKey := fmt.Sprintf("%s/%s", DefaultDataDir, "modules") + archiveOpts.Extra[moduleKey] = filepath.Join(dataDirAbs, "modules") + } else { + // If we're not uploading modules, explicitly exclude add that archiveOpts.Exclude = append( archiveOpts.Exclude, filepath.Join(c.DataDir(), "modules")) } - println(fmt.Sprintf("%#v", archiveOpts)) - archiveR, err := archive.CreateArchive(configPath, archiveOpts) if err != nil { c.Ui.Error(fmt.Sprintf( @@ -225,16 +229,6 @@ func (c *PushCommand) Run(args []string) int { return 1 } - /* - f, err := os.Create("ARCHIVE.tar.gz") - if err != nil { - panic(err) - } - io.Copy(f, archiveR) - f.Close() - return 12 - */ - // List of the vars we're uploading to display to the user. // We always upload all vars from atlas, but only report them if they are overwritten. var setVars []string diff --git a/command/push_test.go b/command/push_test.go index 9797179f7..669b5b128 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -117,9 +117,9 @@ func TestPush_noUploadModules(t *testing.T) { actual := testArchiveStr(t, archivePath) expected := []string{ - ".gitignore", - ".terraform/", ".terraform/terraform.tfstate", + "child/", + "child/main.tf", "main.tf", } if !reflect.DeepEqual(actual, expected) {