|
|
|
|
@ -17,8 +17,9 @@ func TestUntaint(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -49,101 +50,6 @@ test_instance.foo:
|
|
|
|
|
testStateOutput(t, statePath, expected)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUntaint_indexRequired(t *testing.T) {
|
|
|
|
|
state := &terraform.State{
|
|
|
|
|
Modules: []*terraform.ModuleState{
|
|
|
|
|
&terraform.ModuleState{
|
|
|
|
|
Path: []string{"root"},
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
&terraform.InstanceState{ID: "bar2"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
statePath := testStateFile(t, state)
|
|
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
|
c := &UntaintCommand{
|
|
|
|
|
Meta: Meta{
|
|
|
|
|
Ui: ui,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
|
"-state", statePath,
|
|
|
|
|
"test_instance.foo",
|
|
|
|
|
}
|
|
|
|
|
if code := c.Run(args); code == 0 {
|
|
|
|
|
t.Fatalf("Expected non-zero exit. Output:\n\n%s", ui.OutputWriter.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nothing should have gotten untainted
|
|
|
|
|
expected := strings.TrimSpace(`
|
|
|
|
|
test_instance.foo: (2 tainted)
|
|
|
|
|
ID = <not created>
|
|
|
|
|
Tainted ID 1 = bar
|
|
|
|
|
Tainted ID 2 = bar2
|
|
|
|
|
`)
|
|
|
|
|
testStateOutput(t, statePath, expected)
|
|
|
|
|
|
|
|
|
|
// Should have gotten an error message mentioning index
|
|
|
|
|
errOut := ui.ErrorWriter.String()
|
|
|
|
|
errContains := "please specify an index"
|
|
|
|
|
if !strings.Contains(errOut, errContains) {
|
|
|
|
|
t.Fatalf("Expected err output: %s, to contain: %s", errOut, errContains)
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUntaint_indexSpecified(t *testing.T) {
|
|
|
|
|
state := &terraform.State{
|
|
|
|
|
Modules: []*terraform.ModuleState{
|
|
|
|
|
&terraform.ModuleState{
|
|
|
|
|
Path: []string{"root"},
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
&terraform.InstanceState{ID: "bar2"},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
statePath := testStateFile(t, state)
|
|
|
|
|
|
|
|
|
|
ui := new(cli.MockUi)
|
|
|
|
|
c := &UntaintCommand{
|
|
|
|
|
Meta: Meta{
|
|
|
|
|
Ui: ui,
|
|
|
|
|
},
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
args := []string{
|
|
|
|
|
"-state", statePath,
|
|
|
|
|
"-index", "1",
|
|
|
|
|
"test_instance.foo",
|
|
|
|
|
}
|
|
|
|
|
if code := c.Run(args); code != 0 {
|
|
|
|
|
t.Fatalf("bad: %d\n\n%s", code, ui.ErrorWriter.String())
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// Nothing should have gotten untainted
|
|
|
|
|
expected := strings.TrimSpace(`
|
|
|
|
|
test_instance.foo: (1 tainted)
|
|
|
|
|
ID = bar2
|
|
|
|
|
Tainted ID 1 = bar
|
|
|
|
|
`)
|
|
|
|
|
testStateOutput(t, statePath, expected)
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
func TestUntaint_backup(t *testing.T) {
|
|
|
|
|
// Get a temp cwd
|
|
|
|
|
tmp, cwd := testCwd(t)
|
|
|
|
|
@ -157,8 +63,9 @@ func TestUntaint_backup(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -183,9 +90,8 @@ func TestUntaint_backup(t *testing.T) {
|
|
|
|
|
|
|
|
|
|
// Backup is still tainted
|
|
|
|
|
testStateOutput(t, path+".backup", strings.TrimSpace(`
|
|
|
|
|
test_instance.foo: (1 tainted)
|
|
|
|
|
ID = <not created>
|
|
|
|
|
Tainted ID 1 = bar
|
|
|
|
|
test_instance.foo: (tainted)
|
|
|
|
|
ID = bar
|
|
|
|
|
`))
|
|
|
|
|
|
|
|
|
|
// State is untainted
|
|
|
|
|
@ -208,8 +114,9 @@ func TestUntaint_backupDisable(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -273,8 +180,9 @@ func TestUntaint_defaultState(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -311,8 +219,9 @@ func TestUntaint_missing(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -345,8 +254,9 @@ func TestUntaint_missingAllow(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -385,8 +295,9 @@ func TestUntaint_stateOut(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -411,9 +322,8 @@ func TestUntaint_stateOut(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testStateOutput(t, path, strings.TrimSpace(`
|
|
|
|
|
test_instance.foo: (1 tainted)
|
|
|
|
|
ID = <not created>
|
|
|
|
|
Tainted ID 1 = bar
|
|
|
|
|
test_instance.foo: (tainted)
|
|
|
|
|
ID = bar
|
|
|
|
|
`))
|
|
|
|
|
testStateOutput(t, "foo", strings.TrimSpace(`
|
|
|
|
|
test_instance.foo:
|
|
|
|
|
@ -429,8 +339,9 @@ func TestUntaint_module(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.foo": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -440,8 +351,9 @@ func TestUntaint_module(t *testing.T) {
|
|
|
|
|
Resources: map[string]*terraform.ResourceState{
|
|
|
|
|
"test_instance.blah": &terraform.ResourceState{
|
|
|
|
|
Type: "test_instance",
|
|
|
|
|
Tainted: []*terraform.InstanceState{
|
|
|
|
|
&terraform.InstanceState{ID: "bar"},
|
|
|
|
|
Primary: &terraform.InstanceState{
|
|
|
|
|
ID: "bar",
|
|
|
|
|
Tainted: true,
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
},
|
|
|
|
|
@ -467,9 +379,8 @@ func TestUntaint_module(t *testing.T) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
testStateOutput(t, statePath, strings.TrimSpace(`
|
|
|
|
|
test_instance.foo: (1 tainted)
|
|
|
|
|
ID = <not created>
|
|
|
|
|
Tainted ID 1 = bar
|
|
|
|
|
test_instance.foo: (tainted)
|
|
|
|
|
ID = bar
|
|
|
|
|
|
|
|
|
|
module.child:
|
|
|
|
|
test_instance.blah:
|
|
|
|
|
|