-
Notifications
You must be signed in to change notification settings - Fork 9.7k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
provider/aws: Add aws_kinesis_stream data source #13562
Merged
stack72
merged 1 commit into
hashicorp:master
from
cbroglie:data-source-aws-kinesis-stream
Apr 20, 2017
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
package aws | ||
|
||
import ( | ||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/kinesis" | ||
"github.com/hashicorp/terraform/helper/schema" | ||
) | ||
|
||
func dataSourceAwsKinesisStream() *schema.Resource { | ||
return &schema.Resource{ | ||
Read: dataSourceAwsKinesisStreamRead, | ||
|
||
Schema: map[string]*schema.Schema{ | ||
"name": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Required: true, | ||
}, | ||
|
||
"arn": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"creation_timestamp": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"status": &schema.Schema{ | ||
Type: schema.TypeString, | ||
Computed: true, | ||
}, | ||
|
||
"retention_period": &schema.Schema{ | ||
Type: schema.TypeInt, | ||
Computed: true, | ||
}, | ||
|
||
"open_shards": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
}, | ||
|
||
"closed_shards": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
}, | ||
|
||
"shard_level_metrics": &schema.Schema{ | ||
Type: schema.TypeSet, | ||
Computed: true, | ||
Elem: &schema.Schema{Type: schema.TypeString}, | ||
Set: schema.HashString, | ||
}, | ||
|
||
"tags": &schema.Schema{ | ||
Type: schema.TypeMap, | ||
Computed: true, | ||
}, | ||
}, | ||
} | ||
} | ||
|
||
func dataSourceAwsKinesisStreamRead(d *schema.ResourceData, meta interface{}) error { | ||
conn := meta.(*AWSClient).kinesisconn | ||
sn := d.Get("name").(string) | ||
|
||
state, err := readKinesisStreamState(conn, sn) | ||
if err != nil { | ||
return err | ||
} | ||
d.SetId(state.arn) | ||
d.Set("arn", state.arn) | ||
d.Set("name", sn) | ||
d.Set("open_shards", state.openShards) | ||
d.Set("closed_shards", state.closedShards) | ||
d.Set("status", state.status) | ||
d.Set("creation_timestamp", state.creationTimestamp) | ||
d.Set("retention_period", state.retentionPeriod) | ||
d.Set("shard_level_metrics", state.shardLevelMetrics) | ||
|
||
tags, err := conn.ListTagsForStream(&kinesis.ListTagsForStreamInput{ | ||
StreamName: aws.String(sn), | ||
}) | ||
if err != nil { | ||
return err | ||
} | ||
d.Set("tags", tagsToMapKinesis(tags.Tags)) | ||
|
||
return nil | ||
} |
94 changes: 94 additions & 0 deletions
94
builtin/providers/aws/data_source_aws_kinesis_stream_test.go
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,94 @@ | ||
package aws | ||
|
||
import ( | ||
"fmt" | ||
"testing" | ||
|
||
"github.com/aws/aws-sdk-go/aws" | ||
"github.com/aws/aws-sdk-go/service/kinesis" | ||
"github.com/hashicorp/terraform/helper/acctest" | ||
"github.com/hashicorp/terraform/helper/resource" | ||
) | ||
|
||
func TestAccAWSKinesisStreamDataSource(t *testing.T) { | ||
var stream kinesis.StreamDescription | ||
|
||
sn := fmt.Sprintf("terraform-kinesis-test-%d", acctest.RandInt()) | ||
config := fmt.Sprintf(testAccCheckAwsKinesisStreamDataSourceConfig, sn) | ||
|
||
updateShardCount := func() { | ||
conn := testAccProvider.Meta().(*AWSClient).kinesisconn | ||
_, err := conn.UpdateShardCount(&kinesis.UpdateShardCountInput{ | ||
ScalingType: aws.String(kinesis.ScalingTypeUniformScaling), | ||
StreamName: aws.String(sn), | ||
TargetShardCount: aws.Int64(3), | ||
}) | ||
if err != nil { | ||
t.Fatalf("Error calling UpdateShardCount: %s", err) | ||
} | ||
if err := waitForKinesisToBeActive(conn, sn); err != nil { | ||
t.Fatal(err) | ||
} | ||
} | ||
|
||
resource.Test(t, resource.TestCase{ | ||
PreCheck: func() { testAccPreCheck(t) }, | ||
Providers: testAccProviders, | ||
CheckDestroy: testAccCheckKinesisStreamDestroy, | ||
Steps: []resource.TestStep{ | ||
{ | ||
Config: config, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream", &stream), | ||
resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "arn"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "name", sn), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "status", "ACTIVE"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "open_shards.#", "2"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "closed_shards.#", "0"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "shard_level_metrics.#", "2"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "retention_period", "72"), | ||
resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "creation_timestamp"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "tags.Name", "tf-test"), | ||
), | ||
}, | ||
{ | ||
Config: config, | ||
PreConfig: updateShardCount, | ||
Check: resource.ComposeTestCheckFunc( | ||
testAccCheckKinesisStreamExists("aws_kinesis_stream.test_stream", &stream), | ||
resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "arn"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "name", sn), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "status", "ACTIVE"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "open_shards.#", "3"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "closed_shards.#", "4"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "shard_level_metrics.#", "2"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "retention_period", "72"), | ||
resource.TestCheckResourceAttrSet("data.aws_kinesis_stream.test_stream", "creation_timestamp"), | ||
resource.TestCheckResourceAttr("data.aws_kinesis_stream.test_stream", "tags.Name", "tf-test"), | ||
), | ||
}, | ||
}, | ||
}) | ||
} | ||
|
||
var testAccCheckAwsKinesisStreamDataSourceConfig = ` | ||
resource "aws_kinesis_stream" "test_stream" { | ||
name = "%s" | ||
shard_count = 2 | ||
retention_period = 72 | ||
tags { | ||
Name = "tf-test" | ||
} | ||
shard_level_metrics = [ | ||
"IncomingBytes", | ||
"OutgoingBytes" | ||
] | ||
lifecycle { | ||
ignore_changes = ["shard_count"] | ||
} | ||
} | ||
|
||
data "aws_kinesis_stream" "test_stream" { | ||
name = "${aws_kinesis_stream.test_stream.name}" | ||
} | ||
` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
website/source/docs/providers/aws/d/kinesis_stream.html.markdown
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
--- | ||
layout: "aws" | ||
page_title: "AWS: aws_kinesis_stream" | ||
sidebar_current: "docs-aws-datasource-kinesis-stream" | ||
description: |- | ||
Provides a Kinesis Stream data source. | ||
--- | ||
|
||
# aws\_kinesis\_stream | ||
|
||
Use this data source to get information about a Kinesis Stream for use in other | ||
resources. | ||
|
||
For more details, see the [Amazon Kinesis Documentation][1]. | ||
|
||
## Example Usage | ||
|
||
``` | ||
data "aws_kinesis_stream" "stream" { | ||
name = "stream-name" | ||
} | ||
``` | ||
|
||
## Argument Reference | ||
|
||
* `name` - (Required) The name of the Kinesis Stream. | ||
|
||
## Attributes Reference | ||
|
||
`id` is set to the Amazon Resource Name (ARN) of the Kinesis Stream. In addition, the following attributes | ||
are exported: | ||
|
||
* `arn` - The Amazon Resource Name (ARN) of the Kinesis Stream (same as id). | ||
* `name` - The name of the Kinesis Stream. | ||
* `creation_timestamp` - The approximate UNIX timestamp that the stream was created. | ||
* `status` - The current status of the stream. The stream status is one of CREATING, DELETING, ACTIVE, or UPDATING. | ||
* `retention_period` - Length of time (in hours) data records are accessible after they are added to the stream. | ||
* `open_shards` - The list of shard ids in the OPEN state. See [Shard State][2] for more. | ||
* `closed_shards` - The list of shard ids in the CLOSED state. See [Shard State][2] for more. | ||
* `shard_level_metrics` - A list of shard-level CloudWatch metrics which are enabled for the stream. See [Monitoring with CloudWatch][3] for more. | ||
* `tags` - A mapping of tags to assigned to the stream. | ||
|
||
[1]: https://aws.amazon.com/documentation/kinesis/ | ||
[2]: https://docs.aws.amazon.com/streams/latest/dev/kinesis-using-sdk-java-after-resharding.html#kinesis-using-sdk-java-resharding-data-routing | ||
[3]: https://docs.aws.amazon.com/streams/latest/dev/monitoring-with-cloudwatch.html |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why change this to OpenShards?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There is no actual change in behavior here, the value of
s.shardCount
before was the number of open shards. And since I'm now storing the actual list of open shard ids, we can derive the shard count from it rather than storing it separately.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Got it :)