Skip to content

Commit 0743c69

Browse files
authored
Merge branch 'develop' into feat/invoke-mode
2 parents 0f7a0b5 + 4ba545f commit 0743c69

20 files changed

+5250
-690
lines changed

integration/resources/templates/combination/function_lmi_custom.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -64,7 +64,6 @@ Resources:
6464
MyCapacityProvider:
6565
Type: AWS::Serverless::CapacityProvider
6666
Properties:
67-
CapacityProviderName: !Sub "${AWS::StackName}-cp"
6867
VpcConfig:
6968
SubnetIds:
7069
- !Ref SubnetId

integration/resources/templates/combination/function_lmi_default.yaml

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,6 @@ Resources:
2828
AdvancedCapacityProvider:
2929
Type: AWS::Serverless::CapacityProvider
3030
Properties:
31-
CapacityProviderName: !Sub "${AWS::StackName}-cp"
3231
VpcConfig:
3332
SubnetIds:
3433
- !Ref SubnetId

integration/resources/templates/combination/function_with_mq.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ Resources:
6060
- IpProtocol: tcp
6161
FromPort: 8162
6262
ToPort: 8162
63-
CidrIp: 0.0.0.0/0
63+
CidrIp: 10.0.0.0/16
6464
- IpProtocol: tcp
6565
FromPort: 61617
6666
ToPort: 61617
67-
CidrIp: 0.0.0.0/0
67+
CidrIp: 10.0.0.0/16
6868
- IpProtocol: tcp
6969
FromPort: 5671
7070
ToPort: 5671
71-
CidrIp: 0.0.0.0/0
71+
CidrIp: 10.0.0.0/16
7272
- IpProtocol: tcp
7373
FromPort: 61614
7474
ToPort: 61614
75-
CidrIp: 0.0.0.0/0
75+
CidrIp: 10.0.0.0/16
7676
- IpProtocol: tcp
7777
FromPort: 8883
7878
ToPort: 8883
79-
CidrIp: 0.0.0.0/0
79+
CidrIp: 10.0.0.0/16
8080

8181
MyLambdaExecutionRole:
8282
Type: AWS::IAM::Role

integration/resources/templates/combination/function_with_mq_using_autogen_role.yaml

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,23 +60,23 @@ Resources:
6060
- IpProtocol: tcp
6161
FromPort: 8162
6262
ToPort: 8162
63-
CidrIp: 0.0.0.0/0
63+
CidrIp: 10.0.0.0/16
6464
- IpProtocol: tcp
6565
FromPort: 61617
6666
ToPort: 61617
67-
CidrIp: 0.0.0.0/0
67+
CidrIp: 10.0.0.0/16
6868
- IpProtocol: tcp
6969
FromPort: 5671
7070
ToPort: 5671
71-
CidrIp: 0.0.0.0/0
71+
CidrIp: 10.0.0.0/16
7272
- IpProtocol: tcp
7373
FromPort: 61614
7474
ToPort: 61614
75-
CidrIp: 0.0.0.0/0
75+
CidrIp: 10.0.0.0/16
7676
- IpProtocol: tcp
7777
FromPort: 8883
7878
ToPort: 8883
79-
CidrIp: 0.0.0.0/0
79+
CidrIp: 10.0.0.0/16
8080

8181
MyMqBroker:
8282
Properties:

samtranslator/model/preferences/deployment_preference.py

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,8 @@
2222
:param enabled: Whether this deployment preference is enabled (true by default)
2323
:param trigger_configurations: Information about triggers associated with the deployment group. Duplicates are
2424
not allowed.
25+
:param tags: Tags to propagate to CodeDeploy resources when propagate_tags is enabled
26+
:param propagate_tags: Whether to propagate tags to CodeDeploy resources
2527
"""
2628
DeploymentPreferenceTuple = namedtuple(
2729
"DeploymentPreferenceTuple",
@@ -34,6 +36,8 @@
3436
"role",
3537
"trigger_configurations",
3638
"condition",
39+
"tags",
40+
"propagate_tags",
3741
],
3842
)
3943

@@ -46,18 +50,20 @@ class DeploymentPreference(DeploymentPreferenceTuple):
4650
"""
4751

