-
Notifications
You must be signed in to change notification settings - Fork 236
feat: introduce-variable-org-stage #636
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
Merged
StewartW
merged 5 commits into
awslabs:master
from
AndyEfaa:feat/introduce-variable-org-stage
Aug 8, 2023
Merged
Changes from 4 commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
65455c3
feat: introduce-variable-org-stage
falkena1 92e9d22
Merge remote-tracking branch 'upstream/master' into feat/introduce-va…
sbkok 34f4591
Add tests for main configuration parameters
sbkok 51c10ff
Update docs/admin-guide.md
sbkok 0ac4214
Fix linting issues
sbkok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -7,10 +7,11 @@ | |
|
|
||
| from pytest import fixture | ||
| from parameter_store import ParameterStore | ||
| from mock import Mock, patch, call | ||
| from mock import MagicMock, Mock, patch, call | ||
| from main import ( | ||
| Config, | ||
| ensure_generic_account_can_be_setup, | ||
| prepare_deployment_account, | ||
| update_deployment_account_output_parameters, | ||
| ) | ||
|
|
||
|
|
@@ -30,18 +31,20 @@ def cls(): | |
| @fixture | ||
| def sts(): | ||
| sts = Mock() | ||
| sts.assume_cross_account_role.return_value = { | ||
| 'Credentials': { | ||
| 'AccessKeyId': 'string', | ||
| 'SecretAccessKey': 'string', | ||
| 'SessionToken': 'string', | ||
| 'Expiration': 12345 | ||
| }, | ||
| 'AssumedRoleUser': { | ||
| 'AssumedRoleId': 'string', | ||
| 'Arn': 'string' | ||
| } | ||
|
|
||
| role_mock = Mock() | ||
| role_mock.client = Mock() | ||
| role_mock.Credentials = { | ||
| 'AccessKeyId': 'string', | ||
| 'SecretAccessKey': 'string', | ||
| 'SessionToken': 'string', | ||
| 'Expiration': 12345 | ||
| } | ||
| role_mock.AssumedRoleUser = { | ||
| 'AssumedRoleId': 'string', | ||
| 'Arn': 'string' | ||
| } | ||
| sts.assume_cross_account_role.return_value = role_mock | ||
| return sts | ||
|
|
||
|
|
||
|
|
@@ -79,3 +82,171 @@ def test_update_deployment_account_output_parameters(cls, sts): | |
| ) | ||
| assert 4 == mock.call_count | ||
| mock.assert_has_calls(expected_calls, any_order=True) | ||
|
|
||
|
|
||
| @patch('main.ParameterStore') | ||
| def test_prepare_deployment_account_defaults(param_store_cls, cls, sts): | ||
| deploy_param_store = MagicMock() | ||
| parameter_stores = { | ||
| 'eu-central-1': deploy_param_store, | ||
| 'eu-west-1': MagicMock(), | ||
| 'us-west-2': MagicMock(), | ||
| } | ||
| parameter_store_list = [ | ||
| deploy_param_store, | ||
| parameter_stores['eu-west-1'], | ||
| parameter_stores['us-west-2'], | ||
| ] | ||
| param_store_cls.side_effect = [ | ||
| parameter_stores['eu-west-1'], | ||
| parameter_stores['us-west-2'], | ||
| deploy_param_store, | ||
| deploy_param_store, | ||
| ] | ||
| deployment_account_id = "111122223333" | ||
| prepare_deployment_account( | ||
| sts=sts, | ||
| deployment_account_id=deployment_account_id, | ||
| config=cls, | ||
| ) | ||
| assert param_store_cls.call_count == 4 | ||
| param_store_cls.assert_has_calls( | ||
| [ | ||
| call( | ||
| 'eu-central-1', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| call( | ||
| 'eu-west-1', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| call( | ||
| 'us-west-2', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| call( | ||
| 'eu-central-1', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| ], | ||
| any_order=False, | ||
| ) | ||
| for param_store in parameter_store_list: | ||
| assert param_store.put_parameter.call_count == ( | ||
| 11 if param_store == deploy_param_store else 2 | ||
| ) | ||
| param_store.put_parameter.assert_has_calls( | ||
| [ | ||
| call('organization_id', 'o-123456789'), | ||
| call('/adf/extensions/terraform/enabled', 'False'), | ||
| ], | ||
| any_order=False, | ||
| ) | ||
| deploy_param_store.put_parameter.assert_has_calls( | ||
| [ | ||
| call('adf_version', '1.0.0'), | ||
| call('adf_log_level', 'INFO'), | ||
| call('deployment_account_bucket', 'some_deployment_account_bucket'), | ||
| call('default_scm_branch', 'master'), | ||
| call('/adf/org/stage', 'none'), | ||
| call('cross_account_access_role', 'some_role'), | ||
| call('notification_type', 'email'), | ||
| call('notification_endpoint', '[email protected]'), | ||
| call('/adf/extensions/terraform/enabled', 'False'), | ||
| ], | ||
| ) | ||
|
|
||
|
|
||
| @patch('main.ParameterStore') | ||
| def test_prepare_deployment_account_specific_config(param_store_cls, cls, sts): | ||
| deploy_param_store = MagicMock() | ||
| parameter_stores = { | ||
| 'eu-central-1': deploy_param_store, | ||
| 'eu-west-1': MagicMock(), | ||
| 'us-west-2': MagicMock(), | ||
| } | ||
| parameter_store_list = [ | ||
| deploy_param_store, | ||
| parameter_stores['eu-west-1'], | ||
| parameter_stores['us-west-2'], | ||
| ] | ||
| param_store_cls.side_effect = [ | ||
| parameter_stores['eu-west-1'], | ||
| parameter_stores['us-west-2'], | ||
| deploy_param_store, | ||
| deploy_param_store, | ||
| ] | ||
| deployment_account_id = "111122223333" | ||
| # Set optional config | ||
| cls.notification_type = 'slack' | ||
| cls.notification_endpoint = 'slack-channel' | ||
| cls.notification_channel = 'slack-channel' | ||
| cls.config['scm'] = { | ||
| 'auto-create-repositories': 'disabled', | ||
| 'default-scm-branch': 'main', | ||
| } | ||
| cls.config['extensions'] = { | ||
| 'terraform': { | ||
| 'enabled': 'True', | ||
| }, | ||
| } | ||
| cls.config['org'] = { | ||
| 'stage': 'test-stage', | ||
| } | ||
| prepare_deployment_account( | ||
| sts=sts, | ||
| deployment_account_id=deployment_account_id, | ||
| config=cls, | ||
| ) | ||
| assert param_store_cls.call_count == 4 | ||
| param_store_cls.assert_has_calls( | ||
| [ | ||
| call( | ||
| 'eu-central-1', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| call( | ||
| 'eu-west-1', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| call( | ||
| 'us-west-2', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| call( | ||
| 'eu-central-1', | ||
| sts.assume_cross_account_role.return_value, | ||
| ), | ||
| ], | ||
| any_order=False, | ||
| ) | ||
| for param_store in parameter_store_list: | ||
| assert param_store.put_parameter.call_count == ( | ||
| 13 if param_store == deploy_param_store else 2 | ||
| ) | ||
| param_store.put_parameter.assert_has_calls( | ||
| [ | ||
| call('organization_id', 'o-123456789'), | ||
| call('/adf/extensions/terraform/enabled', 'False'), | ||
| ], | ||
| any_order=False, | ||
| ) | ||
| deploy_param_store.put_parameter.assert_has_calls( | ||
| [ | ||
| call('adf_version', '1.0.0'), | ||
| call('adf_log_level', 'INFO'), | ||
| call('deployment_account_bucket', 'some_deployment_account_bucket'), | ||
| call('default_scm_branch', 'main'), | ||
| call('/adf/org/stage', 'test-stage'), | ||
| call('auto_create_repositories', 'disabled'), | ||
| call('cross_account_access_role', 'some_role'), | ||
| call('notification_type', 'slack'), | ||
| call( | ||
| 'notification_endpoint', | ||
| "arn:aws:lambda:eu-central-1:" | ||
| f"{deployment_account_id}:function:SendSlackNotification", | ||
| ), | ||
| call('/notification_endpoint/main', 'slack-channel'), | ||
| call('/adf/extensions/terraform/enabled', 'False'), | ||
| ], | ||
| ) | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.