Skip to content

Commit

Permalink
Support setting the underlying terraform aws provider role per stage
Browse files Browse the repository at this point in the history
  • Loading branch information
Conor Maher committed May 27, 2022
1 parent 1ca226b commit ca3ef7e
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 0 deletions.
7 changes: 7 additions & 0 deletions chalice/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,13 @@ def reserved_concurrency(self):
varies_per_chalice_stage=True,
varies_per_function=True)

@property
def terraform_assume_role(self):
# type: () -> str
return self._chain_lookup('terraform_assume_role',
varies_per_chalice_stage=True,
varies_per_function=False)

def scope(self, chalice_stage, function_name):
# type: (str, str) -> Config
# Used to create a new config object that's scoped to a different
Expand Down
8 changes: 8 additions & 0 deletions chalice/package.py
Original file line number Diff line number Diff line change
Expand Up @@ -822,6 +822,7 @@ def generate(self, resources):

for resource in resources:
self.dispatch(resource, template)
self._inject_terraform_provider(template)
return template

def _fref(self, lambda_function, attr='arn'):
Expand Down Expand Up @@ -1406,6 +1407,13 @@ def _generate_domainname(self, resource, template):
# type: (models.DomainName, Dict[str, Any]) -> None
pass

def _inject_terraform_provider(self, template):
# type: (Dict[str, Any]) -> None
if self._config.terraform_assume_role is None:
return
provider = template.setdefault("provider", {})
aws_provider = provider.setdefault("aws", {})
aws_provider['assume_role'] = {'role_arn': self._config.terraform_assume_role}

class AppPackager(object):
def __init__(self,
Expand Down

0 comments on commit ca3ef7e

Please sign in to comment.