4852
@classmethod
49-
def from_dict(cls, logical_id, deployment_preference_dict, condition=None): # type: ignore[no-untyped-def]
53+
def from_dict(cls, logical_id, deployment_preference_dict, condition=None, tags=None, propagate_tags=False): # type: ignore[no-untyped-def]
5054
"""
5155
:param logical_id: the logical_id of the resource that owns this deployment preference
5256
:param deployment_preference_dict: the dict object taken from the SAM template
5357
:param condition: condition on this deployment preference
58+
:param tags: tags from the SAM resource to propagate to CodeDeploy resources
59+
:param propagate_tags: whether to propagate tags to CodeDeploy resources
5460
:return:
5561
"""
5662
enabled = deployment_preference_dict.get("Enabled", True)
5763
enabled = False if enabled in ["false", "False"] else enabled
5864

5965
if not enabled:
60-
return DeploymentPreference(None, None, None, None, False, None, None, None)
66+
return DeploymentPreference(None, None, None, None, False, None, None, None, None, None)
6167

6268
if "Type" not in deployment_preference_dict:
6369
raise InvalidResourceException(logical_id, "'DeploymentPreference' is missing required Property 'Type'")
@@ -85,4 +91,6 @@ def from_dict(cls, logical_id, deployment_preference_dict, condition=None): # t
8591
role,
8692
trigger_configurations,
8793
condition if passthrough_condition else None,
94+
tags if propagate_tags and tags else None,
95+
propagate_tags,
8896
)

samtranslator/model/preferences/deployment_preference_collection.py

Lines changed: 30 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
ref,
1515
validate_intrinsic_if_items,
1616
)
17+
from samtranslator.model.tags.resource_tagging import get_tag_list
1718
from samtranslator.model.update_policy import UpdatePolicy
1819
from samtranslator.translator.arn_generator import ArnGenerator
1920

@@ -52,20 +53,29 @@ def __init__(self) -> None:
5253
"""
5354
self._resource_preferences: Dict[str, Any] = {}
5455

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:
5664
"""
5765
Add this deployment preference to the collection
5866
5967
:raise ValueError if an existing logical id already exists in the _resource_preferences
6068
:param logical_id: logical id of the resource where this deployment preference applies
6169
:param deployment_preference_dict: the input SAM template deployment preference mapping
6270
: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
6373
"""
6474
if logical_id in self._resource_preferences:
6575
raise ValueError(f"logical_id {logical_id} previously added to this deployment_preference_collection")
6676

6777
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
6979
)
7080

7181
def get(self, logical_id: str) -> DeploymentPreference:
@@ -127,6 +137,13 @@ def enabled_logical_ids(self) -> List[str]:
127137
def get_codedeploy_application(self) -> CodeDeployApplication:
128138
codedeploy_application_resource = CodeDeployApplication(CODEDEPLOY_APPLICATION_LOGICAL_ID)
129139
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)
130147
if self.needs_resource_condition():
131148
conditions = self.get_all_deployment_conditions()
132149
condition_name = CODE_DEPLOY_CONDITION_NAME
@@ -165,6 +182,14 @@ def get_codedeploy_iam_role(self) -> IAMRole:
165182
if len(conditions) <= 1:
166183
condition_name = conditions.pop()
167184
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+
168193
return iam_role
169194

170195
def deployment_group(self, function_logical_id: str) -> CodeDeployDeploymentGroup:
@@ -201,6 +226,9 @@ def deployment_group(self, function_logical_id: str) -> CodeDeployDeploymentGrou
201226
if deployment_preference.trigger_configurations:
202227
deployment_group.TriggerConfigurations = deployment_preference.trigger_configurations
203228

229+
if deployment_preference.tags:
230+
deployment_group.Tags = get_tag_list(deployment_preference.tags)
231+
204232
if deployment_preference.condition:
205233
deployment_group.set_resource_attribute("Condition", deployment_preference.condition)
206234

samtranslator/model/sam_resources.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
"""SAM macro definitions"""
1+
"""SAM macro definitions"""
22

33
import copy
44
import re
@@ -1308,6 +1308,8 @@ def _validate_deployment_preference_and_add_update_policy( # noqa: PLR0913
13081308
self.logical_id,
13091309
self.DeploymentPreference,
13101310
passthrough_resource_attributes.get("Condition"),
1311+
self.Tags,
1312+
self.PropagateTags,
13111313
)
13121314

13131315
if deployment_preference_collection.get(self.logical_id).enabled:

0 commit comments

Comments
 (0)