From ef705793fd868587c526e488f53ecf17784aa106 Mon Sep 17 00:00:00 2001 From: Brian Flad Date: Mon, 18 Feb 2019 23:01:01 -0500 Subject: [PATCH] tests/resource/aws_flow_log: Add covering acceptance test for #7528 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/terraform@v0.11.9-beta1/helper/schema/resource.go:225 +0x351 ``` Output from acceptance testing (after fix): ``` --- PASS: TestAccAWSFlowLog_LogDestinationType_S3_Invalid (74.41s) ``` --- aws/resource_aws_flow_log_test.go | 36 +++++++++++++++++++++++++++++++ 1 file changed, 36 insertions(+) diff --git a/aws/resource_aws_flow_log_test.go b/aws/resource_aws_flow_log_test.go index 5a147d38831..31d77c8e0d1 100644 --- a/aws/resource_aws_flow_log_test.go +++ b/aws/resource_aws_flow_log_test.go @@ -2,6 +2,7 @@ package aws import ( "fmt" + "regexp" "testing" "github.com/aws/aws-sdk-go/aws" @@ -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] @@ -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" {