mirror of
https://github.com/opentofu/opentofu.git
synced 2025-02-25 18:45:20 -06:00
command/push: can set the name on the CLI
This commit is contained in:
parent
5e27bfc040
commit
da46e16f4f
@ -22,11 +22,13 @@ type PushCommand struct {
|
|||||||
func (c *PushCommand) Run(args []string) int {
|
func (c *PushCommand) Run(args []string) int {
|
||||||
var atlasToken string
|
var atlasToken string
|
||||||
var moduleLock bool
|
var moduleLock bool
|
||||||
|
var name string
|
||||||
args = c.Meta.process(args, false)
|
args = c.Meta.process(args, false)
|
||||||
cmdFlags := c.Meta.flagSet("push")
|
cmdFlags := c.Meta.flagSet("push")
|
||||||
cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path")
|
cmdFlags.StringVar(&c.Meta.statePath, "state", DefaultStateFilename, "path")
|
||||||
cmdFlags.StringVar(&atlasToken, "token", "", "")
|
cmdFlags.StringVar(&atlasToken, "token", "", "")
|
||||||
cmdFlags.BoolVar(&moduleLock, "module-lock", true, "")
|
cmdFlags.BoolVar(&moduleLock, "module-lock", true, "")
|
||||||
|
cmdFlags.StringVar(&name, "name", "", "")
|
||||||
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
|
||||||
if err := cmdFlags.Parse(args); err != nil {
|
if err := cmdFlags.Parse(args); err != nil {
|
||||||
return 1
|
return 1
|
||||||
@ -86,14 +88,16 @@ func (c *PushCommand) Run(args []string) int {
|
|||||||
|
|
||||||
// Get the configuration
|
// Get the configuration
|
||||||
config := ctx.Module().Config()
|
config := ctx.Module().Config()
|
||||||
if config.Atlas == nil || config.Atlas.Name == "" {
|
if name == "" {
|
||||||
c.Ui.Error(
|
if config.Atlas == nil || config.Atlas.Name == "" {
|
||||||
"The name of this Terraform configuration in Atlas must be\n" +
|
c.Ui.Error(
|
||||||
"specified within your configuration or the command-line. To\n" +
|
"The name of this Terraform configuration in Atlas must be\n" +
|
||||||
"set it on the command-line, use the `-name` parameter.")
|
"specified within your configuration or the command-line. To\n" +
|
||||||
return 1
|
"set it on the command-line, use the `-name` parameter.")
|
||||||
|
return 1
|
||||||
|
}
|
||||||
|
name = config.Atlas.Name
|
||||||
}
|
}
|
||||||
name := config.Atlas.Name
|
|
||||||
|
|
||||||
// Get the variables we might already have
|
// Get the variables we might already have
|
||||||
vars, err := c.client.Get(name)
|
vars, err := c.client.Get(name)
|
||||||
@ -164,6 +168,10 @@ Options:
|
|||||||
their current checkout and uploaded completely. This
|
their current checkout and uploaded completely. This
|
||||||
prevents Atlas from running "terraform get".
|
prevents Atlas from running "terraform get".
|
||||||
|
|
||||||
|
-name=<name> Name of the configuration in Atlas. This can also
|
||||||
|
be set in the configuration itself. Format is
|
||||||
|
typically: "username/name".
|
||||||
|
|
||||||
-token=<token> Access token to use to upload. If blank, the ATLAS_TOKEN
|
-token=<token> Access token to use to upload. If blank, the ATLAS_TOKEN
|
||||||
environmental variable will be used.
|
environmental variable will be used.
|
||||||
|
|
||||||
|
@ -176,6 +176,48 @@ func TestPush_inputPartial(t *testing.T) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestPush_name(t *testing.T) {
|
||||||
|
tmp, cwd := testCwd(t)
|
||||||
|
defer testFixCwd(t, tmp, cwd)
|
||||||
|
|
||||||
|
// Create remote state file, this should be pulled
|
||||||
|
conf, srv := testRemoteState(t, testState(), 200)
|
||||||
|
defer srv.Close()
|
||||||
|
|
||||||
|
// Persist local remote state
|
||||||
|
s := terraform.NewState()
|
||||||
|
s.Serial = 5
|
||||||
|
s.Remote = conf
|
||||||
|
testStateFileRemote(t, s)
|
||||||
|
|
||||||
|
// Path where the archive will be "uploaded" to
|
||||||
|
archivePath := testTempFile(t)
|
||||||
|
defer os.Remove(archivePath)
|
||||||
|
|
||||||
|
client := &mockPushClient{File: archivePath}
|
||||||
|
ui := new(cli.MockUi)
|
||||||
|
c := &PushCommand{
|
||||||
|
Meta: Meta{
|
||||||
|
ContextOpts: testCtxConfig(testProvider()),
|
||||||
|
Ui: ui,
|
||||||
|
},
|
||||||
|
|
||||||
|
client: client,
|
||||||
|
}
|
||||||
|
|
||||||
|
args := []string{
|
||||||
|
"-name", "bar",
|
||||||
|
testFixturePath("push"),
|
||||||
|
}
|
||||||
|
if code := c.Run(args); code != 0 {
|
||||||
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
||||||
|
}
|
||||||
|
|
||||||
|
if client.UpsertOptions.Name != "bar" {
|
||||||
|
t.Fatalf("bad: %#v", client.UpsertOptions)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
func TestPush_noState(t *testing.T) {
|
func TestPush_noState(t *testing.T) {
|
||||||
tmp, cwd := testCwd(t)
|
tmp, cwd := testCwd(t)
|
||||||
defer testFixCwd(t, tmp, cwd)
|
defer testFixCwd(t, tmp, cwd)
|
||||||
|
Loading…
Reference in New Issue
Block a user