Skip to content

Commit

Permalink
terraform package, switch app/stage values from variables to null dat…
Browse files Browse the repository at this point in the history
…a provider
  • Loading branch information
kapilt committed Aug 6, 2019
1 parent ee19516 commit 36ebccd
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 26 deletions.
22 changes: 9 additions & 13 deletions chalice/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -583,26 +583,22 @@ 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'},
'template': {'version': '> 2.0'},
},
'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
}
}
}
}
}

Expand Down
6 changes: 3 additions & 3 deletions docs/source/topics/tf.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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::

Expand Down
14 changes: 4 additions & 10 deletions tests/unit/test_package.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit 36ebccd

Please sign in to comment.