Skip to content

Commit e7acd39

Browse files
committed
Add an acceptance test for enable_monitoring_dashboard
1 parent d15077b commit e7acd39

File tree

1 file changed

+144
-0
lines changed

1 file changed

+144
-0
lines changed

internal/service/networkfirewall/logging_configuration_test.go

Lines changed: 144 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@ func TestAccNetworkFirewallLoggingConfiguration_CloudWatchLogDestination_logGrou
3636
Config: testAccLoggingConfigurationConfig_cloudWatch(logGroupName, rName, string(awstypes.LogDestinationTypeCloudwatchLogs), string(awstypes.LogTypeFlow)),
3737
Check: resource.ComposeTestCheckFunc(
3838
testAccCheckLoggingConfigurationExists(ctx, resourceName),
39+
resource.TestCheckResourceAttr(resourceName, "enable_monitoring_dashboard", acctest.CtFalse),
3940
resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"),
4041
resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "1"),
4142
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
@@ -49,6 +50,7 @@ func TestAccNetworkFirewallLoggingConfiguration_CloudWatchLogDestination_logGrou
4950
Config: testAccLoggingConfigurationConfig_cloudWatch(updatedLogGroupName, rName, string(awstypes.LogDestinationTypeCloudwatchLogs), string(awstypes.LogTypeFlow)),
5051
Check: resource.ComposeTestCheckFunc(
5152
testAccCheckLoggingConfigurationExists(ctx, resourceName),
53+
resource.TestCheckResourceAttr(resourceName, "enable_monitoring_dashboard", acctest.CtFalse),
5254
resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"),
5355
resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "1"),
5456
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
@@ -62,6 +64,7 @@ func TestAccNetworkFirewallLoggingConfiguration_CloudWatchLogDestination_logGrou
6264
Config: testAccLoggingConfigurationConfig_cloudWatch(updatedLogGroupName, rName, string(awstypes.LogDestinationTypeCloudwatchLogs), string(awstypes.LogTypeTls)),
6365
Check: resource.ComposeTestCheckFunc(
6466
testAccCheckLoggingConfigurationExists(ctx, resourceName),
67+
resource.TestCheckResourceAttr(resourceName, "enable_monitoring_dashboard", acctest.CtFalse),
6568
resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"),
6669
resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "1"),
6770
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
@@ -742,6 +745,115 @@ func TestAccNetworkFirewallLoggingConfiguration_updateToSingleTLSTypeLogDestinat
742745
})
743746
}
744747

