terraform: filtering on name actually matches name
This commit is contained in:
parent
0c8b243ce0
commit
0a2fd1a5e5
|
@ -94,6 +94,11 @@ func (f *StateFilter) filterSingle(a *ResourceAddress) []*StateFilterResult {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if a.Name != "" && a.Name != key.Name {
|
||||||
|
// Name doesn't match
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
|
||||||
if a.Index >= 0 && key.Index != a.Index {
|
if a.Index >= 0 && key.Index != a.Index {
|
||||||
// Index doesn't match
|
// Index doesn't match
|
||||||
continue
|
continue
|
||||||
|
|
|
@ -38,6 +38,15 @@ func TestStateFilterFilter(t *testing.T) {
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"single resource with similar names": {
|
||||||
|
"small_test_instance.tfstate",
|
||||||
|
[]string{"test_instance.foo"},
|
||||||
|
[]string{
|
||||||
|
"*terraform.ResourceState: test_instance.foo",
|
||||||
|
"*terraform.InstanceState: test_instance.foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
|
||||||
"single instance": {
|
"single instance": {
|
||||||
"small.tfstate",
|
"small.tfstate",
|
||||||
[]string{"aws_key_pair.onprem.primary"},
|
[]string{"aws_key_pair.onprem.primary"},
|
||||||
|
|
|
@ -590,6 +590,13 @@ func TestStateRemove(t *testing.T) {
|
||||||
ID: "foo",
|
ID: "foo",
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
||||||
|
"test_instance.bar": &ResourceState{
|
||||||
|
Type: "test_instance",
|
||||||
|
Primary: &InstanceState{
|
||||||
|
ID: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
@ -597,8 +604,15 @@ func TestStateRemove(t *testing.T) {
|
||||||
&State{
|
&State{
|
||||||
Modules: []*ModuleState{
|
Modules: []*ModuleState{
|
||||||
&ModuleState{
|
&ModuleState{
|
||||||
Path: rootModulePath,
|
Path: rootModulePath,
|
||||||
Resources: map[string]*ResourceState{},
|
Resources: map[string]*ResourceState{
|
||||||
|
"test_instance.bar": &ResourceState{
|
||||||
|
Type: "test_instance",
|
||||||
|
Primary: &InstanceState{
|
||||||
|
ID: "foo",
|
||||||
|
},
|
||||||
|
},
|
||||||
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
|
|
|
@ -0,0 +1,27 @@
|
||||||
|
{
|
||||||
|
"version": 1,
|
||||||
|
"serial": 12,
|
||||||
|
"modules": [
|
||||||
|
{
|
||||||
|
"path": [
|
||||||
|
"root"
|
||||||
|
],
|
||||||
|
"resources": {
|
||||||
|
"test_instance.foo": {
|
||||||
|
"type": "test_instance",
|
||||||
|
"primary": {
|
||||||
|
"id": "foo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
},
|
||||||
|
"resources": {
|
||||||
|
"test_instance.bar": {
|
||||||
|
"type": "test_instance",
|
||||||
|
"primary": {
|
||||||
|
"id": "foo"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
]
|
||||||
|
}
|
Loading…
Reference in New Issue