cdk diff (and cdk deploy) complains about short functions in existing yaml
See original GitHub issueI have a stack deployed with an authored YAML template that uses short functions like !GetAtt
. I am trying to convert this template to CDK, but cdk diff
strips them.
Reproduction Steps
- Deploy a stack with a YAML file that uses !GetAtt authored outside of CDK
- Re-create that stack using CDK, generating the same
Fn::GetAtt
references - Run
cdk diff my-stack
Error Log
(node:2590) YAMLWarning: The tag !GetAtt is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !GetAtt is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !ImportValue is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !GetAtt is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Sub is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !Ref is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !ImportValue is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !ImportValue is unavailable, falling back to tag:yaml.org,2002:str (node:2590) YAMLWarning: The tag !FindInMap is unavailable, falling back to tag:yaml.org,2002:seq
The !Fn is stripped, so the diff acts as if Prop: !GetAtt Thing.myAtt
is actually the string Prop: Thing.myAtt
│ [-] "value": "MyKey.SecretAccessKey",
│ [+] "value": {
│ [+] "Fn::GetAtt": [
│ [+] "MyKey",
│ [+] "SecretAccessKey"
│ [+] ]
│ [+] },
Environment
- CLI Version :1.26.0
- Framework Version:
- OS :MacOS
- Language :Typescript
Other
Here’s my workaround for this.
Use cfn-flip to flip it to JSON:
aws cloudformation get-template --stack-name my-stack | jq ".TemplateBody" -r | cfn-flip -i yaml > cdk.out/my-stack.orig.json
Then, use cdk diff
to compare to that:
diff my-stack --template ./cdk.out/my-stack.orig.json
This is 🐛 Bug Report
Issue Analytics
- State:
- Created 4 years ago
- Reactions:4
- Comments:5 (3 by maintainers)
Top GitHub Comments
@comcalvi has actually added support for CloudFormation short-forms in this PR: #8746 .
We’ll probably have to extract his logic after that PR is merged to use the same YAML parsing in the
cdk diff
command.Encountering this same issue when using CfnInclude on an existing template. Issue persists even after using cfn-flip to convert to JSON beforehand. Seems like the yaml generator used internally is not setup with the required custom tags for cloudformation.