AWSTemplateFormatVersion: 2010-09-09 Description: >- This template deploys all components to support the application, with the exception of those related to BIG-IP. An autoscaling group for the application is created. Disclaimer: More realistic application template would take AMI ID as input, with AMI ID being be artifact of a build pipe line.(qs-1p2474b65) Conditions: useAppSecurityGroupId: !Not - !Equals - !Ref appSecurityGroupId - '' useStaticIp: !Not - !Equals - !Ref staticIp - '' useCustomImage: !Not - !Equals - !Ref customImageId - '' Mappings: imageRegionMap: us-east-2: AMI: ami-0a75b786d9a7f8144 us-east-1: AMI: ami-06cf02a98a61f9f5e us-west-1: AMI: ami-02676464a065c9c05 us-west-2: AMI: ami-0a248ce88bcc7bd23 af-south-1: AMI: ami-03bfd033c9d776adc ap-east-1: AMI: ami-09a8f7cf3b1b73e57 ap-south-1: AMI: ami-0dd861ee19fd50a16 ap-northeast-1: AMI: ami-0d09d267328197c99 ap-northeast-2: AMI: ami-0cf8e67d10c823f2e ap-southeast-1: AMI: ami-056251cdd6fd1c8eb ap-southeast-2: AMI: ami-05f50d9ec7e4c3b02 ca-central-1: AMI: ami-0252eebc56636a56b eu-central-1: AMI: ami-095e1a4d3d632d215 eu-west-1: AMI: ami-0d4002a13019b7703 eu-west-2: AMI: ami-0aa3620fadad9198e eu-west-3: AMI: ami-04552009264cbe9f4 eu-south-1: AMI: ami-0a84267606bcea16b eu-north-1: AMI: ami-026f0eb2e8006617d me-south-1: AMI: ami-0c49e56e4c204cc4c sa-east-1: AMI: ami-0c52a0227804a4318 Metadata: 'AWS::CloudFormation::Interface': ParameterGroups: - Label: default: Application Settings Parameters: - appDockerImageName - appSecurityGroupId - applicationSubnet - customImageId - instanceType - provisionPublicIp - sshKey - staticIp ParameterLabels: application: default: Application cost: default: Cost Center environment: default: Environment group: default: Group owner: default: Owner appDockerImageName: default: Application docker image name appSecurityGroupId: default: The resource ID of a security group to apply to the application applicationSubnet: default: Application Subnet ID used in case of standalone application instanceType: default: Must be a valid EC2 instance type for BIG-IP provisionPublicIp: default: To create a Public IP for the Application Instance. sshKey: default: Supply the public key that will be used for SSH authentication to the BIG-IP and application virtual machines staticIp: default: The private IP address to apply as primary private address uniqueString: default: Unique string Version: 1.1.0.0 Outputs: stackName: Description: application nested stack name Value: !Ref "AWS::StackName" appInstanceId: Description: Application server instance-id Value: !Ref AppInstance Parameters: appDockerImageName: Default: f5devcentral/f5-demo-httpd:latest Description: Application docker image name Type: String appSecurityGroupId: Default: '' Description: The resource ID of a security group to apply to the application. Type: String application: Default: f5app Description: Application Tag. MaxLength: 50 Type: String applicationSubnet: Default: '' Description: Application Subnet ID used in case of standalone application Type: String cost: Default: f5cost Description: Cost Center Tag. Type: String customImageId: Default: '' Description: Provide Custom Image AMI ID you wish to deploy. Type: String environment: Default: f5env MaxLength: 50 Type: String group: Default: f5group MaxLength: 50 Type: String instanceType: AllowedValues: - t2.small ConstraintDescription: Must be a valid EC2 instance type for BIG-IP Default: t2.small Description: Enter valid instance type. Type: String owner: Default: f5owner MaxLength: 50 Type: String provisionPublicIp: AllowedValues: - 'true' - 'false' Default: 'false' Description: Whether or not to provision Public IP Addresses for the Application Network Interfaces. Type: String sshKey: Description: REQUIRED - Supply the public key that will be used for SSH authentication to the BIG-IP and application virtual machines. Type: AWS::EC2::KeyPair::KeyName staticIp: Default: '' Description: The private IP address to apply as primary private address. The address must reside in the subnet provided in the subnetId parameter. ***NOTE:*** When set to empty string, DHCP will be used for allocating ip address. Type: String uniqueString: AllowedPattern: ^[a-zA-Z][a-zA-Z0-9]{1,11}$ ConstraintDescription: Must Contain between 1 and 12 alphanumeric characters with first character as a letter. Default: myUniqStr Description: Unique String used when creating object names or Tags. Type: String Resources: AppInstance: Type: 'AWS::EC2::Instance' Properties: ImageId: !If - useCustomImage - !Ref customImageId - !FindInMap - imageRegionMap - !Ref 'AWS::Region' - AMI InstanceType: !Ref instanceType KeyName: !Ref sshKey NetworkInterfaces: !If - useStaticIp - - AssociatePublicIpAddress: !Ref provisionPublicIp DeviceIndex: "0" SubnetId: !Ref applicationSubnet GroupSet: - !If - useAppSecurityGroupId - !Ref appSecurityGroupId - !Ref AWS::NoValue PrivateIpAddress: !Ref staticIp - - AssociatePublicIpAddress: !Ref provisionPublicIp DeviceIndex: "0" SubnetId: !Ref applicationSubnet GroupSet: - !If - useAppSecurityGroupId - !Ref appSecurityGroupId - !Ref AWS::NoValue UserData: !Base64 'Fn::Join': - '' - - | #!/bin/bash - | yum -y install docker - | service docker start - 'docker run --name f5demo -p 80:80 -p 443:443 -d ' - !Ref appDockerImageName - '' Tags: - Key: application Value: !Ref application - Key: cost Value: !Ref cost - Key: environment Value: !Ref environment - Key: Name Value: !Join - '' - - !Ref uniqueString - '-application-instance' - Key: group Value: !Ref group - Key: owner Value: !Ref owner