Skip to content

Commit bd792ad

Browse files
authored
fix(modules/asg): Accept entire SG list for ENI in ASG module (#88)
1 parent 028e112 commit bd792ad

File tree

2 files changed

+6
-6
lines changed

2 files changed

+6
-6
lines changed

modules/asg/main.tf

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ resource "aws_launch_template" "this" {
6868

6969
network_interfaces {
7070
device_index = 0
71-
security_groups = [local.default_eni_sg_ids[0]]
71+
security_groups = local.default_eni_sg_ids
7272
subnet_id = values(local.default_eni_subnet_names[0])[0]
7373
associate_public_ip_address = try(local.default_eni_public_ip[0])
7474
}

modules/asg/scripts/lambda.py

+5-5
Original file line numberDiff line numberDiff line change
@@ -158,7 +158,7 @@ def create_interface_settings(instance_zone: str) -> list:
158158
for k, v in sett.items():
159159
interface[eni] = {} if eni not in interface.keys() else interface[eni]
160160
interface[eni]["index"] = int(v) if 'device_index' in k else interface.get(eni).get('index')
161-
interface[eni]["sg"] = v[0] if 'security_group_ids' in k else interface.get(eni).get('sg')
161+
interface[eni]["sg"] = v if 'security_group_ids' in k else interface.get(eni).get('sg')
162162
interface[eni]["c_pub_ip"] = v if 'create_public_ip' in k else interface.get(eni).get('c_pub_ip')
163163
interface[eni]["s_dest_ch"] = v if 'source_dest_check' in k else interface.get(eni).get('s_dest_ch')
164164
if 'subnet_id' in k:
@@ -180,23 +180,23 @@ def inspect_ec2_instance(self, instance_id: str) -> tuple:
180180
return instance_info.get('Placement').get('AvailabilityZone') if 'Placement' in instance_info else None, \
181181
instance_info.get('SubnetId'), instance_info.get('NetworkInterfaces')
182182

183-
def create_network_interface(self, instance_id: str, subnet_id: str, sg_id: int) -> str:
183+
def create_network_interface(self, instance_id: str, subnet_id: str, sg_ids: list) -> str:
184184
"""
185185
As function name, it creates new ENI, if something wrong it catch error.
186186
187187
:param instance_id: EC2 Instance id
188188
:param subnet_id: Subnet id
189-
:param sg_id: Security group id
189+
:param sg_ids: Security group ids
190190
:return: Network Interface id
191191
"""
192192

193-
self.logger.debug(f"DEBUG: create_interface: instance_id={instance_id}, subnet_id={subnet_id}, sg_id={sg_id}")
193+
self.logger.debug(f"DEBUG: create_interface: instance_id={instance_id}, subnet_id={subnet_id}, sg_ids={sg_ids}")
194194
try:
195195
tags = loads(getenv('lambda_config')).get('tags')
196196
tag_specifications = [{'Key': k, 'Value': v} for k, v in tags.items()]
197197
network_interface = self.ec2_client.create_network_interface(
198198
SubnetId=subnet_id,
199-
Groups=[sg_id],
199+
Groups=sg_ids,
200200
TagSpecifications=[
201201
{
202202
'ResourceType': 'network-interface',

0 commit comments

Comments
 (0)