One of the benefits of sharing your work with smart colleaques is you don’t have to keep up with all the development around you, but can learn from the feedback you get.

I’m a big fan of creating AWS resources with Cloudformation templates but sometimes it gets boring to repeat the same piece of code over and over in your template. This happens especially when I need to tag my resources. You would see below code repeating in template for every resource that supports Cloudformation tagging.

    Properties:
      Tags:
      - Key: Name
        Value: !Ref AWS::StackName
      - Key: customer
        Value: !Ref TagCustomer
      - Key: product
        Value: !Ref TagProduct
      - Key: environment
        Value: !Ref TagEnvironment

Until recently I was asked why I’m doing this. Apparently I did miss that somepoint Cloudformation started to inherit tags from stack to all resources it created. I couldn’t find the announcement but I would think this happened around the time when AWS increased the maximum number of tags per resource from 10 to 50.

So when I now add tags to my stack …

Tagging1

… tags are “magically” propagated to all resources created from the stack!

Tagging2

And thats not all, if I then later on add/remove/update tags on stack. Changes will be reflected on stack resources too!

Tagging3

Cloudformation will create a change set and tell me it is going to modify all my resources that are taggable, but none will be replaced. Note that you don’t see EIP on that list, eventhough I have allocated one for my NAT Gateway, because EIP doesn’t support tagging from Cloudformation.

Tagging4

And after applying the change set, I can see new tag assigned to my NAT gateway!

Tagging5