@@ -36,6 +36,7 @@ func TestAccNetworkFirewallLoggingConfiguration_CloudWatchLogDestination_logGrou
36
36
Config : testAccLoggingConfigurationConfig_cloudWatch (logGroupName , rName , string (awstypes .LogDestinationTypeCloudwatchLogs ), string (awstypes .LogTypeFlow )),
37
37
Check : resource .ComposeTestCheckFunc (
38
38
testAccCheckLoggingConfigurationExists (ctx , resourceName ),
39
+ resource .TestCheckResourceAttr (resourceName , "enable_monitoring_dashboard" , acctest .CtFalse ),
39
40
resource .TestCheckResourceAttr (resourceName , "logging_configuration.#" , "1" ),
40
41
resource .TestCheckResourceAttr (resourceName , "logging_configuration.0.log_destination_config.#" , "1" ),
41
42
resource .TestCheckTypeSetElemNestedAttrs (resourceName , "logging_configuration.0.log_destination_config.*" , map [string ]string {
@@ -49,6 +50,7 @@ func TestAccNetworkFirewallLoggingConfiguration_CloudWatchLogDestination_logGrou
49
50
Config : testAccLoggingConfigurationConfig_cloudWatch (updatedLogGroupName , rName , string (awstypes .LogDestinationTypeCloudwatchLogs ), string (awstypes .LogTypeFlow )),
50
51
Check : resource .ComposeTestCheckFunc (
51
52
testAccCheckLoggingConfigurationExists (ctx , resourceName ),
53
+ resource .TestCheckResourceAttr (resourceName , "enable_monitoring_dashboard" , acctest .CtFalse ),
52
54
resource .TestCheckResourceAttr (resourceName , "logging_configuration.#" , "1" ),
53
55
resource .TestCheckResourceAttr (resourceName , "logging_configuration.0.log_destination_config.#" , "1" ),
54
56
resource .TestCheckTypeSetElemNestedAttrs (resourceName , "logging_configuration.0.log_destination_config.*" , map [string ]string {
@@ -62,6 +64,7 @@ func TestAccNetworkFirewallLoggingConfiguration_CloudWatchLogDestination_logGrou
62
64
Config : testAccLoggingConfigurationConfig_cloudWatch (updatedLogGroupName , rName , string (awstypes .LogDestinationTypeCloudwatchLogs ), string (awstypes .LogTypeTls )),
63
65
Check : resource .ComposeTestCheckFunc (
64
66
testAccCheckLoggingConfigurationExists (ctx , resourceName ),
67
+ resource .TestCheckResourceAttr (resourceName , "enable_monitoring_dashboard" , acctest .CtFalse ),
65
68
resource .TestCheckResourceAttr (resourceName , "logging_configuration.#" , "1" ),
66
69
resource .TestCheckResourceAttr (resourceName , "logging_configuration.0.log_destination_config.#" , "1" ),
67
70
resource .TestCheckTypeSetElemNestedAttrs (resourceName , "logging_configuration.0.log_destination_config.*" , map [string ]string {
@@ -742,6 +745,115 @@ func TestAccNetworkFirewallLoggingConfiguration_updateToSingleTLSTypeLogDestinat
742
745
})
743
746
}
744
747
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
+
745
857
func TestAccNetworkFirewallLoggingConfiguration_disappears (t * testing.T ) {
746
858
ctx := acctest .Context (t )
747
859
bucketName := sdkacctest .RandomWithPrefix (acctest .ResourcePrefix )
@@ -1151,3 +1263,35 @@ resource "aws_networkfirewall_logging_configuration" "test" {
1151
1263
}
1152
1264
` , logTypeS3 , logTypeCloudWatch ))
1153
1265
}
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