aws-cloudformation / aws-cloudformation/cloudformation-coverage-roadmap

Conditions in CloudFormation Output Naming Confict issue

Open
#1,768 2 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
No language data
Stars
1.1k
Forks
62
PR merge metrics
No merged PRs in 30d

Description

### Name of the resource

AWS::CloudFormation::Stack

### Resource name

_No response_

### Description

We know that for logical ID in CloudFormation template should be unique. However, if using conditions in the output section, two output have the same logical ID would not resolve a Create/Update failure, instead, if does not show the output value as expected.

Here is the template that I used to test:
++++++++++++++++++++++++++
AWSTemplateFormatVersion: 2010-09-09
Description: AWS CloudFormation workshop - Conditions at Outputs level (uksb-1q9p31idr).

Parameters:
LatestAmiId:
Type: 'AWS::SSM::Parameter::Value'
Default: /aws/service/ami-amazon-linux-latest/amzn2-ami-hvm-x86_64-gp2
EnvType:
Description: Specify the Environment type of the stack.
Type: String
AllowedValues:
- test
- prod
Default: test
ConstraintDescription: Specify either test or prod.

Conditions:
IsProduction: !Equals
- !Ref EnvType
- prod
IsNotProduction: !Equals
- !Ref EnvType
- test

Resources:
EC2Instance:
Type: 'AWS::EC2::Instance'
Properties:
ImageId: !Ref LatestAmiId
InstanceType: t2.micro
MountPoint:
Type: 'AWS::EC2::VolumeAttachment'
Properties:
InstanceId: !Ref EC2Instance
VolumeId: !Ref Volume
Device: /dev/sdh
Condition: IsProduction
Volume:
Type: 'AWS::EC2::Volume'
Properties:
Size: 2
AvailabilityZone: !GetAtt EC2Instance.AvailabilityZone
Encrypted: true
Condition: IsProduction

Outputs:
VolumeId:
Value: !Ref Volume
Condition: IsProduction
VolumeId:
Value: !Ref EC2Instance
Condition: IsNotProduction
+++++++++++++++++++++++++++++++++++++++++++++
1. With the above template, I have defined the output "VolumeId" twice in the template, the stack deployed successfully. It shows output value when I was in "test" condition, but it does not show value when I was in "prod" condition.
2. I have changed the second "VolumeId" to "EC2Id", and the stack update successful, and the output value shows for each condition.

Therefore, I am requesting is there should throw an error to not let the creation/update completed? Or giving some notifications on the naming conflicts?

### Other Details

_No response_

Contributor guide

Open the contributing guide

Research direction

Start by reproducing the supplied CloudFormation template, focusing on the duplicate VolumeId entries under Outputs and their IsProduction and IsNotProduction conditions. Compare deployment behavior with the version using EC2Id. Done means the duplicate output naming is rejected or clearly reported during creation or update, with behavior covering both conditions.

Written by the indexing model from the issue text.

Assessment

Tech stack
aws, yaml
Domain
cloud, infrastructure
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.