|
14 | 14 | ref, |
15 | 15 | validate_intrinsic_if_items, |
16 | 16 | ) |
| 17 | +from samtranslator.model.tags.resource_tagging import get_tag_list |
17 | 18 | from samtranslator.model.update_policy import UpdatePolicy |
18 | 19 | from samtranslator.translator.arn_generator import ArnGenerator |
19 | 20 |
|
@@ -52,20 +53,29 @@ def __init__(self) -> None: |
52 | 53 | """ |
53 | 54 | self._resource_preferences: Dict[str, Any] = {} |
54 | 55 |
|
55 | | - def add(self, logical_id: str, deployment_preference_dict: Dict[str, Any], condition: Optional[str] = None) -> None: |
| 56 | + def add( |
| 57 | + self, |
| 58 | + logical_id: str, |
| 59 | + deployment_preference_dict: Dict[str, Any], |
| 60 | + condition: Optional[str] = None, |
| 61 | + tags: Optional[Dict[str, Any]] = None, |
| 62 | + propagate_tags: Optional[bool] = False, |
| 63 | + ) -> None: |
56 | 64 | """ |
57 | 65 | Add this deployment preference to the collection |
58 | 66 |
|
59 | 67 | :raise ValueError if an existing logical id already exists in the _resource_preferences |
60 | 68 | :param logical_id: logical id of the resource where this deployment preference applies |
61 | 69 | :param deployment_preference_dict: the input SAM template deployment preference mapping |
62 | 70 | :param condition: the condition (if it exists) on the serverless function |
| 71 | + :param tags: tags from the SAM resource to propagate to CodeDeploy resources |
| 72 | + :param propagate_tags: whether to propagate tags to CodeDeploy resources |
63 | 73 | """ |
64 | 74 | if logical_id in self._resource_preferences: |
65 | 75 | raise ValueError(f"logical_id {logical_id} previously added to this deployment_preference_collection") |
66 | 76 |
|
67 | 77 | self._resource_preferences[logical_id] = DeploymentPreference.from_dict( # type: ignore[no-untyped-call] |
68 | | - logical_id, deployment_preference_dict, condition |
| 78 | + logical_id, deployment_preference_dict, condition, tags, propagate_tags |
69 | 79 | ) |
70 | 80 |
|
71 | 81 | def get(self, logical_id: str) -> DeploymentPreference: |
@@ -127,6 +137,13 @@ def enabled_logical_ids(self) -> List[str]: |
127 | 137 | def get_codedeploy_application(self) -> CodeDeployApplication: |
128 | 138 | codedeploy_application_resource = CodeDeployApplication(CODEDEPLOY_APPLICATION_LOGICAL_ID) |
129 | 139 | codedeploy_application_resource.ComputePlatform = "Lambda" |
| 140 | + |
| 141 | + merged_tags: Dict[str, Any] = {} |
| 142 | + for preference in self._resource_preferences.values(): |
| 143 | + if preference.enabled and preference.propagate_tags and preference.tags: |
| 144 | + merged_tags.update(preference.tags) |
| 145 | + if merged_tags: |
| 146 | + codedeploy_application_resource.Tags = get_tag_list(merged_tags) |
130 | 147 | if self.needs_resource_condition(): |
131 | 148 | conditions = self.get_all_deployment_conditions() |
132 | 149 | condition_name = CODE_DEPLOY_CONDITION_NAME |
@@ -165,6 +182,14 @@ def get_codedeploy_iam_role(self) -> IAMRole: |
165 | 182 | if len(conditions) <= 1: |
166 | 183 | condition_name = conditions.pop() |
167 | 184 | iam_role.set_resource_attribute("Condition", condition_name) |
| 185 | + |
| 186 | + merged_tags: Dict[str, Any] = {} |
| 187 | + for preference in self._resource_preferences.values(): |
| 188 | + if preference.enabled and preference.propagate_tags and preference.tags: |
| 189 | + merged_tags.update(preference.tags) |
| 190 | + if merged_tags: |
| 191 | + iam_role.Tags = get_tag_list(merged_tags) |
| 192 | + |
168 | 193 | return iam_role |
169 | 194 |
|
170 | 195 | def deployment_group(self, function_logical_id: str) -> CodeDeployDeploymentGroup: |
@@ -201,6 +226,9 @@ def deployment_group(self, function_logical_id: str) -> CodeDeployDeploymentGrou |
201 | 226 | if deployment_preference.trigger_configurations: |
202 | 227 | deployment_group.TriggerConfigurations = deployment_preference.trigger_configurations |
203 | 228 |
|
| 229 | + if deployment_preference.tags: |
| 230 | + deployment_group.Tags = get_tag_list(deployment_preference.tags) |
| 231 | + |
204 | 232 | if deployment_preference.condition: |
205 | 233 | deployment_group.set_resource_attribute("Condition", deployment_preference.condition) |
206 | 234 |
|
|
0 commit comments