748+
func TestAccNetworkFirewallLoggingConfiguration_enableMonitoringDashboard(t *testing.T) {
749+
ctx := acctest.Context(t)
750+
bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
751+
logGroupName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
752+
rName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
753+
resourceName := "aws_networkfirewall_logging_configuration.test"
754+
755+
resource.ParallelTest(t, resource.TestCase{
756+
PreCheck: func() { acctest.PreCheck(ctx, t); testAccPreCheck(ctx, t) },
757+
ErrorCheck: acctest.ErrorCheck(t, names.NetworkFirewallServiceID),
758+
ProtoV5ProviderFactories: acctest.ProtoV5ProviderFactories,
759+
CheckDestroy: testAccCheckLoggingConfigurationDestroy(ctx),
760+
Steps: []resource.TestStep{
761+
{
762+
Config: testAccLoggingConfigurationConfig_s3AndCloudWatchEnableMonitoringDashboard(bucketName, logGroupName, rName, string(awstypes.LogTypeAlert), string(awstypes.LogTypeFlow), true),
763+
Check: resource.ComposeTestCheckFunc(
764+
testAccCheckLoggingConfigurationExists(ctx, resourceName),
765+
resource.TestCheckResourceAttr(resourceName, "enable_monitoring_dashboard", acctest.CtTrue),
766+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"),
767+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "2"),
768+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
769+
"log_destination.%": "1",
770+
"log_destination.logGroup": logGroupName,
771+
"log_destination_type": string(awstypes.LogDestinationTypeCloudwatchLogs),
772+
"log_type": string(awstypes.LogTypeFlow),
773+
}),
774+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
775+
"log_destination.%": "1",
776+
"log_destination.bucketName": bucketName,
777+
"log_destination_type": string(awstypes.LogDestinationTypeS3),
778+
"log_type": string(awstypes.LogTypeAlert),
779+
}),
780+
),
781+
},
782+
{
783+
ResourceName: resourceName,
784+
ImportState: true,
785+
ImportStateVerify: true,
786+
},
787+
{
788+
// Disable Monitoring Dashboard
789+
Config: testAccLoggingConfigurationConfig_s3AndCloudWatchEnableMonitoringDashboard(bucketName, logGroupName, rName, string(awstypes.LogTypeAlert), string(awstypes.LogTypeFlow), false),
790+
Check: resource.ComposeTestCheckFunc(
791+
testAccCheckLoggingConfigurationExists(ctx, resourceName),
792+
resource.TestCheckResourceAttr(resourceName, "enable_monitoring_dashboard", acctest.CtFalse),
793+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"),
794+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "2"),
795+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
796+
"log_destination.%": "1",
797+
"log_destination.logGroup": logGroupName,
798+
"log_destination_type": string(awstypes.LogDestinationTypeCloudwatchLogs),
799+
"log_type": string(awstypes.LogTypeFlow),
800+
}),
801+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
802+
"log_destination.%": "1",
803+
"log_destination.bucketName": bucketName,
804+
"log_destination_type": string(awstypes.LogDestinationTypeS3),
805+
"log_type": string(awstypes.LogTypeAlert),
806+
}),
807+
),
808+
},
809+
{
810+
// Re-Enable Monitoring Dashboard and change log types at the same time
811+
Config: testAccLoggingConfigurationConfig_s3AndCloudWatchEnableMonitoringDashboard(bucketName, logGroupName, rName, string(awstypes.LogTypeTls), string(awstypes.LogTypeFlow), true),
812+
Check: resource.ComposeTestCheckFunc(
813+
testAccCheckLoggingConfigurationExists(ctx, resourceName),
814+
resource.TestCheckResourceAttr(resourceName, "enable_monitoring_dashboard", acctest.CtTrue),
815+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"),
816+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "2"),
817+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
818+
"log_destination.%": "1",
819+
"log_destination.logGroup": logGroupName,
820+
"log_destination_type": string(awstypes.LogDestinationTypeCloudwatchLogs),
821+
"log_type": string(awstypes.LogTypeFlow),
822+
}),
823+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
824+
"log_destination.%": "1",
825+
"log_destination.bucketName": bucketName,
826+
"log_destination_type": string(awstypes.LogDestinationTypeS3),
827+
"log_type": string(awstypes.LogTypeTls),
828+
}),
829+
),
830+
},
831+
{
832+
// Omit enable_monitoring_dashboard (inherit previous value)
833+
Config: testAccLoggingConfigurationConfig_s3AndCloudWatch(bucketName, logGroupName, rName, string(awstypes.LogTypeTls), string(awstypes.LogTypeFlow)),
834+
Check: resource.ComposeTestCheckFunc(
835+
testAccCheckLoggingConfigurationExists(ctx, resourceName),
836+
resource.TestCheckResourceAttr(resourceName, "enable_monitoring_dashboard", acctest.CtTrue),
837+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.#", "1"),
838+
resource.TestCheckResourceAttr(resourceName, "logging_configuration.0.log_destination_config.#", "2"),
839+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
840+
"log_destination.%": "1",
841+
"log_destination.logGroup": logGroupName,
842+
"log_destination_type": string(awstypes.LogDestinationTypeCloudwatchLogs),
843+
"log_type": string(awstypes.LogTypeFlow),
844+
}),
845+
resource.TestCheckTypeSetElemNestedAttrs(resourceName, "logging_configuration.0.log_destination_config.*", map[string]string{
846+
"log_destination.%": "1",
847+
"log_destination.bucketName": bucketName,
848+
"log_destination_type": string(awstypes.LogDestinationTypeS3),
849+
"log_type": string(awstypes.LogTypeTls),
850+
}),
851+
),
852+
},
853+
},
854+
})
855+
}
856+
745857
func TestAccNetworkFirewallLoggingConfiguration_disappears(t *testing.T) {
746858
ctx := acctest.Context(t)
747859
bucketName := sdkacctest.RandomWithPrefix(acctest.ResourcePrefix)
@@ -1151,3 +1263,35 @@ resource "aws_networkfirewall_logging_configuration" "test" {
11511263
}
11521264
`, logTypeS3, logTypeCloudWatch))
11531265
}
1266+
1267+
func testAccLoggingConfigurationConfig_s3AndCloudWatchEnableMonitoringDashboard(bucketName, logGroupName, rName, logTypeS3, logTypeCloudWatch string, enableMonitoringDashboard bool) string {
1268+
return acctest.ConfigCompose(
1269+
testAccLoggingConfigurationConfig_base(rName),
1270+
testAccLoggingConfigurationConfig_baseS3Bucket(bucketName),
1271+
testAccLoggingConfigurationConfig_baseCloudWatch(logGroupName),
1272+
fmt.Sprintf(`
1273+
resource "aws_networkfirewall_logging_configuration" "test" {
1274+
firewall_arn = aws_networkfirewall_firewall.test.arn
1275+
1276+
enable_monitoring_dashboard = %[3]t
1277+
1278+
logging_configuration {
1279+
log_destination_config {
1280+
log_destination = {
1281+
bucketName = aws_s3_bucket.test.bucket
1282+
}
1283+
log_destination_type = "S3"
1284+
log_type = %[1]q
1285+
}
1286+
1287+
log_destination_config {
1288+
log_destination = {
1289+
logGroup = aws_cloudwatch_log_group.test.name
1290+
}
1291+
log_destination_type = "CloudWatchLogs"
1292+
log_type = %[2]q
1293+
}
1294+
}
1295+
}
1296+
`, logTypeS3, logTypeCloudWatch, enableMonitoringDashboard))
1297+
}

0 commit comments

Comments
 (0)