providers/aws: test tag removal

This commit is contained in:
Mitchell Hashimoto 2014-10-08 18:21:21 -07:00
parent 6eafac8a34
commit 00bdef3093
4 changed files with 31 additions and 1 deletions

View File

@ -48,6 +48,15 @@ func TestAccVpc_tags(t *testing.T) {
testAccCheckTags(&vpc.Tags, "foo", "bar"),
),
},
resource.TestStep{
Config: testAccVpcConfigTagsUpdate,
Check: resource.ComposeTestCheckFunc(
testAccCheckVpcExists("aws_vpc.foo", &vpc),
testAccCheckTags(&vpc.Tags, "foo", ""),
testAccCheckTags(&vpc.Tags, "bar", "baz"),
),
},
},
})
}
@ -170,3 +179,13 @@ resource "aws_vpc" "foo" {
}
}
`
const testAccVpcConfigTagsUpdate = `
resource "aws_vpc" "foo" {
cidr_block = "10.1.0.0/16"
tags {
bar = "baz"
}
}
`

View File

@ -14,9 +14,15 @@ func testAccCheckTags(
return func(s *terraform.State) error {
m := tagsToMap(*ts)
v, ok := m[key]
if !ok {
if value != "" && !ok {
return fmt.Errorf("Missing tag: %s", key)
} else if value == "" && ok {
return fmt.Errorf("Extra tag: %s", key)
}
if value == "" {
return nil
}
if v != value {
return fmt.Errorf("%s: bad value: %s", key, v)
}

View File

@ -373,6 +373,7 @@ func (d *ResourceData) getMap(
if d.config != nil && source == getSourceConfig {
// For config, we always set the result to exactly what was requested
if mraw, ok := d.config.Get(k); ok {
result = make(map[string]interface{})
switch m := mraw.(type) {
case []interface{}:
for _, innerRaw := range m {

View File

@ -143,6 +143,10 @@ func (s *Schema) finalizeDiff(
return d
}
if d.NewRemoved {
return d
}
if s.Computed {
if d.Old != "" && d.New == "" {
// This is a computed value with an old value set already,