Merge pull request #4527 from hashicorp/b-aws-resources-tests
provider/aws: Update opsworks, vpn connection route tests
This commit is contained in:
commit
bbfb9f0463
|
@ -256,6 +256,7 @@ func resourceAwsOpsworksStackRead(d *schema.ResourceData, meta interface{}) erro
|
|||
if err != nil {
|
||||
if awserr, ok := err.(awserr.Error); ok {
|
||||
if awserr.Code() == "ResourceNotFoundException" {
|
||||
log.Printf("[DEBUG] OpsWorks stack (%s) not found", d.Id())
|
||||
d.SetId("")
|
||||
return nil
|
||||
}
|
||||
|
@ -319,7 +320,7 @@ func resourceAwsOpsworksStackCreate(d *schema.ResourceData, meta interface{}) er
|
|||
req.DefaultAvailabilityZone = aws.String(defaultAvailabilityZone.(string))
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Creating OpsWorks stack: %s", *req.Name)
|
||||
log.Printf("[DEBUG] Creating OpsWorks stack: %s", req)
|
||||
|
||||
var resp *opsworks.CreateStackOutput
|
||||
err = resource.Retry(20*time.Minute, func() error {
|
||||
|
@ -336,7 +337,9 @@ func resourceAwsOpsworksStackCreate(d *schema.ResourceData, meta interface{}) er
|
|||
// The full error we're looking for looks something like
|
||||
// the following:
|
||||
// Service Role Arn: [...] is not yet propagated, please try again in a couple of minutes
|
||||
if opserr.Code() == "ValidationException" && strings.Contains(opserr.Message(), "not yet propagated") {
|
||||
propErr := "not yet propagated"
|
||||
trustErr := "not the necessary trust relationship"
|
||||
if opserr.Code() == "ValidationException" && (strings.Contains(opserr.Message(), trustErr) || strings.Contains(opserr.Message(), propErr)) {
|
||||
log.Printf("[INFO] Waiting for service IAM role to propagate")
|
||||
return cerr
|
||||
}
|
||||
|
@ -411,7 +414,7 @@ func resourceAwsOpsworksStackUpdate(d *schema.ResourceData, meta interface{}) er
|
|||
Version: aws.String(d.Get("configuration_manager_version").(string)),
|
||||
}
|
||||
|
||||
log.Printf("[DEBUG] Updating OpsWorks stack: %s", d.Id())
|
||||
log.Printf("[DEBUG] Updating OpsWorks stack: %s", req)
|
||||
|
||||
_, err = client.UpdateStack(req)
|
||||
if err != nil {
|
||||
|
|
|
@ -8,6 +8,7 @@ import (
|
|||
"github.com/hashicorp/terraform/terraform"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/opsworks"
|
||||
)
|
||||
|
||||
|
@ -358,9 +359,29 @@ func testAccAwsOpsworksCheckVpc(s *terraform.State) error {
|
|||
}
|
||||
|
||||
func testAccCheckAwsOpsworksStackDestroy(s *terraform.State) error {
|
||||
if len(s.RootModule().Resources) > 0 {
|
||||
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
|
||||
}
|
||||
opsworksconn := testAccProvider.Meta().(*AWSClient).opsworksconn
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_opsworks_stack" {
|
||||
continue
|
||||
}
|
||||
|
||||
return nil
|
||||
req := &opsworks.DescribeStacksInput{
|
||||
StackIds: []*string{
|
||||
aws.String(rs.Primary.ID),
|
||||
},
|
||||
}
|
||||
|
||||
_, err := opsworksconn.DescribeStacks(req)
|
||||
if err != nil {
|
||||
if awserr, ok := err.(awserr.Error); ok {
|
||||
if awserr.Code() == "ResourceNotFoundException" {
|
||||
// not found, all good
|
||||
return nil
|
||||
}
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
}
|
||||
return fmt.Errorf("Fall through error for OpsWorks stack test")
|
||||
}
|
||||
|
|
|
@ -5,6 +5,7 @@ import (
|
|||
"testing"
|
||||
|
||||
"github.com/aws/aws-sdk-go/aws"
|
||||
"github.com/aws/aws-sdk-go/aws/awserr"
|
||||
"github.com/aws/aws-sdk-go/service/ec2"
|
||||
|
||||
"github.com/hashicorp/terraform/helper/resource"
|
||||
|
@ -44,11 +45,57 @@ func TestAccAWSVpnConnectionRoute_basic(t *testing.T) {
|
|||
}
|
||||
|
||||
func testAccAwsVpnConnectionRouteDestroy(s *terraform.State) error {
|
||||
if len(s.RootModule().Resources) > 0 {
|
||||
return fmt.Errorf("Expected all resources to be gone, but found: %#v", s.RootModule().Resources)
|
||||
}
|
||||
conn := testAccProvider.Meta().(*AWSClient).ec2conn
|
||||
for _, rs := range s.RootModule().Resources {
|
||||
if rs.Type != "aws_vpn_connection_route" {
|
||||
continue
|
||||
}
|
||||
|
||||
return nil
|
||||
cidrBlock, vpnConnectionId := resourceAwsVpnConnectionRouteParseId(rs.Primary.ID)
|
||||
|
||||
routeFilters := []*ec2.Filter{
|
||||
&ec2.Filter{
|
||||
Name: aws.String("route.destination-cidr-block"),
|
||||
Values: []*string{aws.String(cidrBlock)},
|
||||
},
|
||||
&ec2.Filter{
|
||||
Name: aws.String("vpn-connection-id"),
|
||||
Values: []*string{aws.String(vpnConnectionId)},
|
||||
},
|
||||
}
|
||||
|
||||
resp, err := conn.DescribeVpnConnections(&ec2.DescribeVpnConnectionsInput{
|
||||
Filters: routeFilters,
|
||||
})
|
||||
if err != nil {
|
||||
if ec2err, ok := err.(awserr.Error); ok && ec2err.Code() == "InvalidVpnConnectionID.NotFound" {
|
||||
// not found, all good
|
||||
return nil
|
||||
}
|
||||
return err
|
||||
}
|
||||
|
||||
var vpnc *ec2.VpnConnection
|
||||
if resp != nil {
|
||||
// range over the connections and isolate the one we created
|
||||
for _, v := range resp.VpnConnections {
|
||||
if *v.VpnConnectionId == vpnConnectionId {
|
||||
vpnc = v
|
||||
}
|
||||
}
|
||||
|
||||
if vpnc == nil {
|
||||
// vpn connection not found, so that's good...
|
||||
return nil
|
||||
}
|
||||
|
||||
if vpnc.State != nil && *vpnc.State == "deleted" {
|
||||
return nil
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return fmt.Errorf("Fall through error, Check Destroy criteria not met")
|
||||
}
|
||||
|
||||
func testAccAwsVpnConnectionRoute(
|
||||
|
|
Loading…
Reference in New Issue