command/push: only explicitly include the state

modify the module include flag to flag whether we explicitly include or
exclude modules
This commit is contained in:
Mitchell Hashimoto 2016-08-23 23:12:52 -07:00
parent 3aecc52bf3
commit a650455ed6
No known key found for this signature in database
GPG Key ID: 744E147AA52F5B0A
2 changed files with 14 additions and 20 deletions

View File

@ -203,20 +203,24 @@ func (c *PushCommand) Run(args []string) int {
// Build the archiving options, which includes everything it can // Build the archiving options, which includes everything it can
// by default according to VCS rules but forcing the data directory. // by default according to VCS rules but forcing the data directory.
archiveOpts := &archive.ArchiveOpts{ archiveOpts := &archive.ArchiveOpts{
VCS: archiveVCS, VCS: archiveVCS,
Extra: map[string]string{ Extra: make(map[string]string),
DefaultDataDir: dataDirAbs,
},
} }
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 = append(
archiveOpts.Exclude, archiveOpts.Exclude,
filepath.Join(c.DataDir(), "modules")) filepath.Join(c.DataDir(), "modules"))
} }
println(fmt.Sprintf("%#v", archiveOpts))
archiveR, err := archive.CreateArchive(configPath, archiveOpts) archiveR, err := archive.CreateArchive(configPath, archiveOpts)
if err != nil { if err != nil {
c.Ui.Error(fmt.Sprintf( c.Ui.Error(fmt.Sprintf(
@ -225,16 +229,6 @@ func (c *PushCommand) Run(args []string) int {
return 1 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. // 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. // We always upload all vars from atlas, but only report them if they are overwritten.
var setVars []string var setVars []string

View File

@ -117,9 +117,9 @@ func TestPush_noUploadModules(t *testing.T) {
actual := testArchiveStr(t, archivePath) actual := testArchiveStr(t, archivePath)
expected := []string{ expected := []string{
".gitignore",
".terraform/",
".terraform/terraform.tfstate", ".terraform/terraform.tfstate",
"child/",
"child/main.tf",
"main.tf", "main.tf",
} }
if !reflect.DeepEqual(actual, expected) { if !reflect.DeepEqual(actual, expected) {