Repository: aws/chalice

Issue:
Terraform aws provider invalid arn for s3 lambda permission
Packaging the chalice app for terraform is giving me an invalid source_arn error for the aws_lambda_permission s3event `"source_arn": "arn:*:s3:::lambda-function-name`

```
Error: "source_arn" (arn:*:s3:::lambda-function-name) is an invalid ARN:
invalid partition value (expecting to match regular expression: ^aws(-[a-z]+)*$)
```

I can't determine whether this is an issue with the validation of the provider or with how chalice is packaging this up?

https://github.com/aws/chalice/blob/ba93124276c3f2d360286396e536520c9fa5fecf/chalice/package.py#L853

chalice 1.18.1 & 1.19.0, python 3.8.0, terraform aws provider 3.4.0

Discussion:

Patch:
diff --git a/.changes/next-release/19399802349-bugfix-Terraform-93436.json b/.changes/next-release/19399802349-bugfix-Terraform-93436.json
new file mode 100644
index 0000000..37981d1
--- /dev/null
+++ b/.changes/next-release/19399802349-bugfix-Terraform-93436.json
@@ -0,0 +1,5 @@
+{
+  "type": "bugfix",
+  "category": "Terraform",
+  "description": "Fix issue with wildcard partition names in s3 event handlers (#1508)"
+}
diff --git a/chalice/package.py b/chalice/package.py
index 0aec597..9d5c094 100644
--- a/chalice/package.py
+++ b/chalice/package.py
@@ -791,7 +791,7 @@ class TerraformGenerator(TemplateGenerator):
         template = {
             'resource': {},
             'terraform': {
-                'required_version': '> 0.11.0, < 0.13.0'
+                'required_version': '> 0.11.0, < 0.14.0'
             },
             'provider': {
                 'template': {'version': '~> 2'},
@@ -895,7 +895,8 @@ class TerraformGenerator(TemplateGenerator):
             'action': 'lambda:InvokeFunction',
             'function_name': resource.lambda_function.function_name,
             'principal': self._options.service_principal('s3'),
-            'source_arn': 'arn:*:s3:::%s' % resource.bucket
+            'source_arn': ('arn:${data.aws_partition.chalice.partition}:'
+                           's3:::%s' % resource.bucket)
         }
 
     def _generate_sqseventsource(self, resource, template):


Test patch:
diff --git a/tests/unit/test_package.py b/tests/unit/test_package.py
index 22533d0..3ac9296 100644
--- a/tests/unit/test_package.py
+++ b/tests/unit/test_package.py
@@ -642,7 +642,8 @@ class TestTerraformTemplate(TemplateTestBase):
                    'action': 'lambda:InvokeFunction',
                    'function_name': 'sample_app-dev-handler',
                    'principal': 's3.amazonaws.com',
-                   'source_arn': 'arn:*:s3:::foo',
+                   'source_arn': (
+                       'arn:${data.aws_partition.chalice.partition}:s3:::foo'),
                    'statement_id': 'handler-s3event'
                }