providers/aws/aws_instance: user_data diffs properly
This commit is contained in:
parent
c89e02c545
commit
0d8f6645fa
|
@ -29,16 +29,8 @@ func resource_aws_instance_create(
|
||||||
|
|
||||||
// Figure out user data
|
// Figure out user data
|
||||||
userData := ""
|
userData := ""
|
||||||
if v, ok := rs.Attributes["user_data"]; ok {
|
if attr, ok := d.Attributes["user_data"]; ok {
|
||||||
userData = v
|
userData = attr.NewExtra.(string)
|
||||||
delete(rs.Attributes, "user_data")
|
|
||||||
}
|
|
||||||
|
|
||||||
if userData != "" {
|
|
||||||
// Set the SHA1 hash of the data as an attribute so we can
|
|
||||||
// compare for diffs.
|
|
||||||
hash := sha1.Sum([]byte(userData))
|
|
||||||
rs.Attributes["user_data_hash"] = hex.EncodeToString(hash[:])
|
|
||||||
}
|
}
|
||||||
|
|
||||||
// Build the creation struct
|
// Build the creation struct
|
||||||
|
@ -210,9 +202,15 @@ func resource_aws_instance_diff(
|
||||||
"security_groups",
|
"security_groups",
|
||||||
"subnet_id",
|
"subnet_id",
|
||||||
},
|
},
|
||||||
}
|
|
||||||
|
|
||||||
// TODO(mitchellh): figure out way to diff user_data_hash
|
PreProcess: map[string]diff.PreProcessFunc{
|
||||||
|
"user_data": func(v string) string {
|
||||||
|
println("SUMMIN: " + v)
|
||||||
|
hash := sha1.Sum([]byte(v))
|
||||||
|
return hex.EncodeToString(hash[:])
|
||||||
|
},
|
||||||
|
},
|
||||||
|
}
|
||||||
|
|
||||||
return b.Diff(s, c)
|
return b.Diff(s, c)
|
||||||
}
|
}
|
||||||
|
|
|
@ -36,7 +36,23 @@ func TestAccAWSInstance_normal(t *testing.T) {
|
||||||
testCheck,
|
testCheck,
|
||||||
resource.TestCheckResourceAttr(
|
resource.TestCheckResourceAttr(
|
||||||
"aws_instance.foo",
|
"aws_instance.foo",
|
||||||
"user_data_hash",
|
"user_data",
|
||||||
|
"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"),
|
||||||
|
),
|
||||||
|
},
|
||||||
|
|
||||||
|
// We repeat the exact same test so that we can be sure
|
||||||
|
// that the user data hash stuff is working without generating
|
||||||
|
// an incorrect diff.
|
||||||
|
resource.TestStep{
|
||||||
|
Config: testAccInstanceConfig,
|
||||||
|
Check: resource.ComposeTestCheckFunc(
|
||||||
|
testAccCheckInstanceExists(
|
||||||
|
"aws_instance.foo", &v),
|
||||||
|
testCheck,
|
||||||
|
resource.TestCheckResourceAttr(
|
||||||
|
"aws_instance.foo",
|
||||||
|
"user_data",
|
||||||
"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"),
|
"0beec7b5ea3f0fdbc95d0dd47f3c5bc275da8a33"),
|
||||||
),
|
),
|
||||||
},
|
},
|
||||||
|
|
Loading…
Reference in New Issue