Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use spruce to merge cloudformation yaml templates #377

Open
sqqqrly opened this issue Jun 6, 2023 · 1 comment
Open

Use spruce to merge cloudformation yaml templates #377

sqqqrly opened this issue Jun 6, 2023 · 1 comment

Comments

@sqqqrly
Copy link

sqqqrly commented Jun 6, 2023

When I try spruce merge test1.yaml test2.yaml > test-all.yaml the result has all of the cloudformation functions (!Ref, !Sub, !GetAtt) silently removed.

Q. Is there a work-around?
Seems all spruce needs to do is to leave the cloudformation functions unchanged in values.

Here are links to the official AWS CloudFormation documentation pages for !Ref and !Sub:

Example

# test1.yaml
Resources:
  MyBucket1:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub my-bucket1-${Environment}
  MyTopic1:
    Type: AWS::SNS::Topic
    Properties:
      DisplayName: !Sub My Topic1 - ${Environment}
      TopicName: !Sub my-topic1-${Environment}
Outputs:
  MyBucket1Arn:
    Value: !GetAtt MyBucket1.Arn
  MyTopic1Arn:
    Value: !Ref MyTopic1
# test2.yaml
Resources:
  MyBucket2:
    Type: AWS::S3::Bucket
    Properties:
      BucketName: !Sub my-bucket2-${Environment}
  MyTopic2:
    Type: AWS::SNS::Topic
    Properties:
      DisplayName: !Sub My Topic2 - ${Environment}
      TopicName: !Sub my-topic2-${Environment}
Outputs:
  MyBucket2Arn:
    Value: !GetAtt MyBucket2.Arn
  MyTopic2Arn:
    Value: !Ref MyTopic2
╰─➤  spruce merge test1.yaml test2.yaml > test-all.yaml
# test-all.yaml
Outputs:
  MyBucket1Arn:
    Value: MyBucket1.Arn
  MyBucket2Arn:
    Value: MyBucket2.Arn
  MyTopic1Arn:
    Value: MyTopic1
  MyTopic2Arn:
    Value: MyTopic2
Resources:
  MyBucket1:
    Properties:
      BucketName: my-bucket1-${Environment}
    Type: AWS::S3::Bucket
  MyBucket2:
    Properties:
      BucketName: my-bucket2-${Environment}
    Type: AWS::S3::Bucket
  MyTopic1:
    Properties:
      DisplayName: My Topic1 - ${Environment}
      TopicName: my-topic1-${Environment}
    Type: AWS::SNS::Topic
  MyTopic2:
    Properties:
      DisplayName: My Topic2 - ${Environment}
      TopicName: my-topic2-${Environment}
    Type: AWS::SNS::Topic
@sqqqrly
Copy link
Author

sqqqrly commented Jun 6, 2023

I have tried using a \!Ref which mostly works, but leaves the backslash in the output yaml. It requires post processing to fix.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant