Skip to content

Commit

Permalink
Merge pull request #3834 from terraform-providers/b-aws_kinesis_fireh…
Browse files Browse the repository at this point in the history
…ose_delivery_stream-arn-import-crash

resource/aws_kinesis_firehose_delivery_stream: Prevent crash on malformed ID for import
  • Loading branch information
bflad authored Mar 20, 2018
2 parents d6f9849 + a5cffac commit d6eb19e
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
14 changes: 14 additions & 0 deletions aws/import_aws_kinesis_firehose_delivery_stream_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/hashicorp/terraform/helper/acctest"
Expand Down Expand Up @@ -33,6 +34,19 @@ func TestAccAWSKinesisFirehoseDeliveryStream_importBasic(t *testing.T) {
ImportState: true,
ImportStateVerify: true,
},
// Ensure we properly error on malformed import IDs
{
ResourceName: resName,
ImportState: true,
ImportStateId: "just-a-name",
ExpectError: regexp.MustCompile(`Expected ID in format`),
},
{
ResourceName: resName,
ImportState: true,
ImportStateId: "arn:aws:firehose:us-east-1:123456789012:missing-slash",
ExpectError: regexp.MustCompile(`Expected ID in format`),
},
},
})
}
9 changes: 7 additions & 2 deletions aws/resource_aws_kinesis_firehose_delivery_stream.go
Original file line number Diff line number Diff line change
Expand Up @@ -376,11 +376,16 @@ func resourceAwsKinesisFirehoseDeliveryStream() *schema.Resource {

Importer: &schema.ResourceImporter{
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
idErr := fmt.Errorf("Expected ID in format of arn:PARTITION:firehose:REGION:ACCOUNTID:deliverystream/NAME and provided: %s", d.Id())
resARN, err := arn.Parse(d.Id())
if err != nil {
return nil, err
return nil, idErr
}
d.Set("name", strings.Split(resARN.Resource, "/")[1])
resourceParts := strings.Split(resARN.Resource, "/")
if len(resourceParts) != 2 {
return nil, idErr
}
d.Set("name", resourceParts[1])
return []*schema.ResourceData{d}, nil
},
},
Expand Down

0 comments on commit d6eb19e

Please sign in to comment.