provider/aws: fix cache SG tests

* CheckDestroy should handle not found error
 * Pin provider in config to region most likely to have EC2 Classic
This commit is contained in:
Paul Hinze 2015-12-21 21:12:47 -06:00
parent 47f8b0cd79
commit 67832f6bd0

View File

@ -5,6 +5,7 @@ import (
"testing" "testing"
"github.com/aws/aws-sdk-go/aws" "github.com/aws/aws-sdk-go/aws"
"github.com/aws/aws-sdk-go/aws/awserr"
"github.com/aws/aws-sdk-go/service/elasticache" "github.com/aws/aws-sdk-go/service/elasticache"
"github.com/hashicorp/terraform/helper/resource" "github.com/hashicorp/terraform/helper/resource"
"github.com/hashicorp/terraform/terraform" "github.com/hashicorp/terraform/terraform"
@ -36,12 +37,14 @@ func testAccCheckAWSElasticacheSecurityGroupDestroy(s *terraform.State) error {
res, err := conn.DescribeCacheSecurityGroups(&elasticache.DescribeCacheSecurityGroupsInput{ res, err := conn.DescribeCacheSecurityGroups(&elasticache.DescribeCacheSecurityGroupsInput{
CacheSecurityGroupName: aws.String(rs.Primary.ID), CacheSecurityGroupName: aws.String(rs.Primary.ID),
}) })
if err != nil { if awserr, ok := err.(awserr.Error); ok && awserr.Code() == "CacheSecurityGroupNotFound" {
return err continue
} }
if len(res.CacheSecurityGroups) > 0 { if len(res.CacheSecurityGroups) > 0 {
return fmt.Errorf("still exist.") return fmt.Errorf("cache security group still exists")
} }
return err
} }
return nil return nil
} }
@ -69,6 +72,9 @@ func testAccCheckAWSElasticacheSecurityGroupExists(n string) resource.TestCheckF
} }
var testAccAWSElasticacheSecurityGroupConfig = fmt.Sprintf(` var testAccAWSElasticacheSecurityGroupConfig = fmt.Sprintf(`
provider "aws" {
region = "us-east-1"
}
resource "aws_security_group" "bar" { resource "aws_security_group" "bar" {
name = "tf-test-security-group-%03d" name = "tf-test-security-group-%03d"
description = "tf-test-security-group-descr" description = "tf-test-security-group-descr"