github.com/danp/terraform@v0.9.5-0.20170426144147-39d740081351/builtin/providers/aws/data_source_aws_kinesis_stream_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/service/kinesis" 9 "github.com/hashicorp/terraform/helper/acctest" 10 "github.com/hashicorp/terraform/helper/resource" 11 ) 12 13 func TestAccAWSKinesisStreamDataSource(t *testing.T) { 14 var stream kinesis.StreamDescription 15 16 sn := fmt.Sprintf("terraform-kinesis-test-%d", acctest.RandInt()) 17 config := fmt.Sprintf(testAccCheckAwsKinesisStreamDataSourceConfig, sn) 18 19 updateShardCount := func() { 20 conn := testAccProvider.Meta().(*AWSClient).kinesisconn 21 _, err := conn.UpdateShardCount(&kinesis.UpdateShardCountInput{ 22 ScalingType: aws.String(kinesis.ScalingTypeUniformScaling), 23 StreamName: aws.String(sn), 24 TargetShardCount: aws.Int64(3), 25 }) 26 if err != nil { 27 t.Fatalf("Error calling UpdateShardCount: %s", err) 28 } 29 if err := waitForKinesisToBeActive(conn, sn); err != nil { 30 t.Fatal(err) 31 } 32 } 33 34 resource.Test(t, resource.TestCase{ 35 PreCheck: func() { testAccPreCheck(t) }, 36 Providers: testAccProviders, 37 CheckDestroy: testAccCheckKinesisStreamDestroy, 38 Steps: []resource.TestStep{ 39 { 40 Config: config, 41 Check: resource.ComposeTestCheckFunc( 42 testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream", &stream), 43 resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "arn"), 44 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "name", sn), 45 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "status", "ACTIVE"), 46 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "open_shards.#", "2"), 47 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "closed_shards.#", "0"), 48 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "shard_level_metrics.#", "2"), 49 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "retention_period", "72"), 50 resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "creation_timestamp"), 51 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "tags.Name", "tf-test"), 52 ), 53 }, 54 { 55 Config: config, 56 PreConfig: updateShardCount, 57 Check: resource.ComposeTestCheckFunc( 58 testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream", &stream), 59 resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "arn"), 60 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "name", sn), 61 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "status", "ACTIVE"), 62 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "open_shards.#", "3"), 63 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "closed_shards.#", "4"), 64 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "shard_level_metrics.#", "2"), 65 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "retention_period", "72"), 66 resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "creation_timestamp"), 67 resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "tags.Name", "tf-test"), 68 ), 69 }, 70 }, 71 }) 72 } 73 74 var testAccCheckAwsKinesisStreamDataSourceConfig = ` 75 resource "aws_kinesis_stream" "test_stream" { 76 name = "%s" 77 shard_count = 2 78 retention_period = 72 79 tags { 80 Name = "tf-test" 81 } 82 shard_level_metrics = [ 83 "IncomingBytes", 84 "OutgoingBytes" 85 ] 86 lifecycle { 87 ignore_changes = ["shard_count"] 88 } 89 } 90 91 data "aws_kinesis_stream" "test_stream" { 92 name = "${aws_kinesis_stream.test_stream.name}" 93 } 94 `