From 88daa5425bfa0533d4cd746418eda3e23a13b5cb Mon Sep 17 00:00:00 2001 From: nickyamanaka Date: Wed, 22 Sep 2021 21:57:58 -0600 Subject: [PATCH] #20068 logdeliveryconfigurations test: `data_source_aws_elasticache_cluster` basic kinesis --- ...ata_source_aws_elasticache_cluster_test.go | 90 +++++++++++++++++++ 1 file changed, 90 insertions(+) diff --git a/aws/data_source_aws_elasticache_cluster_test.go b/aws/data_source_aws_elasticache_cluster_test.go index 824d127bf946..4c45cebb04c7 100644 --- a/aws/data_source_aws_elasticache_cluster_test.go +++ b/aws/data_source_aws_elasticache_cluster_test.go @@ -56,6 +56,29 @@ func TestAccAWSDataElasticacheCluster_Engine_Redis_LogDeliveryConfigurations_Clo }, }) } + +func TestAccAWSDataElasticacheCluster_Engine_Redis_LogDeliveryConfigurations_KinesisFirehose(t *testing.T) { + rName := acctest.RandomWithPrefix("tf-acc-test") + dataSourceName := "data.aws_elasticache_cluster.test" + + resource.ParallelTest(t, resource.TestCase{ + PreCheck: func() { testAccPreCheck(t) }, + ErrorCheck: testAccErrorCheck(t, elasticache.EndpointsID), + Providers: testAccProviders, + Steps: []resource.TestStep{ + { + Config: testAccAWSElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations_KinesisFirehose(rName, true), + Check: resource.ComposeAggregateTestCheckFunc( + resource.TestCheckResourceAttr(dataSourceName, "log_delivery_configurations.0.destination_details.0.kinesis_firehose.0.delivery_stream", rName), + resource.TestCheckResourceAttr(dataSourceName, "log_delivery_configurations.0.destination_type", "kinesis-firehose"), + resource.TestCheckResourceAttr(dataSourceName, "log_delivery_configurations.0.log_format", "json"), + resource.TestCheckResourceAttr(dataSourceName, "log_delivery_configurations.0.log_type", "slow-log"), + ), + }, + }, + }) +} + func testAccAWSElastiCacheClusterConfigWithDataSource(rName string) string { return fmt.Sprintf(` resource "aws_elasticache_cluster" "test" { @@ -132,3 +155,70 @@ data "aws_elasticache_cluster" "test" { } `, rName, enableLogDelivery) } + +func testAccAWSElastiCacheCluster_Engine_Redis_LogDeliveryConfigurations_KinesisFirehose(rName string, enableLogDelivery bool) string { + return fmt.Sprintf(` +resource "aws_s3_bucket" "b" { + count = tobool("%[2]t") ? 1 : 0 + acl = "private" + force_destroy = true +} +resource "aws_iam_role" "r" { + count = tobool("%[2]t") ? 1 : 0 + managed_policy_arns = ["arn:aws:iam::aws:policy/AmazonS3FullAccess"] + assume_role_policy = jsonencode({ + Version = "2012-10-17" + Statement = [ + { + Action = "sts:AssumeRole" + Effect = "Allow" + Sid = "" + Principal = { + Service = "firehose.amazonaws.com" + } + }, + ] + }) +} +resource "aws_kinesis_firehose_delivery_stream" "ds" { + count = tobool("%[2]t") ? 1 : 0 + name = "%[1]s" + destination = "s3" + s3_configuration { + role_arn = aws_iam_role.r[0].arn + bucket_arn = aws_s3_bucket.b[0].arn + } + lifecycle { + ignore_changes = [ + tags["LogDeliveryEnabled"], + ] + } +} +resource "aws_elasticache_cluster" "test" { + cluster_id = "%[1]s" + engine = "redis" + node_type = "cache.t3.micro" + num_cache_nodes = 1 + port = 6379 + apply_immediately = true + + dynamic "log_delivery_configurations" { + for_each = tobool("%[2]t") ? [""] : [] + content { + destination_details { + kinesis_firehose { + delivery_stream = aws_kinesis_firehose_delivery_stream.ds[0].name + } + } + destination_type = "kinesis-firehose" + log_format = "json" + log_type = "slow-log" + } + } +} + +data "aws_elasticache_cluster" "test" { + cluster_id = aws_elasticache_cluster.test.cluster_id +} +`, rName, enableLogDelivery) +}