Skip to content

How to use two intrinsic functions in a tag key in Cloudformation

0

I'm trying to add tags to a AWS::EKS::Nodegroup resource that contain an output exported by another stack:

Resources:
  Nodegroup:
    Type: AWS::EKS::Nodegroup
      Properties:
        Tags:
          firstKey: firstValue
          !Sub myString-${Fn::ImportValue: myExport}: secondValue

But I'm getting validation errors because the function's colon is being interpreted as the key/value separator: Nested mappings are not allowed in compact mappings

Quoting as suggested here does not help since the intrinsic function is then seen as a string and not executed.

I tried this form as suggested in the documentation:

Tags: !Sub
  - 'myString-${myExport}: secondValue'
  - myExport: !ImportValue myExport

But apart from getting a string instead of a needed object, I wouldn't know how to add more than one tag.

Is there a way to achieve what I need?

asked 2 years ago284 views
1 Answer
0

Try like this:

      Tags:
        - Key: firstKey
          Value: firstValue
        - Key: !Sub "myString-${myExport}"
          Value: secondValue
        - Key: anotherKey
          Value: !Sub "anotherString-${Fn::ImportValue myOtherExport}"
EXPERT
answered 2 years ago
EXPERT
reviewed 2 years ago
  • This will not work because this is an array while the AWS::EKS::Nodegroup template wants an object of key-value pairs. Furthermore quoting intrinsic functions does not work.

You are not logged in. Log in to post an answer.

A good answer clearly answers the question and provides constructive feedback and encourages professional growth in the question asker.