command/push: read name from the config

This commit is contained in:
Mitchell Hashimoto 2015-03-06 15:12:39 -08:00
parent 9062bfda89
commit 5e27bfc040
6 changed files with 35 additions and 1 deletions

View File

@ -84,8 +84,19 @@ func (c *PushCommand) Run(args []string) int {
return 1
}
// Get the configuration
config := ctx.Module().Config()
if config.Atlas == nil || config.Atlas.Name == "" {
c.Ui.Error(
"The name of this Terraform configuration in Atlas must be\n" +
"specified within your configuration or the command-line. To\n" +
"set it on the command-line, use the `-name` parameter.")
return 1
}
name := config.Atlas.Name
// Get the variables we might already have
vars, err := c.client.Get("")
vars, err := c.client.Get(name)
if err != nil {
c.Ui.Error(fmt.Sprintf(
"Error looking up prior pushed configuration: %s", err))
@ -127,6 +138,7 @@ func (c *PushCommand) Run(args []string) int {
// Upsert!
opts := &pushUpsertOptions{
Name: name,
Archive: archiveR,
Variables: ctx.Variables(),
}
@ -171,6 +183,7 @@ type pushClient interface {
}
type pushUpsertOptions struct {
Name string
Archive *archive.Archive
Variables map[string]string
}

View File

@ -64,6 +64,10 @@ func TestPush_good(t *testing.T) {
if !reflect.DeepEqual(client.UpsertOptions.Variables, variables) {
t.Fatalf("bad: %#v", client.UpsertOptions)
}
if client.UpsertOptions.Name != "foo" {
t.Fatalf("bad: %#v", client.UpsertOptions)
}
}
func TestPush_input(t *testing.T) {

View File

@ -2,3 +2,7 @@ variable "foo" {}
variable "bar" {}
resource "test_instance" "foo" {}
atlas {
name = "foo"
}

View File

@ -1,3 +1,7 @@
variable "foo" {}
resource "test_instance" "foo" {}
atlas {
name = "foo"
}

View File

@ -1 +1,5 @@
resource "aws_instance" "foo" {}
atlas {
name = "foo"
}

View File

@ -376,6 +376,11 @@ func (c *Context) Validate() ([]string, []error) {
return walker.ValidationWarnings, rerrs.Errors
}
// Module returns the module tree associated with this context.
func (c *Context) Module() *module.Tree {
return c.module
}
// Variables will return the mapping of variables that were defined
// for this Context. If Input was called, this mapping may be different
// than what was given.