Skip to content

Commit

Permalink
remove -allow-missing-config from import
Browse files Browse the repository at this point in the history
  • Loading branch information
jbardin committed Jun 21, 2022
1 parent 03fc2b0 commit 71bb8ca
Show file tree
Hide file tree
Showing 2 changed files with 1 addition and 65 deletions.
9 changes: 1 addition & 8 deletions internal/command/import.go
Expand Up @@ -45,7 +45,6 @@ func (c *ImportCommand) Run(args []string) int {
cmdFlags.StringVar(&configPath, "config", pwd, "path")
cmdFlags.BoolVar(&c.Meta.stateLock, "lock", true, "lock state")
cmdFlags.DurationVar(&c.Meta.stateLockTimeout, "lock-timeout", 0, "lock timeout")
cmdFlags.BoolVar(&c.Meta.allowMissingConfig, "allow-missing-config", false, "allow missing config")
cmdFlags.Usage = func() { c.Ui.Error(c.Help()) }
if err := cmdFlags.Parse(args); err != nil {
return 1
Expand Down Expand Up @@ -135,7 +134,7 @@ func (c *ImportCommand) Run(args []string) int {
break
}
}
if !c.Meta.allowMissingConfig && rc == nil {
if rc == nil {
modulePath := addr.Module.String()
if modulePath == "" {
modulePath = "the root module"
Expand Down Expand Up @@ -262,10 +261,6 @@ func (c *ImportCommand) Run(args []string) int {

c.Ui.Output(c.Colorize().Color("[reset][green]\n" + importCommandSuccessMsg))

if c.Meta.allowMissingConfig && rc == nil {
c.Ui.Output(c.Colorize().Color("[reset][yellow]\n" + importCommandAllowMissingResourceMsg))
}

c.showDiagnostics(diags)
if diags.HasErrors() {
return 1
Expand Down Expand Up @@ -310,8 +305,6 @@ Options:
If no config files are present, they must be provided
via the input prompts or env vars.
-allow-missing-config Allow import when no resource configuration block exists.
-input=false Disable interactive input prompts.
-lock=false Don't hold a state lock during the operation. This is
Expand Down
57 changes: 0 additions & 57 deletions internal/command/import_test.go
Expand Up @@ -644,63 +644,6 @@ func TestImport_providerConfigWithVarFile(t *testing.T) {
testStateOutput(t, statePath, testImportStr)
}

func TestImport_allowMissingResourceConfig(t *testing.T) {
defer testChdir(t, testFixturePath("import-missing-resource-config"))()

statePath := testTempFile(t)

p := testProvider()
ui := new(cli.MockUi)
view, _ := testView(t)
c := &ImportCommand{
Meta: Meta{
testingOverrides: metaOverridesForProvider(p),
Ui: ui,
View: view,
},
}

p.ImportResourceStateFn = nil
p.ImportResourceStateResponse = &providers.ImportResourceStateResponse{
ImportedResources: []providers.ImportedResource{
{
TypeName: "test_instance",
State: cty.ObjectVal(map[string]cty.Value{
"id": cty.StringVal("yay"),
}),
},
},
}
p.GetProviderSchemaResponse = &providers.GetProviderSchemaResponse{
ResourceTypes: map[string]providers.Schema{
"test_instance": {
Block: &configschema.Block{
Attributes: map[string]*configschema.Attribute{
"id": {Type: cty.String, Optional: true, Computed: true},
},
},
},
},
}

args := []string{
"-state", statePath,
"-allow-missing-config",
"test_instance.foo",
"bar",
}

if code := c.Run(args); code != 0 {
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
}

if !p.ImportResourceStateCalled {
t.Fatal("ImportResourceState should be called")
}

testStateOutput(t, statePath, testImportStr)
}

func TestImport_emptyConfig(t *testing.T) {
defer testChdir(t, testFixturePath("empty"))()

Expand Down

0 comments on commit 71bb8ca

Please sign in to comment.