aws: kms resources - Simplify error handling

This commit is contained in:
Radek Simko 2015-11-14 17:41:50 +00:00 committed by Radek Simko
parent 2b244e21bc
commit 5c9fe668f5
2 changed files with 17 additions and 21 deletions

View File

@ -75,12 +75,8 @@ func resourceAwsKmsAliasRead(d *schema.ResourceData, meta interface{}) error {
}
for _, e := range resp.Aliases {
if name == *e.AliasName {
if err := d.Set("arn", e.AliasArn); err != nil {
return err
}
if err := d.Set("target_key_id", e.TargetKeyId); err != nil {
return err
}
d.Set("arn", e.AliasArn)
d.Set("target_key_id", e.TargetKeyId)
return nil
}
}
@ -94,7 +90,8 @@ func resourceAwsKmsAliasUpdate(d *schema.ResourceData, meta interface{}) error {
conn := meta.(*AWSClient).kmsconn
if d.HasChange("target_key_id") {
if err := resourceAwsKmsAliasTargetUpdate(conn, d); err != nil {
err := resourceAwsKmsAliasTargetUpdate(conn, d)
if err != nil {
return err
}
}
@ -124,8 +121,11 @@ func resourceAwsKmsAliasDelete(d *schema.ResourceData, meta interface{}) error {
AliasName: aws.String(name),
}
_, err := conn.DeleteAlias(req)
if err != nil {
return err
}
log.Printf("[DEBUG] KMS Alias: %s deleted.", name)
d.SetId("")
return err
return nil
}

View File

@ -105,18 +105,11 @@ func resourceAwsKmsKeyRead(d *schema.ResourceData, meta interface{}) error {
func resourceAwsKmsKeyReadResult(d *schema.ResourceData, metadata *kms.KeyMetadata) error {
d.SetId(*metadata.KeyId)
if err := d.Set("arn", metadata.Arn); err != nil {
return err
}
if err := d.Set("key_id", metadata.KeyId); err != nil {
return err
}
if err := d.Set("description", metadata.Description); err != nil {
return err
}
if err := d.Set("key_usage", metadata.KeyUsage); err != nil {
return err
}
d.Set("arn", metadata.Arn)
d.Set("key_id", metadata.KeyId)
d.Set("description", metadata.Description)
d.Set("key_usage", metadata.KeyUsage)
return nil
}
@ -176,8 +169,11 @@ func resourceAwsKmsKeyDelete(d *schema.ResourceData, meta interface{}) error {
req.PendingWindowInDays = aws.Int64(int64(v.(int)))
}
_, err := conn.ScheduleKeyDeletion(req)
if err != nil {
return err
}
log.Printf("[DEBUG] KMS Key: %s deactivated.", keyId)
d.SetId("")
return err
return nil
}