Skip to content

Commit

Permalink
Merge pull request #1095 from seriva/fix/aws-duplicate-asg
Browse files Browse the repository at this point in the history
Fix for ASG duplicate issue with infrastructure/virtual-machine definitions re-use
  • Loading branch information
seriva authored Apr 7, 2020
2 parents 5f1151c + b0edbcd commit 62a0539
Showing 1 changed file with 8 additions and 5 deletions.
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import os
import uuid
from copy import deepcopy

from cli.helpers.doc_list_helpers import select_first
from cli.helpers.data_loader import load_yaml_obj, types
Expand All @@ -10,7 +11,7 @@
from cli.helpers.build_saver import get_terraform_path
from cli.helpers.data_loader import load_json_obj
from cli.helpers.naming_helpers import resource_name
from cli.helpers.objdict_helpers import objdict_to_dict
from cli.helpers.objdict_helpers import objdict_to_dict, dict_to_objdict
from cli.version import VERSION


Expand Down Expand Up @@ -57,6 +58,7 @@ def run(self):
subnets_to_create = []
security_groups_to_create = []
subnet_index = 0
asg_index = 0
for subnet_definition in component_value.subnets: # todo extract to another method or class
subnet = select_first(infrastructure, lambda item: item.kind == 'infrastructure/subnet' and
item.specification.cidr_block == subnet_definition['address_pool'])
Expand All @@ -79,7 +81,7 @@ def run(self):
subnets_to_create.append(subnet)
security_groups_to_create.append(security_group)

autoscaling_group = self.get_autoscaling_group(component_key, component_value, subnets_to_create)
autoscaling_group = self.get_autoscaling_group(component_key, component_value, subnets_to_create, asg_index)

for security_group in security_groups_to_create:
security_group.specification.rules += autoscaling_group.specification.security.rules
Expand All @@ -99,6 +101,7 @@ def run(self):

infrastructure.append(autoscaling_group)
infrastructure.append(launch_configuration)
asg_index += 1

if self.has_efs_any_mounts(efs_config):
infrastructure.append(efs_config)
Expand Down Expand Up @@ -130,10 +133,10 @@ def get_efs_config(self):
efs_config.specification.name = resource_name(self.cluster_prefix, self.cluster_name, 'efs')
return efs_config

def get_autoscaling_group(self, component_key, component_value, subnets_to_create):
autoscaling_group = self.get_virtual_machine(component_value, self.cluster_model, self.docs)
def get_autoscaling_group(self, component_key, component_value, subnets_to_create, index):
autoscaling_group = dict_to_objdict(deepcopy(self.get_virtual_machine(component_value, self.cluster_model, self.docs)))
autoscaling_group.specification.cluster_name = self.cluster_name
autoscaling_group.specification.name = resource_name(self.cluster_prefix, self.cluster_name, 'asg', component_key)
autoscaling_group.specification.name = resource_name(self.cluster_prefix, self.cluster_name, 'asg' + '-' + str(index), component_key)
autoscaling_group.specification.count = component_value.count
autoscaling_group.specification.subnet_names = [s.specification.name for s in subnets_to_create]
autoscaling_group.specification.availability_zones = list(set([s.specification.availability_zone for s in subnets_to_create]))
Expand Down

0 comments on commit 62a0539

Please sign in to comment.