Skip to content
This repository was archived by the owner on Oct 23, 2025. It is now read-only.

Commit eb0ef3d

Browse files
authored
Merge pull request #411 from adyach/master
bugfix: added posibility to set vpc id for elbv2
2 parents b1699e7 + 5a73fb8 commit eb0ef3d

File tree

2 files changed

+24
-1
lines changed

2 files changed

+24
-1
lines changed

senza/components/elastic_load_balancer_v2.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,8 @@ def component_elastic_load_balancer_v2(definition,
9696
else:
9797
loadbalancer_subnet_map = "LoadBalancerSubnets"
9898

99+
vpc_id = configuration.get("VpcId") or account_info.VpcID
100+
99101
tags = [
100102
# Tag "Name"
101103
{
@@ -138,7 +140,7 @@ def component_elastic_load_balancer_v2(definition,
138140
'Port': configuration['HTTPPort'],
139141
'Protocol': 'HTTP',
140142
'UnhealthyThresholdCount': '2',
141-
'VpcId': account_info.VpcID, # TODO: support multiple VPCs
143+
'VpcId': vpc_id,
142144
'Tags': tags,
143145
'TargetGroupAttributes': [{'Key': 'deregistration_delay.timeout_seconds', 'Value': '60'}]
144146
}

tests/test_components.py

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1044,6 +1044,27 @@ def test_component_load_balancer_v2_default_internal_scheme(monkeypatch):
10441044
assert 'internal' == result["Resources"]["test_lb"]["Properties"]["Scheme"]
10451045

10461046

1047+
def test_component_load_balancer_v2_target_group_vpc_id(monkeypatch):
1048+
configuration = {
1049+
"Name": "test_lb",
1050+
"SecurityGroups": "",
1051+
"HTTPPort": "9999",
1052+
"VpcId": "0a-12345"
1053+
}
1054+
info = {'StackName': 'foobar', 'StackVersion': '0.1'}
1055+
definition = {"Resources": {}}
1056+
1057+
args = MagicMock()
1058+
args.region = "foo"
1059+
1060+
mock_string_result = MagicMock()
1061+
mock_string_result.return_value = "foo"
1062+
monkeypatch.setattr('senza.components.elastic_load_balancer_v2.resolve_security_groups', mock_string_result)
1063+
1064+
result = component_elastic_load_balancer_v2(definition, configuration, args, info, False, MagicMock())
1065+
assert '0a-12345' == result["Resources"]["test_lbTargetGroup"]["Properties"]["VpcId"]
1066+
1067+
10471068
def test_component_subnet_auto_configuration(monkeypatch):
10481069
configuration = {
10491070
'PublicOnly': True,

0 commit comments

Comments
 (0)