aws-cdk-constructs 2.48.0__tar.gz → 2.49.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (87) hide show
  1. {aws_cdk_constructs-2.48.0/aws_cdk_constructs.egg-info → aws_cdk_constructs-2.49.0}/PKG-INFO +1 -1
  2. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/__init__.py +1 -1
  3. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/ecs/cluster.py +12 -1
  4. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/ecs/microservice.py +16 -0
  5. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/efs/volume.py +14 -1
  6. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0/aws_cdk_constructs.egg-info}/PKG-INFO +1 -1
  7. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_ecs_cluster.py +43 -0
  8. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_ecs_microservice.py +67 -0
  9. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_efs_volume.py +99 -17
  10. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/LICENSE.txt +0 -0
  11. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/MANIFEST.in +0 -0
  12. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/README.md +0 -0
  13. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/api/__init__.py +0 -0
  14. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/api/api.py +0 -0
  15. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/__init__.py +0 -0
  16. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/auth_flow.py +0 -0
  17. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/base_edge_constructs.py +0 -0
  18. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/bucket.py +0 -0
  19. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/configuration.py +0 -0
  20. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/edge_function.py +0 -0
  21. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/edge_role.py +0 -0
  22. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/log_level.py +0 -0
  23. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/secret_generator.py +0 -0
  24. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/bucket/with_configuration.py +0 -0
  25. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/database/__init__.py +0 -0
  26. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/database/_types/__init__.py +0 -0
  27. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/database/_types/document.py +0 -0
  28. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/database/_types/graph.py +0 -0
  29. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/database/_types/relational.py +0 -0
  30. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/database/database.py +0 -0
  31. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/database/types.py +0 -0
  32. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/ecs/__init__.py +0 -0
  33. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/ecs/fargate_validator.py +0 -0
  34. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/efs/__init__.py +0 -0
  35. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/add-index/index.js +0 -0
  36. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/add-index/index.js.map +0 -0
  37. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/check-auth/index.js +0 -0
  38. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/check-auth/index.js.LICENSE.txt +0 -0
  39. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/check-auth/index.js.map +0 -0
  40. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/parse-auth/index.js +0 -0
  41. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/parse-auth/index.js.LICENSE.txt +0 -0
  42. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/parse-auth/index.js.map +0 -0
  43. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/refresh-auth/index.js +0 -0
  44. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/refresh-auth/index.js.LICENSE.txt +0 -0
  45. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/refresh-auth/index.js.map +0 -0
  46. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/secret-generator/index.js +0 -0
  47. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/secret-generator/index.js.map +0 -0
  48. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/sign-out/index.js +0 -0
  49. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/sign-out/index.js.LICENSE.txt +0 -0
  50. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/sign-out/index.js.map +0 -0
  51. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/with_configuration/index.js +0 -0
  52. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/with_configuration/index.js.LICENSE.txt +0 -0
  53. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/lambdas/with_configuration/index.js.map +0 -0
  54. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/load_balancer/__init__.py +0 -0
  55. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/load_balancer/alb.py +0 -0
  56. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/load_balancer/nlb.py +0 -0
  57. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/microservice/__init__.py +0 -0
  58. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/microservice/base_user_data.sh +0 -0
  59. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/microservice/manage_connection_to_nlb_instance_security_group_ingress/lambda_function.js +0 -0
  60. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/microservice/microservice.py +0 -0
  61. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/security_group/__init__.py +0 -0
  62. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/security_group/security_group.py +0 -0
  63. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/service_user_for_iac/__init__.py +0 -0
  64. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/service_user_for_iac/service_user_for_iac.py +0 -0
  65. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/service_user_for_static_assets/__init__.py +0 -0
  66. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/service_user_for_static_assets/service_user_for_static_assets.py +0 -0
  67. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/utils.py +0 -0
  68. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/windows_server/__init__.py +0 -0
  69. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/windows_server/user_data.ps1 +0 -0
  70. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs/windows_server/windows_server.py +0 -0
  71. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs.egg-info/SOURCES.txt +0 -0
  72. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs.egg-info/dependency_links.txt +0 -0
  73. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs.egg-info/requires.txt +0 -0
  74. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/aws_cdk_constructs.egg-info/top_level.txt +0 -0
  75. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/setup.cfg +0 -0
  76. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/setup.py +0 -0
  77. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_alb.py +0 -0
  78. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_bucket.py +0 -0
  79. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_database.py +0 -0
  80. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_fargate_validator.py +0 -0
  81. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_microservice.py +0 -0
  82. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_nlb.py +0 -0
  83. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_security_group.py +0 -0
  84. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_service_user_for_iac.py +0 -0
  85. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_service_user_for_static_assets.py +0 -0
  86. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_utils.py +0 -0
  87. {aws_cdk_constructs-2.48.0 → aws_cdk_constructs-2.49.0}/tests/test_windows_server.py +0 -0
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aws_cdk_constructs
3
- Version: 2.48.0
3
+ Version: 2.49.0
4
4
  Summary: AWS CDK constructs
