Skip to content
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

terraform support #1129

Merged
merged 1 commit into from
Aug 7, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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