Skip to content

Commit

Permalink
provider/aws: Refresh state on Directory Service not found (#6294)
Browse files Browse the repository at this point in the history
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
  • Loading branch information
stack72 committed Apr 22, 2016
1 parent 4345c08 commit fb1a82d
Showing 1 changed file with 7 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down

0 comments on commit fb1a82d

Please sign in to comment.