5
5
  Home-page: https://bitbucket.org/cioapps/aws-cdk-constructs
6
6
  Author: author
@@ -15,4 +15,4 @@ from .load_balancer import Alb, Nlb
15
15
  from .security_group import SecurityGroup
16
16
  from .windows_server import WindowsServer
17
17
 
18
- __version__ = '2.48.0'
18
+ __version__ = '2.49.0'
@@ -87,6 +87,8 @@ class ECSCluster(Construct):
87
87
  ec2_send_emails (Optional - bool): When set to true, attaches the SMTP relay security group (defined by ``smtp_relay_security_group`` in the environment account parameters) to the EC2 launch template, allowing instances to send emails through the relay. Default is false.
88
88
 
89
89
  will_drop_invalid_headers (Optional | str): Indicates whether HTTP headers with invalid header fields are removed by the load balancer ('true') or routed to targets ('false'). Default: false
90
+
91
+ container_insights (Optional | str): Whether to enable Container Insights for the cluster. This can be 'DISABLED', 'ENABLED' or 'ENHANCED'. Default: ENABLED
90
92
  """
91
93
 
92
94
  def __init__(
@@ -115,6 +117,7 @@ class ECSCluster(Construct):
115
117
  ec2_tag_scheduler_uptime_days: Optional[str] = '1-2-3-4-5',
116
118
  ec2_tag_scheduler_skip: Optional[str] = 'False',
117
119
  will_drop_invalid_headers: str = 'False',
120
+ container_insights: Optional[str] = 'ENABLED',
118
121
  ) -> None:
119
122
  self.id = id
120
123
  self.scope = scope
@@ -145,6 +148,7 @@ class ECSCluster(Construct):
145
148
  self.ec2_instance_type = (ec2_instance_type,)
146
149
  self.ec2_max_capacity = (ec2_max_capacity,)
147
150
  self.ec2_desired_capacity = ec2_desired_capacity
151
+ self.container_insights = container_insights
148
152
 
149
153
  super().__init__(scope, id)
150
154
 
@@ -351,11 +355,18 @@ class ECSCluster(Construct):
351
355
  )
352
356
 
353
357
  def _create_cluster(self) -> None:
358
+ if self.container_insights == 'ENHANCED':
359
+ self.config_insights = _ecs.ContainerInsights.ENHANCED
360
+ elif self.container_insights == 'DISABLED':
361
+ self.config_insights = _ecs.ContainerInsights.DISABLED
362
+ else:
363
+ self.config_insights = _ecs.ContainerInsights.ENABLED
364
+
354
365
  self.cluster = _ecs.Cluster(
355
366
  scope=self.scope,
356
367
  id=self.id + '_ecs',
357
368
  vpc=self.vpc,
358
- container_insights=True,
369
+ container_insights_v2=self.config_insights,
359
370
  )
360
371
 
361
372
  def register_ms(self, microservice: ECSMicroservice) -> None:
@@ -3,6 +3,7 @@ from __future__ import annotations
3
3
  import os
4
4
  from typing import Optional, List, Dict, TYPE_CHECKING
5
5
 
6
+ import aws_cdk as cdk
6
7
  from aws_cdk import (
7
8
  Tags,
8
9
  Duration,
@@ -17,6 +18,10 @@ from aws_cdk import (
17
18
  aws_cloudwatch as _cloudwatch,
18
19
  )
19
20
  from constructs import Construct
21
+ from aws_cdk_constructs.utils import (
22
+ normalize_environment_parameter,
23
+ get_version,
24
+ )
20
25
 
21
26
  from aws_cdk_constructs.ecs.fargate_validator import FargateValidator
22
27
  from aws_cdk_constructs.efs.volume import EFSVolume
@@ -212,6 +217,17 @@ class ECSMicroservice(Construct):
212
217
  self.main_container = self._create_main_container()
213
218
  self.service = self._create_service()
214
219
 
220
+ # Apply mandatory tags
221
+ tag_environment = normalize_environment_parameter(self.environment)
222
+ tag_app_name = self.cluster.app_name.lower().strip()
223
+
224
+ for entity in [self.task, self.service]:
225
+ Tags.of(entity).add('ApplicationName', tag_app_name)
226
+ Tags.of(entity).add('Environment', tag_environment)
227
+ Tags.of(entity).add('fao-cdk-version', get_version())
228
+ Tags.of(entity).add('fao-cdk', 'true')
229
+ Tags.of(entity).add('fao-cdk-construct', 'ecs_microservice')
230
+
215
231
  # It will attach services to the LB listener and route them by hostname
216
232
  if self.cluster.alb is not None and internal is False:
217
233
  lb_target_priority = self.cluster.alb.get_safe_rule_priority()
@@ -11,7 +11,10 @@ from aws_cdk import (
11
11
  RemovalPolicy,
12
12
  Tags,
13
13
  )
14
-
14
+ from aws_cdk_constructs.utils import (
15
+ normalize_environment_parameter,
16
+ get_version,
17
+ )
15
18
  from constructs import Construct
16
19
 
17
20
 
@@ -96,6 +99,16 @@ class EFSVolume(Construct):
96
99
  removal_policy=efs_removal_policy,
97
100
  )
98
101
 
102
+ # Apply mandatory tags
103
+ tag_environment = normalize_environment_parameter(self._environment)
104
+ tag_app_name = self.app_name.lower().strip()
105
+
106
+ Tags.of(self.efs).add('ApplicationName', tag_app_name)
107
+ Tags.of(self.efs).add('Environment', tag_environment)
108
+ Tags.of(self.efs).add('fao-cdk-version', get_version())
109
+ Tags.of(self.efs).add('fao-cdk', 'true')
110
+ Tags.of(self.efs).add('fao-cdk-construct', 'efs_volume')
111
+
99
112
  self._efs_security_group = self.efs.node.find_child('EfsSecurityGroup')
100
113
 
101
114
  if to_be_backed_up:
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.4
2
2
  Name: aws_cdk_constructs
3
- Version: 2.48.0
3
+ Version: 2.49.0
4
4
  Summary: AWS CDK constructs
5
5
  Home-page: https://bitbucket.org/cioapps/aws-cdk-constructs
6
6
  Author: author
@@ -805,3 +805,46 @@ def test_ecs_with_ec2_creates_asg(
805
805
  ],
806
806
  },
807
807
  )
808
+
809
+
810
+ @pytest.mark.parametrize(
811
+ 'insights_input, expected_value',
812
+ [
813
+ ('ENABLED', 'enabled'),
814
+ ('ENHANCED', 'enhanced'),
815
+ ('DISABLED', 'disabled'),
816
+ ],
817
+ )
818
+ def test_ecs_cluster_container_insights_configuration(
819
+ stack,
820
+ vpc,
821
+ hosted_zone,
822
+ environment_parameters,
823
+ mocker,
824
+ insights_input,
825
+ expected_value,
826
+ ):
827
+ mocker.patch('aws_cdk.aws_ec2.Vpc.from_lookup', return_value=vpc)
828
+
829
+ ECSCluster(
830
+ scope=stack,
831
+ id='x',
832
+ environment='development',
833
+ environments_parameters=environment_parameters,
834
+ app_name='testapp',
835
+ hosted_zone=hosted_zone,
836
+ container_insights=insights_input,
837
+ )
838
+ template = Template.from_stack(stack)
839
+
840
+ template.has_resource_properties(
841
+ 'AWS::ECS::Cluster',
842
+ {
843
+ 'ClusterSettings': [
844
+ {
845
+ 'Name': 'containerInsights',
846
+ 'Value': expected_value,
847
+ }
848
+ ]
849
+ },
850
+ )
@@ -5,6 +5,7 @@ from aws_cdk.assertions import Template, Match
5
5
  from aws_cdk_constructs.ecs.cluster import ECSCluster
6
6
  from aws_cdk_constructs.ecs.microservice import ECSMicroservice
7
7
  from aws_cdk_constructs.efs.volume import EFSVolume
8
+ from aws_cdk_constructs.utils import get_version
8
9
 
9
10
 
10
11
  @pytest.fixture
@@ -548,6 +549,72 @@ def test_service_has_custom_scheduling_tags(stack, cluster):
548
549
  )
549
550
 
550
551
 
552
+ MANDATORY_TAGS = [
553
+ {'Key': 'ApplicationName', 'Value': 'test-app'},
554
+ {'Key': 'Environment', 'Value': 'Development'},
555
+ {'Key': 'fao-cdk', 'Value': 'true'},
556
+ {'Key': 'fao-cdk-construct', 'Value': 'ecs_microservice'},
557
+ {'Key': 'fao-cdk-version', 'Value': get_version()},
558
+ ]
559
+
560
+
561
+ def test_task_definition_has_mandatory_tags(stack, ms, template):
562
+ template.has_resource_properties(
563
+ 'AWS::ECS::TaskDefinition',
564
+ {'Tags': Match.array_with(MANDATORY_TAGS)},
565
+ )
566
+
567
+
568
+ def test_service_has_mandatory_tags(stack, ms, template):
569
+ template.has_resource_properties(
570
+ 'AWS::ECS::Service',
571
+ {'Tags': Match.array_with(MANDATORY_TAGS)},
572
+ )
573
+
574
+
575
+ def test_mandatory_tags_normalize_environment(stack, cluster):
576
+ cluster.environment = 'production'
577
+ ECSMicroservice(
578
+ scope=stack, name='test-ms', image='repository/image', cluster=cluster
579
+ )
580
+ template = Template.from_stack(stack)
581
+ for resource_type in ['AWS::ECS::Service', 'AWS::ECS::TaskDefinition']:
582
+ template.has_resource_properties(
583
+ resource_type,
584
+ {
585
+ 'Tags': Match.array_with(
586
+ [{'Key': 'Environment', 'Value': 'Production'}]
587
+ )
588
+ },
589
+ )
590
+
591
+
592
+ def test_mandatory_tags_normalize_app_name(
593
+ stack, vpc, environment_parameters, mocker
594
+ ):
595
+ mocker.patch('aws_cdk.aws_ec2.Vpc.from_lookup', return_value=vpc)
596
+ cluster = ECSCluster(
597
+ scope=stack,
598
+ id='x',
599
+ environments_parameters=environment_parameters,
600
+ environment='development',
601
+ app_name='Test-App',
602
+ )
603
+ ECSMicroservice(
604
+ scope=stack, name='test-ms', image='repository/image', cluster=cluster
605
+ )
606
+ template = Template.from_stack(stack)
607
+ for resource_type in ['AWS::ECS::Service', 'AWS::ECS::TaskDefinition']:
608
+ template.has_resource_properties(
609
+ resource_type,
610
+ {
611
+ 'Tags': Match.array_with(
612
+ [{'Key': 'ApplicationName', 'Value': 'test-app'}]
613
+ )
614
+ },
615
+ )
616
+
617
+
551
618
  def test_service_includes_all_alternative_fqdns(
552
619
  stack, vpc, environment_parameters, mocker
553
620
  ):
@@ -1,8 +1,9 @@
1
1
  import aws_cdk as cdk
2
2
  import pytest
3
- from aws_cdk.assertions import Template
3
+ from aws_cdk.assertions import Template, Match
4
4
 
5
5
  from aws_cdk_constructs.efs.volume import EFSVolume
6
+ from aws_cdk_constructs.utils import get_version
6
7
 
7
8
 
8
9
  @pytest.fixture
@@ -53,15 +54,90 @@ def test_created_volume_template(stack, vpc, environment_parameters):
53
54
  template.has_resource_properties(
54
55
  'AWS::EFS::FileSystem',
55
56
  {
56
- 'FileSystemTags': [
57
- {'Key': 'HasBackup', 'Value': 'false'},
58
- {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
59
- ]
57
+ 'FileSystemTags': Match.array_with(
58
+ [
59
+ {'Key': 'HasBackup', 'Value': 'false'},
60
+ {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
61
+ ]
62
+ )
60
63
  },
61
64
  )
62
65
  template.resource_count_is('AWS::EFS::MountTarget', 2)
63
66
 
64
67
 
68
+ MANDATORY_TAGS = [
69
+ {'Key': 'ApplicationName', 'Value': 'test-app'},
70
+ {'Key': 'Environment', 'Value': 'Development'},
71
+ {'Key': 'fao-cdk', 'Value': 'true'},
72
+ {'Key': 'fao-cdk-construct', 'Value': 'efs_volume'},
73
+ {'Key': 'fao-cdk-version', 'Value': get_version()},
74
+ ]
75
+
76
+
77
+ def test_volume_has_mandatory_tags(stack, vpc, environment_parameters):
78
+ EFSVolume(
79
+ scope=stack,
80
+ id='volume-id',
81
+ environment='development',
82
+ environments_parameters=environment_parameters,
83
+ vpc=vpc,
84
+ volume_mount_path='/opt/mount',
85
+ app_name='test-app',
86
+ )
87
+
88
+ template = Template.from_stack(stack)
89
+ template.has_resource_properties(
90
+ 'AWS::EFS::FileSystem',
91
+ {'FileSystemTags': Match.array_with(MANDATORY_TAGS)},
92
+ )
93
+
94
+
95
+ def test_mandatory_tags_normalize_environment(
96
+ stack, vpc, environment_parameters
97
+ ):
98
+ EFSVolume(
99
+ scope=stack,
100
+ id='volume-id',
101
+ environment='production',
102
+ environments_parameters=environment_parameters,
103
+ vpc=vpc,
104
+ volume_mount_path='/opt/mount',
105
+ app_name='test-app',
106
+ )
107
+
108
+ template = Template.from_stack(stack)
109
+ template.has_resource_properties(
110
+ 'AWS::EFS::FileSystem',
111
+ {
112
+ 'FileSystemTags': Match.array_with(
113
+ [{'Key': 'Environment', 'Value': 'Production'}]
114
+ )
115
+ },
116
+ )
117
+
118
+
119
+ def test_mandatory_tags_normalize_app_name(stack, vpc, environment_parameters):
120
+ EFSVolume(
121
+ scope=stack,
122
+ id='volume-id',
123
+ environment='development',
124
+ environments_parameters=environment_parameters,
125
+ vpc=vpc,
126
+ volume_mount_path='/opt/mount',
127
+ app_name='Test-App',
128
+ )
129
+
130
+ template = Template.from_stack(stack)
131
+ template.has_resource_properties(
132
+ 'AWS::EFS::FileSystem',
133
+ {
134
+ 'FileSystemTags': Match.array_with(
135
+ [{'Key': 'ApplicationName', 'Value': 'test-app'}]
136
+ )
137
+ },
138
+ )
139
+
140
+
65
141
  def test_grant_access_to_volume(stack, vpc, environment_parameters):
66
142
  volume = EFSVolume(
67
143
  scope=stack,
@@ -116,10 +192,12 @@ def test_development_policy_and_backup(stack, vpc, environment_parameters):
116
192
  template.has_resource_properties(
117
193
  'AWS::EFS::FileSystem',
118
194
  {
119
- 'FileSystemTags': [
120
- {'Key': 'HasBackup', 'Value': 'false'},
121
- {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
122
- ]
195
+ 'FileSystemTags': Match.array_with(
196
+ [
197
+ {'Key': 'HasBackup', 'Value': 'false'},
198
+ {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
199
+ ]
200
+ )
123
201
  },
124
202
  )
125
203
  template.has_resource('AWS::EFS::FileSystem', {'DeletionPolicy': 'Delete'})
@@ -160,10 +238,12 @@ def test_production_default_enabled_backup(stack, vpc, environment_parameters):
160
238
  template.has_resource_properties(
161
239
  'AWS::EFS::FileSystem',
162
240
  {
163
- 'FileSystemTags': [
164
- {'Key': 'HasBackup', 'Value': 'true'},
165
- {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
166
- ]
241
+ 'FileSystemTags': Match.array_with(
242
+ [
243
+ {'Key': 'HasBackup', 'Value': 'true'},
244
+ {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
245
+ ]
246
+ )
167
247
  },
168
248
  )
169
249
 
@@ -183,9 +263,11 @@ def test_production_disabled_backup(stack, vpc, environment_parameters):
183
263
  template.has_resource_properties(
184
264
  'AWS::EFS::FileSystem',
185
265
  {
186
- 'FileSystemTags': [
187
- {'Key': 'HasBackup', 'Value': 'false'},
188
- {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
189
- ]
266
+ 'FileSystemTags': Match.array_with(
267
+ [
268
+ {'Key': 'HasBackup', 'Value': 'false'},
269
+ {'Key': 'Name', 'Value': 'test-stack/volume-id-efs'},
270
+ ]
271
+ )
190
272
  },
191
273
  )