I 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.
Fn::GetAtt referencescdk diff my-stack(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"
│ [+] ]
│ [+] },
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: Bug Report
@jonb-ifit Is the use case here the scenario where a template that was initially authored in YAML is not being detected by cdk diff. Ideally cdk diff performs your workaround or something equivalent on your behalf and does not require any customer interaction.
Did you have another resolution in mind?
Is the use case here the scenario where a template that was initially authored in YAML is not being detected by
cdk diff
Essentially, yes. While cdk diff seems to parse the yaml mostly ok, it just plain removes the short-tagged functions like !Ref
Ideally, yeah, if it just did my workaround of using cfn-flip to JSON (which replaces the short-tagged functions with { "Ref": "xxx" }) that would work
I just run into the same issue: I'm trying to migrate an existing stack authored in YAML to CDK without destroying the existing resources.
I can confirm that the workaround works as expected.
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.
@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.
Most helpful comment
@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 diffcommand.