2015-07-19 06:09:25 +02:00
|
|
|
package aws
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"testing"
|
|
|
|
|
|
|
|
"github.com/aws/aws-sdk-go/aws"
|
2015-12-22 14:22:06 +01:00
|
|
|
"github.com/aws/aws-sdk-go/aws/awserr"
|
2015-07-19 06:09:25 +02:00
|
|
|
"github.com/aws/aws-sdk-go/service/codedeploy"
|
|
|
|
"github.com/hashicorp/terraform/helper/resource"
|
|
|
|
"github.com/hashicorp/terraform/terraform"
|
|
|
|
)
|
|
|
|
|
|
|
|
func TestAccAWSCodeDeployApp_basic(t *testing.T) {
|
|
|
|
resource.Test(t, resource.TestCase{
|
|
|
|
PreCheck: func() { testAccPreCheck(t) },
|
|
|
|
Providers: testAccProviders,
|
|
|
|
CheckDestroy: testAccCheckAWSCodeDeployAppDestroy,
|
|
|
|
Steps: []resource.TestStep{
|
|
|
|
resource.TestStep{
|
|
|
|
Config: testAccAWSCodeDeployApp,
|
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
resource.TestStep{
|
2015-11-14 13:19:29 +01:00
|
|
|
Config: testAccAWSCodeDeployAppModified,
|
2015-07-19 06:09:25 +02:00
|
|
|
Check: resource.ComposeTestCheckFunc(
|
|
|
|
testAccCheckAWSCodeDeployAppExists("aws_codedeploy_app.foo"),
|
|
|
|
),
|
|
|
|
},
|
|
|
|
},
|
|
|
|
})
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSCodeDeployAppDestroy(s *terraform.State) error {
|
|
|
|
conn := testAccProvider.Meta().(*AWSClient).codedeployconn
|
|
|
|
|
|
|
|
for _, rs := range s.RootModule().Resources {
|
|
|
|
if rs.Type != "aws_codedeploy_app" {
|
|
|
|
continue
|
|
|
|
}
|
|
|
|
|
2015-12-22 14:22:06 +01:00
|
|
|
_, err := conn.GetApplication(&codedeploy.GetApplicationInput{
|
2015-12-22 04:43:42 +01:00
|
|
|
ApplicationName: aws.String(rs.Primary.Attributes["name"]),
|
2015-07-19 06:09:25 +02:00
|
|
|
})
|
|
|
|
|
2015-12-22 14:22:06 +01:00
|
|
|
if err != nil {
|
|
|
|
// Verify the error is what we want
|
|
|
|
if ae, ok := err.(awserr.Error); ok && ae.Code() == "ApplicationDoesNotExistException" {
|
|
|
|
continue
|
2015-07-19 06:09:25 +02:00
|
|
|
}
|
2015-12-22 14:22:06 +01:00
|
|
|
return err
|
2015-07-19 06:09:25 +02:00
|
|
|
}
|
|
|
|
|
2015-12-22 14:22:06 +01:00
|
|
|
return fmt.Errorf("still exists")
|
2015-07-19 06:09:25 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
|
|
|
|
func testAccCheckAWSCodeDeployAppExists(name string) resource.TestCheckFunc {
|
|
|
|
return func(s *terraform.State) error {
|
|
|
|
_, ok := s.RootModule().Resources[name]
|
|
|
|
if !ok {
|
|
|
|
return fmt.Errorf("Not found: %s", name)
|
|
|
|
}
|
|
|
|
|
|
|
|
return nil
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
var testAccAWSCodeDeployApp = `
|
|
|
|
resource "aws_codedeploy_app" "foo" {
|
|
|
|
name = "foo"
|
|
|
|
}`
|
|
|
|
|
2015-11-14 13:19:29 +01:00
|
|
|
var testAccAWSCodeDeployAppModified = `
|
2015-07-19 06:09:25 +02:00
|
|
|
resource "aws_codedeploy_app" "foo" {
|
|
|
|
name = "bar"
|
|
|
|
}`
|