Aws-cdk: cdk diff (and cdk deploy) complains about short functions in existing yaml

Created on 2 Mar 2020  Â·  5Comments  Â·  Source: aws/aws-cdk

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.

Reproduction Steps

  1. Deploy a stack with a YAML file that uses !GetAtt authored outside of CDK
  2. Re-create that stack using CDK, generating the same Fn::GetAtt references
  3. 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: Bug Report

bug efforsmall in-progress p2 packagtools

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 diff command.

All 5 comments

@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.

Was this page helpful?
0 / 5 - 0 ratings