Repository: cloud-custodian/cloud-custodian

Issue:
Cannot search for ami unused if launch template does not have Version key
**Describe the bug**


Launch template does not have the `Version` key

**To Reproduce**

1. Create a launch template without a default version
2. Create the `ami-unused.yml` policy from the yaml below
3. Run the policy

    ```
    $ custodian run \
      -c policies/ami-unused.yml \
      -s out \
      --region us-west-2 \
      --dryrun \
      --cache-period 0
    ```

**Expected behavior**
Not error out

**Background (please complete the following information):**
 - OS: 10.15
 - Python Version: 3.7.6
 - Custodian Version: 0.9
 - Tool Version: [if applicable]
 - Cloud Provider: aws
 - Policy: [please exclude any account/sensitive information]
```yaml
policies:
  - name: ami-unused
    resource: ami
    filters:
      - type: unused
        value: true
```
 - Traceback: [if applicable, please exclude sensitive/account information]

```
2020-03-17 14:34:01,624: custodian.output:ERROR Error while executing policy
Traceback (most recent call last):
  File "/Users/user/.local/share/virtualenvs/cloud_custodian-GAUqGNXp/lib/python3.7/site-packages/c7n/policy.py", line 288, in run
    resources = self.policy.resource_manager.resources()
  File "/Users/user/.local/share/virtualenvs/cloud_custodian-GAUqGNXp/lib/python3.7/site-packages/c7n/resources/ami.py", line 53, in resources
    return super(AMI, self).resources(query=query)
  File "/Users/user/.local/share/virtualenvs/cloud_custodian-GAUqGNXp/lib/python3.7/site-packages/c7n/query.py", line 460, in resources
    resources = self.filter_resources(resources)
  File "/Users/user/.local/share/virtualenvs/cloud_custodian-GAUqGNXp/lib/python3.7/site-packages/c7n/manager.py", line 108, in filter_resources
    resources = f.process(resources, event)
  File "/Users/user/.local/share/virtualenvs/cloud_custodian-GAUqGNXp/lib/python3.7/site-packages/c7n/resources/ami.py", line 305, in process
    images = self._pull_ec2_images().union(self._pull_asg_images())
  File "/Users/user/.local/share/virtualenvs/cloud_custodian-GAUqGNXp/lib/python3.7/site-packages/c7n/resources/ami.py", line 296, in _pull_asg_images
    list(tmpl_mgr.get_asg_templates(asgs).keys())):
  File "/Users/user/.local/share/virtualenvs/cloud_custodian-GAUqGNXp/lib/python3.7/site-packages/c7n/resources/ec2.py", line 1902, in get_asg_templates
    t['Version']), []).append(a['AutoScalingGroupName'])
KeyError: 'Version'
```

**Additional context**
Add any other context about the problem here.

By checking for the Version key using 

```
t.get('Version', None)
```

we can eliminate this issue.



Discussion:

Resolving patch:
diff --git a/c7n/resources/ec2.py b/c7n/resources/ec2.py
--- a/c7n/resources/ec2.py
+++ b/c7n/resources/ec2.py
@@ -2008,7 +2008,7 @@ def get_asg_templates(self, asgs):
                 continue
             templates.setdefault(
                 (t['LaunchTemplateId'],
-                 t['Version']), []).append(a['AutoScalingGroupName'])
+                 t.get('Version', None)), []).append(a['AutoScalingGroupName'])
         return templates
 
 


Test patch: