provider/aws: Refresh state on Directory Service not found (#6294)

When a directory service was not found, Terraform was panicking due to
`dir := out.DirectoryDescriptions[0]`. The AWS API doesn't throw an
Error in this case. IT just return s0 results. Therefore, we should
check for 0 results in the return and remove the directory from the
state
This commit is contained in:
Paul Stack 2016-04-22 01:13:04 +01:00
parent 4345c08194
commit fb1a82dbd7
1 changed files with 7 additions and 0 deletions

View File

@ -401,6 +401,13 @@ func resourceAwsDirectoryServiceDirectoryRead(d *schema.ResourceData, meta inter
out, err := dsconn.DescribeDirectories(&input)
if err != nil {
return err
}
if len(out.DirectoryDescriptions) == 0 {
log.Printf("[WARN] Directory %s not found", d.Id())
d.SetId("")
return nil
}
dir := out.DirectoryDescriptions[0]