github.com/recobe182/terraform@v0.8.5-0.20170117231232-49ab22a935b7/builtin/providers/aws/resource_aws_inspector_assessment_target_test.go (about) 1 package aws 2 3 import ( 4 "fmt" 5 "testing" 6 7 "github.com/aws/aws-sdk-go/aws" 8 "github.com/aws/aws-sdk-go/aws/awserr" 9 "github.com/aws/aws-sdk-go/service/inspector" 10 "github.com/hashicorp/terraform/helper/resource" 11 "github.com/hashicorp/terraform/terraform" 12 ) 13 14 func TestAccAWSInspectorTarget_basic(t *testing.T) { 15 resource.Test(t, resource.TestCase{ 16 PreCheck: func() { testAccPreCheck(t) }, 17 Providers: testAccProviders, 18 CheckDestroy: testAccCheckAWSInspectorTargetAssessmentDestroy, 19 Steps: []resource.TestStep{ 20 resource.TestStep{ 21 Config: testAccAWSInspectorTargetAssessment, 22 Check: resource.ComposeTestCheckFunc( 23 testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"), 24 ), 25 }, 26 resource.TestStep{ 27 Config: testAccCheckAWSInspectorTargetAssessmentModified, 28 Check: resource.ComposeTestCheckFunc( 29 testAccCheckAWSInspectorTargetExists("aws_inspector_assessment_target.foo"), 30 ), 31 }, 32 }, 33 }) 34 } 35 36 func testAccCheckAWSInspectorTargetAssessmentDestroy(s *terraform.State) error { 37 conn := testAccProvider.Meta().(*AWSClient).inspectorconn 38 39 for _, rs := range s.RootModule().Resources { 40 if rs.Type != "aws_inspector_assessment_target" { 41 continue 42 } 43 44 resp, err := conn.DescribeAssessmentTargets(&inspector.DescribeAssessmentTargetsInput{ 45 AssessmentTargetArns: []*string{ 46 aws.String(rs.Primary.ID), 47 }, 48 }) 49 50 if err != nil { 51 if inspectorerr, ok := err.(awserr.Error); ok && inspectorerr.Code() == "InvalidInputException" { 52 return nil 53 } else { 54 return fmt.Errorf("Error finding Inspector Assessment Target: %s", err) 55 } 56 } 57 58 if len(resp.AssessmentTargets) > 0 { 59 return fmt.Errorf("Found Target, expected none: %s", resp) 60 } 61 } 62 63 return nil 64 } 65 66 func testAccCheckAWSInspectorTargetExists(name string) resource.TestCheckFunc { 67 return func(s *terraform.State) error { 68 _, ok := s.RootModule().Resources[name] 69 if !ok { 70 return fmt.Errorf("Not found: %s", name) 71 } 72 73 return nil 74 } 75 } 76 77 var testAccAWSInspectorTargetAssessment = ` 78 79 resource "aws_inspector_resource_group" "foo" { 80 tags { 81 Name = "bar" 82 } 83 } 84 85 resource "aws_inspector_assessment_target" "foo" { 86 name = "foo" 87 resource_group_arn = "${aws_inspector_resource_group.foo.arn}" 88 }` 89 90 var testAccCheckAWSInspectorTargetAssessmentModified = ` 91 92 resource "aws_inspector_resource_group" "foo" { 93 tags { 94 Name = "bar" 95 } 96 } 97 98 resource "aws_inspector_assessment_target" "foo" { 99 name = "bar" 100 resource_group_arn = "${aws_inspector_resource_group.foo.arn}" 101 }`