Skip to content

Commit

Permalink
hashicorp#20068 logdeliveryconfigurations test: `data_source_aws_elas…
Browse files Browse the repository at this point in the history
…ticache_cluster` basic kinesis
  • Loading branch information
nickolivera committed Sep 23, 2021
1 parent 1377066 commit 88daa54
Showing 1 changed file with 90 additions and 0 deletions.
90 changes: 90 additions & 0 deletions aws/data_source_aws_elasticache_cluster_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -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" {
Expand Down Expand Up @@ -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)
}

0 comments on commit 88daa54

Please sign in to comment.