aws-cloudformation / cfn-language-discussion

Language discussions for CloudFormation template language
https://aws.amazon.com/cloudformation/
Apache License 2.0
143 stars 13 forks source link

Feature request for dynamic evaluation of conditions. #132

Open reidca opened 1 year ago

reidca commented 1 year ago

Community Note

Tell us about your request

What do you want us to build? The ability for conditions to work using a dynamic element within the template.

Tell us about the problem you are trying to solve. What are you trying to do, and why is it hard?

I was writing a template where I needed to decide whether to create a resource based on whether there was an existing resource already in the account with the same name. In this case it was an IAM role however it could be anything.

Whilst conditions can be used to determine whether to create a resource, these can only be influenced by parameter values which are static for the template. When operating at scale using Stack Sets across many accounts it is impractical to alter the parameter value for each individual account.

I know CloudFormation does not have the ability to determine whether something exists, (that in itself could be another feature request), however it does have the ability to use Custom Resources that can do this check for you. However, a custom resource with a bool value indicating whether something exists or not cannot be used to influence the evaluation of a Condition. This is because conditions currently do not allow inputs from the Resources section.

Are you currently working around this issue?

I create a horrible hack where I would check to see whether something existed using a custom resource then would return an alternative name if it did and then use this name for the resource so as to not clash with the existing resource. This results in a useless resource being created.

What is the expected behavior with this new feature

Conditions that can be influenced by the output from a resource, or some other way of dynamically determining whether something should be created or not.

Additional context

Everyone who I talk to about this problem says use Terraform however this is not the answer when you already have a large deployment of CloudFormation and wish to have the server side state advantages and integration that CloudFormation brings.