kristofwillen / cfntagger

Mass tag resources in Cloudformation templates
GNU General Public License v3.0
4 stars 0 forks source link

AttributeError when adding new tags #18

Closed kristofwillen closed 1 year ago

kristofwillen commented 1 year ago

Wen adding new tags on a json based tag resource, I get an AttributeError:

$ export CFN_TAGS='{"test": "pytest"}' 

$ cat myfile.yml
...
  ResourceWithJsonTags:
    Type: AWS::SSM::Parameter
    Properties:
      Description: APoliciyArnParameter
      Name: APolicyParameterName
      Type: String
      Value: ADeployPolicy
      Tags:
          CostCenter: Sales

$ cfntagger -f myfile.yaml # cfntagger tags correctly
...
$ export CFN_TAGS='{"test": "pytest", "Creator": "Dinesh"}'      
$ cfntagger -f ./myfile.yml

[./myfile.yml][Resource] ResourceWithJsonTags => AWS::SSM::Parameter
Traceback (most recent call last):
  File "/usr/local/bin/cfntagger", line 73, in <module>
    cfn_tagger.tag()
  File "/usr/local/lib/python3.11/site-packages/cfntagger/cfntagger.py", line 721, in tag
    updated = self.change_tags(taglist=restags, resource=item)
              ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cfntagger/cfntagger.py", line 682, in change_tags
    key, value = get_tag_kv(tags, taglist)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/usr/local/lib/python3.11/site-packages/cfntagger/cfntagger.py", line 29, in get_tag_kv
    return resourcetag, resourcetaglist.get(resourcetag)
                        ^^^^^^^^^^^^^^^^^^^
AttributeError: 'CommentedSeq' object has no attribute 'get'
kristofwillen commented 1 year ago

This is probably related to #19 : in the first run, cfntagger converts existing list-based tags to Key/Value pairs. This breaks the programs logic, as it expects list tags.