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

Shortform intrinsic functions not working in YAML templates #223

Open
geerlingguy opened this issue May 9, 2017 · 5 comments
Open

Shortform intrinsic functions not working in YAML templates #223

geerlingguy opened this issue May 9, 2017 · 5 comments

Comments

@geerlingguy
Copy link

I've converted my moonshot templates from JSON to YAML using aws-cfn-template-flip, and when I'm creating new infrastructure using moonshot create, I get errors like:

--> CREATE_FAILED QueueSecurityGroup The vpc ID 'VpcId' does not exist

This seems to occur because I'm using the short form of the Ref function, like so:

VpcId: !Ref VpcId

If I convert all my templates to use the more verbose/annoying full function form, like:

VpcId:
  Ref: VpcId

Then it seems to work.

Is moonshot reformatting the YAML before sending it across the CloudFormation? The templates in CloudFormation's UI seem to show that any of the short form functions are stripped out (e.g. it shows VpcId: VpcId, which is obviously going to fail...).

@geerlingguy
Copy link
Author

Same thing with any of the different Intrinsic Functions, for example:

These work:

ImageId:
  Fn::FindInMap: [Region2AMI, Ref: 'AWS::Region', AMI]
...
SubnetId:
  Fn::Select: ['0', Ref: 'Subnets']

But the short syntax versions don't:

ImageId: !FindInMap [Region2AMI, !Ref 'AWS::Region', AMI]
...
SubnetId: !Select ['0', !Ref 'Subnets']

@geerlingguy
Copy link
Author

geerlingguy commented May 9, 2017

And as an aside, after finishing the conversion from JSON to YAML... WOW it's so much easier to work with these templates.

For example, compare the YAML:

        bootstrap:
          files:
            /etc/yum.repos.d/docker.repo:
              content: |
                [docker]
                name=Docker Repository
                baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/
                enabled=1
                gpgcheck=1
                gpgkey=https://yum.dockerproject.org/gpg

...to the JSON:

          "bootstrap": {
            "files": {
              "/etc/yum.repos.d/docker.repo": {
                "content": {
                  "Fn::Join": [
                    "",
                    [
                      "[docker]",
                      "\n",
                      "name=Docker Repository",
                      "\n",
                      "baseurl=https://yum.dockerproject.org/repo/main/centos/$releasever/",
                      "\n",
                      "enabled=1",
                      "\n",
                      "gpgcheck=1",
                      "\n",
                      "gpgkey=https://yum.dockerproject.org/gpg"
                    ]
                  ]
                }
              }
            }
          },

@geerlingguy geerlingguy changed the title Shortform functions not working in YAML templates Shortform intrinsic functions not working in YAML templates May 9, 2017
@tallandroid
Copy link

Did you get a solution for this one ?

@geerlingguy
Copy link
Author

@tallandroid - We switched to running the CloudFormation templates with Ansible.

@jimohalloran
Copy link

Wanted to add that I've also run into this same issue. It's as though Moonshot when it parses/validates the YAML is stripping out the ! function calls before the template is passed to CloudFormation itself.

So for example:

Outputs:
  DrawingName:
    Value: !Sub
      - '${stack}-be-drawings'
      - { stack: !Ref 'AWS::StackName'}

... fails because the !Sub is stripped out and the Value of an output can't be a List.

This also doesn't work as expected:

Outputs:
  DrawingName:
    Value: !Sub '${AWS::StackName}-be-drawings'

This passes validation, but when you run it via Moonshot the output is set to the literal string '${AWS::StackName}-be-drawings', which is clearly not what was intended.

The same occurs with !Join, so presumably this is all CloudFormation functions when written with the ! shorthand syntax.

If I execute a stack update in the AWS console directly with either of the code samples above, it works as expected, so it seems as though it's Moonshot interfering with the YAML.

I'm running Moonshot 2.0.0beta5 on Ruby 2.5.3p105. I'm happy to provide any other details about my environment that might be required to repro this. In fact, I could supply a complete docker container if needed.

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

3 participants