Skip to content

Commit

Permalink
Upgrade AWS provider and remove now-redundant second apply (#107)
Browse files Browse the repository at this point in the history
  • Loading branch information
austinbyers committed Mar 21, 2018
1 parent 2f0ee27 commit 775092d
Show file tree
Hide file tree
Showing 3 changed files with 3 additions and 25 deletions.
12 changes: 0 additions & 12 deletions manage.py
Expand Up @@ -32,10 +32,6 @@

# Terraform identifiers.
CB_KMS_ALIAS_TERRAFORM_ID = 'aws_kms_alias.encrypt_credentials_alias'
LAMBDA_ALIASES_TERRAFORM_IDS = [
'module.binaryalert_{}.aws_lambda_alias.production_alias'.format(name)
for name in ['analyzer', 'batcher', 'dispatcher', 'downloader']
]
BINARY_BUCKET_TERRAFORM_ID = 'aws_s3_bucket.binaryalert_binaries'
LOG_BUCKET_TERRAFORM_ID = 'aws_s3_bucket.binaryalert_log_bucket'

Expand Down Expand Up @@ -375,19 +371,11 @@ def apply() -> None:
# Setup the backend if needed and reload modules.
subprocess.check_call(['terraform', 'init'])

subprocess.check_call(['terraform', 'validate'])
subprocess.check_call(['terraform', 'fmt'])

# Apply changes (requires interactive approval)
subprocess.check_call(['terraform', 'apply', '-auto-approve=false'])

# A second apply is unfortunately necessary to update the Lambda aliases.
print('\nRe-applying to update Lambda aliases...')
subprocess.check_call(
['terraform', 'apply', '-auto-approve=true', '-refresh=false'] +
['-target=' + alias for alias in LAMBDA_ALIASES_TERRAFORM_IDS]
)

def build(self) -> None:
"""Build Lambda packages (saves *.zip files in terraform/)."""
lambda_build(TERRAFORM_DIR, self._config.enable_carbon_black_downloader == 1)
Expand Down
2 changes: 1 addition & 1 deletion terraform/main.tf
Expand Up @@ -3,6 +3,6 @@ terraform {
}

provider "aws" {
version = "~> 1.5.0"
version = "~> 1.11.0"
region = "${var.aws_region}"
}
14 changes: 2 additions & 12 deletions tests/manage_test.py
Expand Up @@ -288,25 +288,15 @@ def test_analyze_all(self, mock_print: mock.MagicMock, mock_client: mock.MagicMo
)
])

@mock.patch.object(manage, 'print')
@mock.patch.object(subprocess, 'check_call')
def test_apply(self, mock_subprocess: mock.MagicMock, mock_print: mock.MagicMock):
def test_apply(self, mock_subprocess: mock.MagicMock):
"""Validate order of Terraform operations."""
self.manager.apply()
mock_subprocess.assert_has_calls([
mock.call(['terraform', 'init']),
mock.call(['terraform', 'validate']),
mock.call(['terraform', 'fmt']),
mock.call(['terraform', 'apply', '-auto-approve=false']),
mock.call([
'terraform', 'apply', '-auto-approve=true', '-refresh=false',
'-target=module.binaryalert_analyzer.aws_lambda_alias.production_alias',
'-target=module.binaryalert_batcher.aws_lambda_alias.production_alias',
'-target=module.binaryalert_dispatcher.aws_lambda_alias.production_alias',
'-target=module.binaryalert_downloader.aws_lambda_alias.production_alias'
])
mock.call(['terraform', 'apply', '-auto-approve=false'])
])
mock_print.assert_called_once()

@mock.patch.object(manage, 'lambda_build')
def test_build(self, mock_build: mock.MagicMock):
Expand Down

0 comments on commit 775092d

Please sign in to comment.