Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for ASG duplicate issue with infrastructure/virtual-machine definitions re-use #1095

Merged
merged 1 commit into from
Apr 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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