Skip to content

Commit

Permalink
Add support for terraform packaging
Browse files Browse the repository at this point in the history
Squashed commit of the following:

commit 9ea78cba5919fab817efa22752974ab1cc70ce9c
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Fri Aug 2 17:14:52 2019 -0400

    terraform-package rebase 1

commit a4936fc
Merge: 22a3463 60d0217
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Fri Aug 2 13:28:19 2019 -0400

    terraform support, merge upstream and resolve conflicts

commit 22a3463
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Fri Aug 2 08:44:20 2019 -0400

    terraform packaging, explicit error message on websocket support

commit 50d1880
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Thu Aug 1 17:15:29 2019 -0400

    terraform support, handle a tf ref for bucket notifications

commit 6cf5a54
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Thu Aug 1 09:32:29 2019 -0400

    terraform packaging test with private api gateway resource and min compression size

commit 77d4840
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Wed Jul 31 17:54:37 2019 -0400

    fix tests and lint

commit b3e324b
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Wed Jul 31 14:44:46 2019 -0400

    terraform support, address review comments

commit 124f3d9
Merge: 373d2f3 bd7fa76
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Tue Jul 30 10:00:53 2019 -0400

    Merge branch 'upstream' into terraform-package

commit 373d2f3
Merge: 8fbd4b1 4853c6c
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Thu Jun 20 16:08:07 2019 -0400

    Merge branch 'upstream' into terraform-package

commit 8fbd4b1
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Fri Jun 7 10:52:21 2019 -0400

    update sam layer gen to new generator interface

commit cbc4a64
Merge: 3084852 07ca537
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Fri Jun 7 10:41:24 2019 -0400

    Merge branch 'upstream' into terraform-package

commit 07ca537
Merge: 4f8ddd0 31acf9e
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Thu Jun 6 13:01:32 2019 -0400

    Merge branch 'master' of https://github.com/aws/chalice into upstream

commit 3084852
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Thu Jun 6 12:53:40 2019 -0400

    address review comments on docs

commit 0fd9d87
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Tue Jun 4 14:19:44 2019 -0400

    test default generator method

commit 2dd988a
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Tue Jun 4 14:05:43 2019 -0400

    relax terraform version requirement

commit cf2a95a
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Mon Jun 3 19:10:35 2019 -0400

    add layer support

commit 4f8ddd0
Author: Kapil Thangavelu <kapilt@gmail.com>
Date:   Sat May 25 07:32:14 2019 -0400

    cli package terraform support
  • Loading branch information
kapilt authored and jamesls committed Aug 6, 2019
1 parent cf0cad0 commit 53a55a8
Show file tree
Hide file tree
Showing 10 changed files with 1,005 additions and 88 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.rst
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ Next Release (TBD)
(`#1160 https://github.com/aws/chalice/pull/1160`__)
* Add --merge-template option to package command
(`#1195 https://github.com/aws/chalice/pull/1195`__)
* Add support for packaging via terraform
(`#1129 https://github.com/aws/chalice/pull/1129`__)


1.9.1
Expand Down
30 changes: 21 additions & 9 deletions chalice/cli/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -368,29 +368,41 @@ def generate_sdk(ctx, sdk_type, stage, outdir):


@cli.command('package')
@click.option('--pkg-format', default='cloudformation',
help=('Specify the provisioning engine to use for '
'template output. Chalice supports both '
'CloudFormation and Terraform. Default '
'is CloudFormation.'),
type=click.Choice(['cloudformation', 'terraform']))
@click.option('--stage', default=DEFAULT_STAGE_NAME,
help="Chalice Stage to package.")
@click.option('--single-file', is_flag=True,
default=False,
help=("Create a single packaged file. "
"By default, the 'out' argument "
"specifies a directory in which the "
"package assets will be placed. If "
"this argument is specified, a single "
"zip file will be created instead."))
@click.option('--stage', default=DEFAULT_STAGE_NAME)
"zip file will be created instead. CloudFormation Only."))
@click.option('--merge-template',
help=('Specify a JSON template to be merged '
'into the generated template. This is useful '
'for adding resources to a Chalice template or '
'modify values in the template.'))
'modify values in the template. CloudFormation Only.'))
@click.argument('out')
@click.pass_context
def package(ctx, single_file, stage, merge_template, out):
# type: (click.Context, bool, str, str, str) -> None
def package(ctx, single_file, stage, merge_template,
out, pkg_format):
# type: (click.Context, bool, str, str, str, str) -> None
factory = ctx.obj['factory'] # type: CLIFactory
config = factory.create_config_obj(
chalice_stage_name=stage,
)
packager = factory.create_app_packager(config, merge_template)
config = factory.create_config_obj(stage)
packager = factory.create_app_packager(config, pkg_format, merge_template)
if pkg_format == 'terraform' and (merge_template or single_file):
click.echo((
"Terraform format does not support "
"merge-template or single-file options"))
raise click.Abort()

if single_file:
dirname = tempfile.mkdtemp()
try:
Expand Down
7 changes: 4 additions & 3 deletions chalice/cli/factory.py
Original file line number Diff line number Diff line change
Expand Up @@ -179,9 +179,10 @@ def _validate_config_from_disk(self, config):
except ValueError:
raise UnknownConfigFileVersion(string_version)

def create_app_packager(self, config, merge_template=None):
# type: (Config, OptStr) -> AppPackager
return create_app_packager(config, merge_template=merge_template)
def create_app_packager(self, config, package_format, merge_template=None):
# type: (Config, str, OptStr) -> AppPackager
return create_app_packager(
config, package_format, merge_template=merge_template)

def create_log_retriever(self, session, lambda_arn):
# type: (Session, str) -> LogRetriever
Expand Down
15 changes: 15 additions & 0 deletions chalice/deploy/swagger.py
Original file line number Diff line number Diff line change
Expand Up @@ -286,3 +286,18 @@ def _auth_uri(self, authorizer):
'/functions/{%s}/invocations' % varname,
['region_name', varname],
)


class TerraformSwaggerGenerator(SwaggerGenerator):

def __init__(self):
# type: () -> None
pass

def _uri(self, lambda_arn=None):
# type: (Optional[str]) -> Any
return '${aws_lambda_function.api_handler.invoke_arn}'

def _auth_uri(self, authorizer):
# type: (ChaliceAuthorizer) -> Any
return '${aws_lambda_function.%s.invoke_arn}' % (authorizer.name)
Loading

0 comments on commit 53a55a8

Please sign in to comment.