From 36ebccd2784d105057b9013468c68337719af025 Mon Sep 17 00:00:00 2001 From: Kapil Thangavelu Date: Tue, 6 Aug 2019 16:25:00 -0400 Subject: [PATCH] terraform package, switch app/stage values from variables to null data provider --- chalice/package.py | 22 +++++++++------------- docs/source/topics/tf.rst | 6 +++--- tests/unit/test_package.py | 14 ++++---------- 3 files changed, 16 insertions(+), 26 deletions(-) diff --git a/chalice/package.py b/chalice/package.py index e6f668e0e..16e53dc29 100644 --- a/chalice/package.py +++ b/chalice/package.py @@ -583,18 +583,6 @@ def generate(self, resources): 'terraform': { 'required_version': '> 0.11.0' }, - 'variable': { - 'chalice_app_name': { - 'type': 'string', - 'description': 'Chalice App Name (not editable)', - 'default': self._config.app_name - }, - 'chalice_stage_name': { - 'type': 'string', - 'description': 'Chalice Stage (not editable)', - 'default': self._config.chalice_stage, - } - }, 'provider': { 'aws': {'version': '> 2.0.0'}, 'local': {'version': '> 1.0'}, @@ -602,7 +590,15 @@ def generate(self, resources): }, 'data': { 'aws_caller_identity': {'chalice': {}}, - 'aws_region': {'chalice': {}} + 'aws_region': {'chalice': {}}, + 'null_data_provider': { + 'chalice': { + 'inputs': { + 'app': self._config.app_name, + 'stage': self._config.chalice_stage + } + } + } } } diff --git a/docs/source/topics/tf.rst b/docs/source/topics/tf.rst index e2f6ade5c..445bf6808 100644 --- a/docs/source/topics/tf.rst +++ b/docs/source/topics/tf.rst @@ -77,9 +77,9 @@ to deploy our app. Note terraform will deploy run against all terraform files in this directory, so we can add additional resources for our application by adding terraform additional files here. The Chalice terraform template -includes two variables that we can optionally use when constructing -these additional resources `chalice_stage_name` and -`chalice_app_name`, these variables should **not** be user overridden. +includes two static data values (`app` and `stage` names) that we can +optionally use when constructing these additional resources, +ie. `${data.null_data_source.chalice.outputs.app}` First let's run Terraform init to install the AWS Terraform Provider:: diff --git a/tests/unit/test_package.py b/tests/unit/test_package.py index c0f828731..886574d90 100644 --- a/tests/unit/test_package.py +++ b/tests/unit/test_package.py @@ -458,22 +458,16 @@ def handler(event): }] } - def test_can_generate_chalice_terraform_variables(self, sample_app): + def test_can_generate_chalice_terraform_static_data(self, sample_app): config = Config.create(chalice_app=sample_app, project_dir='.', app_name='myfoo', api_gateway_stage='dev') template = self.generate_template(config, 'dev') - assert template['variable'] == { - 'chalice_app_name': { - 'default': 'myfoo', - 'description': 'Chalice App Name (not editable)', - 'type': 'string'}, - 'chalice_stage_name': { - 'default': 'dev', - 'description': 'Chalice Stage (not editable)', - 'type': 'string'} + assert template['data']['null_data_provider']['chalice']['inputs'] == { + 'app': 'myfoo', + 'stage': 'dev' } def test_can_package_s3_event_handler_sans_filters(self, sample_app):