Skip to content
Closed
Show file tree
Hide file tree
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
Expand Up @@ -59,7 +59,7 @@ def store_regional_parameter_config(pipeline, parameter_store):
"""
if pipeline.top_level_regions:
parameter_store.put_parameter(
f"/deployment/{pipeline.nam}/regions",
f"/deployment/{pipeline.name}/regions",
str(list(set(pipeline.top_level_regions)))
)
return
Expand Down Expand Up @@ -115,7 +115,15 @@ def worker_thread(p, organizations, auto_create_repositories, deployment_map, pa
pipeline_target = Target(path_or_tag, target_structure, organizations, step, regions)
pipeline_target.fetch_accounts_for_target()

pipeline.template_dictionary["targets"].append(target_structure.generate_waves())
# Targets should be a list of lists.

# Note: This is a big shift away from how ADF handles targets natively.
# Previously this would be a list of [accountId(s)] it now returns a list of [[account_ids], [account_ids]]
# for the sake of consistency we should probably think of a target consisting of multiple "waves". So if you see
# any reference to a wave going forward it will be the individual batch of account ids
pipeline.template_dictionary["targets"].append(
list(target_structure.generate_waves()),
)

if DEPLOYMENT_ACCOUNT_REGION not in regions:
pipeline.stage_regions.append(DEPLOYMENT_ACCOUNT_REGION)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,13 +35,18 @@ def __init__(

def update_deployment_parameters(self, pipeline):
for target in pipeline.template_dictionary['targets']:
for _t in target:
if _t.get('target'): # Allows target to be interchangeable with path
_t['path'] = _t.pop('target')
if _t.get('path'):
self.account_ou_names.update(
{item['name']: item['path'] for item in target if item['name'] != 'approval'}
)
for wave in target:
for wave_target in wave:
if wave_target.get('target'): # Allows target to be interchangeable with path
wave_target['path'] = wave_target.pop('target')
if wave_target.get('path'):
self.account_ou_names.update(
{
item['name']: item['path']
for item in wave
if item['name'] != 'approval'
}
)
with open(f'{pipeline.name}.json', mode='w', encoding='utf-8') as outfile:
json.dump(self.account_ou_names, outfile)
self.s3.put_object(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,13 +48,10 @@ def _define_target_type(target):
return target

def generate_waves(self):
waves = []
wave_size = self.wave.get('size', 50)
length = len(self.account_list)
for index in range(0, length, wave_size):
yield self.account_list[index:min(index + wave_size, length)]
waves.append(self.account_list[index:min(index + wave_size, length)])
return waves


class Target:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,13 +43,84 @@ def test_update_deployment_parameters(cls):
}
})
pipeline.template_dictionary = {
"targets": [[
{
"name": "some_pipeline",
"path": "/fake/path",
}
]]
"targets": [
# Array holding all waves
[
# First wave of targets
[
# First batch within the first wave
{
# First target in first wave
"name": "some_pipeline",
"path": "/fake/path",
}
],
],
],
}

cls.update_deployment_parameters(pipeline)
assert cls.account_ou_names['some_pipeline'] == '/fake/path'


def test_update_deployment_parameters_waves(cls):
cls.s3 = Mock()
cls.s3.put_object.return_value = None

pipeline = Pipeline({
"name": "pipeline",
"params": {"key": "value"},
"targets": [],
"default_providers": {
"source": {
"name": "codecommit",
"properties" : {
"account_id": 111111111111,
}
}
}
})
pipeline.template_dictionary = {
"targets": [ # Array holding all waves
[ # First wave of targets
[ # First batch within the first wave
{ # First target in first wave
"name": "first",
"path": "/first/path",
},
{ # Second target in first wave
"name": "second",
"path": "/second/path",
}
],
[ # Second batch within the first wave
{
# Third target in first wave
"name": "third",
"path": "/third/path",
},
],
],
[ # Second wave of targets
[ # First batch within the second wave
{
# Third target in first wave
"name": "approval",
},
],
],
[ # Third wave of targets
[ # First batch within the third wave
{
# Third target in first wave
"name": "fourth",
"path": "/fourth/path",
},
],
]
],
}

cls.update_deployment_parameters(pipeline)
for target in ['first', 'second', 'third', 'fourth']:
assert cls.account_ou_names[target] == f'/{target}/path'