aws_key_pair: Ensure key_name attribute is set

Ensure that the `key_name` attribute is available to `aws_key_pair`
resource dependents, even when the attribute is not specifically
set (i.e., when `key_name_prefix` or automatic naming is performed).

Fixes #10983.
This commit is contained in:
Michael S. Fischer 2017-01-01 12:17:43 -08:00
parent af5baf7b13
commit af9505ffa2
1 changed files with 2 additions and 0 deletions

View File

@ -75,8 +75,10 @@ func resourceAwsKeyPairCreate(d *schema.ResourceData, meta interface{}) error {
keyName = v.(string)
} else if v, ok := d.GetOk("key_name_prefix"); ok {
keyName = resource.PrefixedUniqueId(v.(string))
d.Set("key_name", keyName)
} else {
keyName = resource.UniqueId()
d.Set("key_name", keyName)
}
publicKey := d.Get("public_key").(string)