aws-cloudformation / cloudformation-coverage-roadmap

The AWS CloudFormation Public Coverage Roadmap
https://aws.amazon.com/cloudformation/
Creative Commons Attribution Share Alike 4.0 International
1.11k stars 57 forks source link

Change CFN behavior when there are two output elements of the same name and affected by conditions. #478

Open bbergero opened 4 years ago

bbergero commented 4 years ago
  1. Title -> Change CFN behavior when there are two output elements of the same name and affected by conditions.

  2. Scope of request -> Currently two outputs like:

    "Output1" : {
       "Condition" : "IsCondition",
       "Value" : "SomeValue"
    },
    "Output1" : {
       "Condition" : "IsNotCondition,
       "Value" : "OtherValue"
    }

    No output is created.

  3. Expected behavior -> The expected behavior would be that if more than one output by the same name is defined AFTER conditions as applied, then an error should be produced, and if only one resulted, that would be the one being created. We try to use this scheme to have a template produce different outputs depending on a condition that affected the resources that got created. We work around this issue using exports with the same name in two outputs of different names, but in some scenarios, such as when using Terraform data sources, the output name is what gets exposed and would need to be the same. In any case, the behavior of not producing any error but silently missing the output, creates errors further down the deployment pipeline that are harder to diagnose.

benbridts commented 4 years ago

@bbergero You can use the Fn::If function in the output value. Here is a snippet and a full example in yaml:

Output:
    Value: !If [IsCondition, "SomeValue", "OtherValue"]

---
Parameters:
  OutputSelector:
    Type: String
    Default: First
    AllowedValues:
    - First
    - Second
Conditions:
  IsFirst: !Equals [!Ref OutputSelector, "First"]
Resources:
  Dummy:
    Type: AWS::CloudFormation::WaitConditionHandle
Outputs:
  Output:
    Description: Based on OutputSelector
    Value: !If [IsFirst, "First selected", "Second selected"]
luiseduardocolon commented 4 years ago

@bbergero were you able to use the suggestion from @ikben ? Do you get any error from the linter?

bbergero commented 4 years ago

Awaiting from DXC, thanks

Regards,

Bernard

Bernard Bergeron Partner Solution Architect Amazon Web Services [1]https://pages.awscloud.com/remote-learning-partners.html Learn More >> https://pages.awscloud.com/remote-learning-partners.html [signature_1031148478]https://www.certmetrics.com/amazon/public/badge.aspx?i=1&t=c&d=2016-03-17&ci=AWS00180058[signature_1319527369]https://www.certmetrics.com/amazon/public/badge.aspx?i=4&t=c&d=2018-03-16&ci=AWS00180058 [signature_1939587076]https://twitter.com/awscloud [signature_1078948150] https://www.facebook.com/amazonwebservices [signature_1827324250] https://www.youtube.com/user/AmazonWebServices https://aws.amazon.com/new https://aws.amazon.com/blogs/aws/ https://aws.amazon.com/podcasts/aws-podcast/ https://aws.amazon.com/resources/analyst-reportshttps://aws.amazon.com/resources/analyst-reports/?nc1=f_cc&analyst-reports-main.sort-by=item.additionalFields.datePublished&analyst-reports-main.sort-order=desc https://aws.amazon.com/getting-started/use-cases/

We’re hiring!!!https://aws.amazon.com/careers/ Thoughts on our interaction? Provide feedback herehttps://feedback.aws.amazon.com/?ea=bbergero&fn=Bernard&ln=Bergeron.

From: Luis Eduardo Colon notifications@github.com Reply to: aws-cloudformation/aws-cloudformation-coverage-roadmap reply@reply.github.com Date: Friday, 29 May 2020 at 02:09 To: aws-cloudformation/aws-cloudformation-coverage-roadmap aws-cloudformation-coverage-roadmap@noreply.github.com Cc: Bergeron Bernard bbergero@amazon.co.uk, Mention mention@noreply.github.com Subject: Re: [aws-cloudformation/aws-cloudformation-coverage-roadmap] Change CFN behavior when there are two output elements of the same name and affected by conditions. (#478)

@bbergerohttps://github.com/bbergero were you able to use the suggestion from @ikbenhttps://github.com/ikben ? Do you get any error from the linter?

— You are receiving this because you were mentioned. Reply to this email directly, view it on GitHubhttps://github.com/aws-cloudformation/aws-cloudformation-coverage-roadmap/issues/478#issuecomment-635698825, or unsubscribehttps://github.com/notifications/unsubscribe-auth/AEKYBSZIZYE73TYWF5AQTY3RT4DNTANCNFSM4NGDDCYQ.

Amazon Web Services EMEA SARL, 38 avenue John F. Kennedy, L-1855 Luxembourg, R.C.S. Luxembourg B186284

Amazon Web Services EMEA Sarl, UK Branch, 1 Principal Place, Worship Street, London, EC2A 2FA, United Kingdom, registered in England and Wales, UK Establishment No. BR019315

benbridts commented 4 years ago

@luiseduardocolon IIRC I was able to deploy that example

gbourniq commented 3 years ago

This works!