Skip to content

Commit

Permalink
Merge pull request #8027 from atsushi-ishibashi/issue7549
Browse files Browse the repository at this point in the history
r/kinesis_analytics_application: Support import
  • Loading branch information
bflad authored Mar 21, 2019
2 parents 95eadf0 + 1259da9 commit 6ec1dbb
Show file tree
Hide file tree
Showing 3 changed files with 105 additions and 7 deletions.
10 changes: 10 additions & 0 deletions aws/resource_aws_kinesis_analytics_application.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"log"
"reflect"
"strings"
"time"

"github.com/aws/aws-sdk-go/aws"
Expand All @@ -20,6 +21,15 @@ func resourceAwsKinesisAnalyticsApplication() *schema.Resource {
Update: resourceAwsKinesisAnalyticsApplicationUpdate,
Delete: resourceAwsKinesisAnalyticsApplicationDelete,

Importer: &schema.ResourceImporter{
State: func(d *schema.ResourceData, meta interface{}) ([]*schema.ResourceData, error) {
arns := strings.Split(d.Id(), ":")
name := strings.Replace(arns[len(arns)-1], "application/", "", 1)
d.Set("name", name)
return []*schema.ResourceData{d}, nil
},
},

Schema: map[string]*schema.Schema{
"name": {
Type: schema.TypeString,
Expand Down
82 changes: 81 additions & 1 deletion aws/resource_aws_kinesis_analytics_application_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,11 @@ func TestAccAWSKinesisAnalyticsApplication_basic(t *testing.T) {
resource.TestCheckResourceAttr(resName, "code", "testCode\n"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -56,6 +61,11 @@ func TestAccAWSKinesisAnalyticsApplication_update(t *testing.T) {
resource.TestCheckResourceAttr(resName, "code", "testCode2\n"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -88,6 +98,11 @@ func TestAccAWSKinesisAnalyticsApplication_addCloudwatchLoggingOptions(t *testin
resource.TestCheckResourceAttrPair(resName, "cloudwatch_logging_options.0.log_stream_arn", "aws_cloudwatch_log_stream.test", "arn"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -122,6 +137,11 @@ func TestAccAWSKinesisAnalyticsApplication_updateCloudwatchLoggingOptions(t *tes
resource.TestCheckResourceAttrPair(resName, "cloudwatch_logging_options.0.log_stream_arn", "aws_cloudwatch_log_stream.test", "arn"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -144,6 +164,11 @@ func TestAccAWSKinesisAnalyticsApplication_inputsKinesisFirehose(t *testing.T) {
resource.TestCheckResourceAttr(resName, "inputs.0.kinesis_firehose.#", "1"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -173,6 +198,11 @@ func TestAccAWSKinesisAnalyticsApplication_inputsKinesisStream(t *testing.T) {
resource.TestCheckResourceAttr(resName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.json.#", "1"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -212,6 +242,11 @@ func TestAccAWSKinesisAnalyticsApplication_inputsAdd(t *testing.T) {
resource.TestCheckResourceAttr(resName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.json.#", "1"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -252,6 +287,11 @@ func TestAccAWSKinesisAnalyticsApplication_inputsUpdateKinesisStream(t *testing.
resource.TestCheckResourceAttr(resName, "inputs.0.schema.0.record_format.0.mapping_parameters.0.csv.#", "1"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -279,6 +319,11 @@ func TestAccAWSKinesisAnalyticsApplication_outputsKinesisStream(t *testing.T) {
resource.TestCheckResourceAttr(resName, "outputs.0.schema.0.record_format_type", "JSON"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand All @@ -302,6 +347,11 @@ func TestAccAWSKinesisAnalyticsApplication_outputsMultiple(t *testing.T) {
resource.TestCheckResourceAttr(resName, "outputs.#", "2"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -337,6 +387,11 @@ func TestAccAWSKinesisAnalyticsApplication_outputsAdd(t *testing.T) {
resource.TestCheckResourceAttr(resName, "outputs.0.schema.#", "1"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -378,6 +433,11 @@ func TestAccAWSKinesisAnalyticsApplication_outputsUpdateKinesisStream(t *testing
resource.TestCheckResourceAttr(resName, "outputs.0.schema.0.record_format_type", "CSV"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -413,6 +473,11 @@ func TestAccAWSKinesisAnalyticsApplication_Outputs_Lambda_Add(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "outputs.0.lambda.0.role_arn", iamRoleResourceName, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -440,6 +505,11 @@ func TestAccAWSKinesisAnalyticsApplication_Outputs_Lambda_Create(t *testing.T) {
resource.TestCheckResourceAttrPair(resourceName, "outputs.0.lambda.0.role_arn", iamRoleResourceName, "arn"),
),
},
{
ResourceName: resourceName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -467,6 +537,11 @@ func TestAccAWSKinesisAnalyticsApplication_referenceDataSource(t *testing.T) {
resource.TestCheckResourceAttr(resName, "reference_data_sources.0.schema.0.record_format.0.mapping_parameters.0.json.#", "1"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -499,6 +574,11 @@ func TestAccAWSKinesisAnalyticsApplication_referenceDataSourceUpdate(t *testing.
resource.TestCheckResourceAttr(resName, "reference_data_sources.#", "1"),
),
},
{
ResourceName: resName,
ImportState: true,
ImportStateVerify: true,
},
},
})
}
Expand Down Expand Up @@ -1010,7 +1090,7 @@ data "aws_iam_policy_document" "trust" {
resource "aws_iam_role" "test" {
name = "testAcc-%d"
assume_role_policy = "${data.aws_iam_policy_document.trust.json}"
assume_role_policy = "${data.aws_iam_policy_document.trust.json}"
}
data "aws_iam_policy_document" "test" {
Expand Down
20 changes: 14 additions & 6 deletions website/docs/r/kinesis_analytics_application.html.markdown
Original file line number Diff line number Diff line change
Expand Up @@ -59,11 +59,11 @@ The following arguments are supported:
* `name` - (Required) Name of the Kinesis Analytics Application.
* `code` - (Optional) SQL Code to transform input data, and generate output.
* `description` - (Optional) Description of the application.
* `cloudwatch_logging_options` - (Optional) The CloudWatch log stream options to monitor application errors.
* `cloudwatch_logging_options` - (Optional) The CloudWatch log stream options to monitor application errors.
See [CloudWatch Logging Options](#cloudwatch-logging-options) below for more details.
* `inputs` - (Optional) Input configuration of the application. See [Inputs](#inputs) below for more details.
* `outputs` - (Optional) Output destination configuration of the application. See [Outputs](#outputs) below for more details.
* `reference_data_sources` - (Optional) An S3 Reference Data Source for the application.
* `reference_data_sources` - (Optional) An S3 Reference Data Source for the application.
See [Reference Data Sources](#reference-data-sources) below for more details.

### CloudWatch Logging Options
Expand All @@ -83,11 +83,11 @@ The `inputs` block supports the following:

* `name_prefix` - (Required) The Name Prefix to use when creating an in-application stream.
* `schema` - (Required) The Schema format of the data in the streaming source. See [Source Schema](#source-schema) below for more details.
* `kinesis_firehose` - (Optional) The Kinesis Firehose configuration for the streaming source. Conflicts with `kinesis_stream`.
* `kinesis_firehose` - (Optional) The Kinesis Firehose configuration for the streaming source. Conflicts with `kinesis_stream`.
See [Kinesis Firehose](#kinesis-firehose) below for more details.
* `kinesis_stream` - (Optional) The Kinesis Stream configuration for the streaming source. Conflicts with `kinesis_firehose`.
* `kinesis_stream` - (Optional) The Kinesis Stream configuration for the streaming source. Conflicts with `kinesis_firehose`.
See [Kinesis Stream](#kinesis-stream) below for more details.
* `parallelism` - (Optional) The number of Parallel in-application streams to create.
* `parallelism` - (Optional) The number of Parallel in-application streams to create.
See [Parallelism](#parallelism) below for more details.
* `processing_configuration` - (Optional) The Processing Configuration to transform records as they are received from the stream.
See [Processing Configuration](#processing-configuration) below for more details.
Expand All @@ -114,7 +114,7 @@ The `reference_data_sources` block supports the following:

* `schema` - (Required) The Schema format of the data in the streaming source. See [Source Schema](#source-schema) below for more details.
* `table_name` - (Required) The in-application Table Name.
* `s3` - (Optional) The S3 configuration for the reference data source. See [S3 Reference](#s3-reference) below for more details.
* `s3` - (Optional) The S3 configuration for the reference data source. See [S3 Reference](#s3-reference) below for more details.

#### Kinesis Firehose

Expand Down Expand Up @@ -249,3 +249,11 @@ The following attributes are exported along with all argument references:
* `version` - The Version of the application.

[1]: https://docs.aws.amazon.com/kinesisanalytics/latest/dev/what-is.html

## Import

Kinesis Analytics Application can be imported by using ARN, e.g.

```
$ terraform import aws_kinesis_analytics_application.example arn:aws:kinesisanalytics:us-west-2:1234567890:application/example
```

0 comments on commit 6ec1dbb

Please sign in to comment.