Skip to content

Commit

Permalink
tests/resource/aws_flow_log: Add covering acceptance test for #7528
Browse files Browse the repository at this point in the history
Output from acceptance testing (before fix):

```
=== CONT  TestAccAWSFlowLog_LogDestinationType_S3_Invalid
panic: runtime error: index out of range

goroutine 249 [running]:
github.com/terraform-providers/terraform-provider-aws/aws.resourceAwsLogFlowCreate(0xc000a38fc0, 0x4838760, 0xc0004c1800, 0xc000a38fc0, 0x0)
	/Users/bflad/src/github.com/terraform-providers/terraform-provider-aws/aws/resource_aws_flow_log.go:149 +0xc6e
github.com/hashicorp/terraform/helper/schema.(*Resource).Apply(0xc00024fc70, 0xc0004fad70, 0xc0007187a0, 0x4838760, 0xc0004c1800, 0xc000510e01, 0x31, 0x0)
	/Users/bflad/go/pkg/mod/github.com/hashicorp/[email protected]/helper/schema/resource.go:225 +0x351
```

Output from acceptance testing (after fix):

```
--- PASS: TestAccAWSFlowLog_LogDestinationType_S3_Invalid (74.41s)
```
  • Loading branch information
bflad committed Feb 19, 2019
1 parent 8eab274 commit ef70579
Showing 1 changed file with 36 additions and 0 deletions.
36 changes: 36 additions & 0 deletions aws/resource_aws_flow_log_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package aws

import (
"fmt"
"regexp"
"testing"

"github.com/aws/aws-sdk-go/aws"
Expand Down Expand Up @@ -146,6 +147,22 @@ func TestAccAWSFlowLog_LogDestinationType_S3(t *testing.T) {
})
}

func TestAccAWSFlowLog_LogDestinationType_S3_Invalid(t *testing.T) {
rName := acctest.RandomWithPrefix("tf-acc-test-flow-log-s3-invalid")

resource.ParallelTest(t, resource.TestCase{
PreCheck: func() { testAccPreCheck(t) },
Providers: testAccProviders,
CheckDestroy: testAccCheckFlowLogDestroy,
Steps: []resource.TestStep{
{
Config: testAccFlowLogConfig_LogDestinationType_S3_Invalid(rName),
ExpectError: regexp.MustCompile(`Access Denied for LogDestination`),
},
},
})
}

func testAccCheckFlowLogExists(n string, flowLog *ec2.FlowLog) resource.TestCheckFunc {
return func(s *terraform.State) error {
rs, ok := s.RootModule().Resources[n]
Expand Down Expand Up @@ -269,6 +286,25 @@ resource "aws_flow_log" "test" {
`, rName, rName)
}

func testAccFlowLogConfig_LogDestinationType_S3_Invalid(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
cidr_block = "10.0.0.0/16"
tags = {
Name = %q
}
}
resource "aws_flow_log" "test" {
log_destination = "arn:aws:s3:::does-not-exist"
log_destination_type = "s3"
traffic_type = "ALL"
vpc_id = "${aws_vpc.test.id}"
}
`, rName)
}

func testAccFlowLogConfig_SubnetID(rName string) string {
return fmt.Sprintf(`
resource "aws_vpc" "test" {
Expand Down

0 comments on commit ef70579

Please sign in to comment.