Create multipleenvt.yml

This commit is contained in:
minakshi 2024-11-13 21:20:50 +05:30 committed by GitHub
parent 20720ca4f9
commit 50f5078608
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
1 changed files with 92 additions and 0 deletions

92
multipleenvt.yml Normal file
View File

@ -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