aws-cloudformation / aws-cloudformation-samples

Apache License 2.0
134 stars 55 forks source link

More about modules #108

Closed marconWillianNeves closed 2 months ago

marconWillianNeves commented 2 months ago

You can add a example of who I can set a required parameters on module?

And a regex validation?

mrinaudo-aws commented 2 months ago

Hi @marconWillianNeves - thank you for your question!

Today, modules don't support constraint enforcement; for more information on this modules-specific topic, see Specifying constraints for module parameters in Using modules to encapsulate and reuse resource configurations.

What you can do today though, per the above, is to set up constraints you need in the parameters you configure in your CloudFormation template that consumes the module. In your module, you then reference the parameters and their type. In other words, today you can perform parameter validation on the CloudFormation template itself and not in the module.

For example, the sample template that consumes the sample EC2ImageBuilderGoldenAMI module in this repository defines template parameters (in the Parameters section of the template) with a number of constraints; the module fragment references such template parameters without using constraints.

As per the regex validation, you'd do that also in template parameters. For more information, see Using regular expressions in AWS CloudFormation templates and AllowedPattern in Properties.

Hope that helps! Feel free to reopen this issue should you have any questions!