https://aws.amazon.com/cloudformation/, an Infrastructure as Code (IaC) service that lets you model, provision, and manage AWS and third-party resources, recently released https://aws.amazon.com/blogs/mt/introducing-new-language-extensions-in-aws-cloudformation/. These new language extensions are the result of open discussions with the larger CloudFormation community via our Request For Comments (RFC) proposals for new language features at our Language Discussion https://github.com/aws-cloudformation/cfn-language-discussion.

Resources: Ec2Instance: Type: AWS::EC2::Instance Properties: ImageId: !Ref 'LatestAmiId' InstanceType: !FindInMap - LifecycleEnvToInstanceType - !Ref 'Environment' - InstanceType - DefaultValue: t2.micro Tags: - Key: test Value: test

With this, we can then use our new Fn::ForEach functionality and FindInMap enhancements: Resources: Fn::ForEach::Instances: - InstanceLogicalId - [FirstInstance, SecondInstance, ThirdInstance] - ${InstanceLogicalId}: Type: AWS::EC2::Instance Properties: ImageId: !Ref LatestAmiId InstanceType: !FindInMap - !Ref Environment - !Ref InstanceLogicalId - InstanceType - DefaultValue: t2.micro

Fn::ForEach::Subnets: - SubnetIdentifier - - SubnetOne - SubnetTwo - SubnetThree - Fn::ForEach::SubnetAvailabilityType: - AvailabilityType - !Ref AvailabilityTypes - "${SubnetIdentifier}${AvailabilityType}": Type: AWS::EC2::Subnet Properties: CidrBlock: !FindInMap - !Ref SubnetIdentifier - !Ref AvailabilityType - Cidr which outputs the following resource section: Resources: VPC: Properties: CidrBlock: !Ref VpcCidr EnableDnsSupport: true EnableDnsHostnames: true

Related Articles