Skip to content
This repository has been archived by the owner on Oct 17, 2024. It is now read-only.

Intrinsics and Ref not working #554

Closed
scottiedog45 opened this issue Feb 14, 2023 · 4 comments
Closed

Intrinsics and Ref not working #554

scottiedog45 opened this issue Feb 14, 2023 · 4 comments

Comments

@scottiedog45
Copy link

scottiedog45 commented Feb 14, 2023

Given the following code and template, I would expect useast1-foo-qa-resources, but I get useast1-Environment-resources. I am new to the package, so might be using it incorrectly. Or, is this a bug?

package main

import (
	"fmt"

	"github.com/awslabs/goformation/v7"
	"github.com/awslabs/goformation/v7/intrinsics"
)

func main() {
	templ, err := goformation.OpenWithOptions(
		"./cf.yaml",
		&intrinsics.ProcessorOptions{ParameterOverrides: map[string]interface{}{
			"Environment": "qa",
		}},
	)
	if err != nil {
		panic(err)
	}
	res := templ.GetAllSQSQueueResources()["SomeQueue"]
	fmt.Println(*res.QueueName)
}
AWSTemplateFormatVersion: 2010-09-09
Description: The AWS CloudFormation template
Parameters:
  Environment:
    Type: String
    Description: Environment name - dev, qa, or prod
    AllowedValues:
      - dev
      - qa
      - prod
    ConstraintDescription: Must be dev, qa, or prod

Mappings:
  Constant:
    Value:
      Name: foo

Resources:
  SomeQueue:
    Type: AWS::SQS::Queue
    Properties:
      RedrivePolicy:
        maxReceiveCount: 3
      QueueName: !Join
        - '-'
        - - 'useast1'
          - !FindInMap [ Constant, Value, Name ]
          - !Ref Environment
          - 'resources'
@xrn
Copy link
Contributor

xrn commented Feb 15, 2023

Probably duplicates #551

@drmmarsunited
Copy link

drmmarsunited commented Jun 8, 2023

@scottiedog45 The issue here seems to be nested short form tags not working as expected. Also, in the template the Environment parameter doesn't have a default. I tested with the following template:

AWSTemplateFormatVersion: 2010-09-09
Description: The AWS CloudFormation template
Parameters:
  Environment:
    Type: String
    Description: Environment name - dev, qa, or prod
    AllowedValues:
      - dev
      - qa
      - prod
    ConstraintDescription: Must be dev, qa, or prod

Mappings:
  Constant:
    Value:
      Name: foo

Resources:
  SomeQueue:
    Type: AWS::SQS::Queue
    Properties:
      RedrivePolicy:
        maxReceiveCount: 3
      QueueName:
        "Fn::Join":
          - '-'
          - - 'useast1'
            - !FindInMap [ Constant, Value, Name ]
            - !Ref Environment
            - 'resources'

After template resolution with the library, here are my results, which conform to my expectations (after changing the top level join to a long form version):

AWSTemplateFormatVersion: "2010-09-09T00:00:00Z"
Description: The AWS CloudFormation template
Mappings:
    Constant:
        Value:
            Name: foo
Parameters:
    Environment:
        AllowedValues:
            - dev
            - qa
            - prod
        ConstraintDescription: Must be dev, qa, or prod
        Description: Environment name - dev, qa, or prod
        Type: String
Resources:
    SomeQueue:
        Properties:
            QueueName: useast1-foo-resources
            RedrivePolicy:
                maxReceiveCount: 3
        Type: AWS::SQS::Queue

As there is no default value for Environment, it is omitted in the joined output of useast1-foo-resources. It seems as though as long as there is no nesting of short form tags within short form tags, everything remains happy.

@rubenfonseca
Copy link
Contributor

Looking at this now, thank you so much for the great examples that help me debug the problem!

@rubenfonseca
Copy link
Contributor

Can you please try version 7.8.1 that we just released to see if it fixes the problem?

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

No branches or pull requests

4 participants