diff --git a/command/push.go b/command/push.go index 324e8a258..75434a0d4 100644 --- a/command/push.go +++ b/command/push.go @@ -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 } diff --git a/command/push_test.go b/command/push_test.go index 68c5a8a42..de91a759f 100644 --- a/command/push_test.go +++ b/command/push_test.go @@ -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) { diff --git a/command/test-fixtures/push-input-partial/main.tf b/command/test-fixtures/push-input-partial/main.tf index 8862603b0..8285c1ada 100644 --- a/command/test-fixtures/push-input-partial/main.tf +++ b/command/test-fixtures/push-input-partial/main.tf @@ -2,3 +2,7 @@ variable "foo" {} variable "bar" {} resource "test_instance" "foo" {} + +atlas { + name = "foo" +} diff --git a/command/test-fixtures/push-input/main.tf b/command/test-fixtures/push-input/main.tf index 55072f712..3bd930cf3 100644 --- a/command/test-fixtures/push-input/main.tf +++ b/command/test-fixtures/push-input/main.tf @@ -1,3 +1,7 @@ variable "foo" {} resource "test_instance" "foo" {} + +atlas { + name = "foo" +} diff --git a/command/test-fixtures/push/main.tf b/command/test-fixtures/push/main.tf index 919f140bb..265162636 100644 --- a/command/test-fixtures/push/main.tf +++ b/command/test-fixtures/push/main.tf @@ -1 +1,5 @@ resource "aws_instance" "foo" {} + +atlas { + name = "foo" +} diff --git a/terraform/context.go b/terraform/context.go index fd59bd671..86a804548 100644 --- a/terraform/context.go +++ b/terraform/context.go @@ -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.