diff --git a/multipleenvt.yml b/multipleenvt.yml new file mode 100644 index 00000000..5a310fa2 --- /dev/null +++ b/multipleenvt.yml @@ -0,0 +1,92 @@ +AWSTemplateFormatVersion: +'2010-09-09' +Description: AWS CloudFormation Template for Dev,Stage,Prod Enviornments + +Parameters: + Enviornment: + Description: The enviornment to deploy(dev,stage.prod) + Type: String + AllowedValues: + :dev + :stage + :prod + Default:dev + +Resources: +MyVPC: + Type: AWS::EC2::VPC + Properties: + CidrBlock:!If + :lsProd + :10.0.0.0/16 + :!If + :lsStage + :10.1.0.0/16 + :10.2.0.0/16 + EnableDnsSupport:true + EnableDnsHostnames:true + Tags: + Key:Name + Value:!Sub"${Enviornment}-vpc" +MyInternetGateway: + Type: AWS::EC2::InternetGateway +AttachGateway: + Type: +AWS::EC2::VPCGatewayAttachment + Properties: + VpcId:!Ref MyVPC + InternetGatewayId:!Ref MyInternetGateway +PublicSubnet: + Type: AWS::EC2::Subnet + Properties: + VpcId: !Ref MyVPC + CidrBlock:!If + :lsProd + :10.0.1.0/24 + :!If + :lsStage + :10.1.1.0/24 + :10.2.1.0/24 + MapPublicIpOnLaunch:true + AvailabilityZone:!Select[0,!GETAZs"] +PublicRouteTable: + Type:AWS::EC2::RouteTable + Properties: + VpcId:!Ref MyVPC +PublicRoute: + Type: AWS::EC2::Route + Properties: + RouteTableId:!Ref PublicRouteTable + DestinationCidrBlock:0.0.0.0/0 + GatewayId:!Ref MyInternetGateway +PublicSubnetRouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + SubnetId:!Ref PublicSubnet + RouteTableId: !Ref PublicRouteTable +MyEC2Instance: + Type: AWS::EC2::Instance + Properties: + InstanceType:t2.micro + ImageId:ami- + SubnetId:!Ref PublicSubnet + KeyName:my-key + Tags: + Key:Name + Value:!Sub"${Enviornment}-instance" + Conditions: + lsProd:!Equals[!Ref Enviornment,prod] + lsStage:!Equals[!Ref Envionment,stage] + +Outputs: + VPCId: + Description:VPC Id + Value:!Ref MyVPC + SubnetId: + Description:PublicSubnetId + Value:!Ref PublicSubnet + InstanceId: + Description:EC2InstanceId + Value:!Ref MyEC2Instance + +