From a520ad7bc775e3a2d25b5603c5de561af43864e3 Mon Sep 17 00:00:00 2001 From: fidelis-ogunsanmi Date: Mon, 18 Jul 2022 19:22:12 -0400 Subject: [PATCH 1/3] added changes to mod 06 --- 06-auto-scaling/.gitignore | 1 + 06-auto-scaling/asg-6-1-1.yaml | 26 +++++++++ 06-auto-scaling/asg-6-1-2.yaml | 44 ++++++++++++++ 06-auto-scaling/asg-6-1-3.yaml | 45 +++++++++++++++ 06-auto-scaling/asg-6-1-4.yaml | 55 ++++++++++++++++++ 06-auto-scaling/asg-6-2-2.yaml | 54 +++++++++++++++++ 06-auto-scaling/exec.sh | 21 +++++++ 06-auto-scaling/params.json | 6 ++ 06-auto-scaling/vpc.yaml | 102 +++++++++++++++++++++++++++++++++ 9 files changed, 354 insertions(+) create mode 100644 06-auto-scaling/.gitignore create mode 100644 06-auto-scaling/asg-6-1-1.yaml create mode 100644 06-auto-scaling/asg-6-1-2.yaml create mode 100644 06-auto-scaling/asg-6-1-3.yaml create mode 100644 06-auto-scaling/asg-6-1-4.yaml create mode 100644 06-auto-scaling/asg-6-2-2.yaml create mode 100755 06-auto-scaling/exec.sh create mode 100644 06-auto-scaling/params.json create mode 100644 06-auto-scaling/vpc.yaml diff --git a/06-auto-scaling/.gitignore b/06-auto-scaling/.gitignore new file mode 100644 index 00000000..dc477e95 --- /dev/null +++ b/06-auto-scaling/.gitignore @@ -0,0 +1 @@ +fidelis.pem diff --git a/06-auto-scaling/asg-6-1-1.yaml b/06-auto-scaling/asg-6-1-1.yaml new file mode 100644 index 00000000..6e851877 --- /dev/null +++ b/06-auto-scaling/asg-6-1-1.yaml @@ -0,0 +1,26 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + +Resources: + myEc2Instance: + Type: AWS::EC2::Instance + Properties: + ImageId: !Ref LinuxAMI + InstanceType: t2.micro + KeyName: fidelis + SubnetId: !ImportValue fidelisPubSubnet + SecurityGroupIds: + - !ImportValue InstancegroupID +Outputs: + InstanceID: + Description: Instance ID of ec2 instance + Value: !Ref myEc2Instance diff --git a/06-auto-scaling/asg-6-1-2.yaml b/06-auto-scaling/asg-6-1-2.yaml new file mode 100644 index 00000000..9fce003f --- /dev/null +++ b/06-auto-scaling/asg-6-1-2.yaml @@ -0,0 +1,44 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: !Ref Ec2InstanceType + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + Properties: + MinSize: '1' + MaxSize: '1' + DesiredCapacity: '1' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet diff --git a/06-auto-scaling/asg-6-1-3.yaml b/06-auto-scaling/asg-6-1-3.yaml new file mode 100644 index 00000000..78f42c66 --- /dev/null +++ b/06-auto-scaling/asg-6-1-3.yaml @@ -0,0 +1,45 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: t2.small + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + Properties: + MinSize: '1' + MaxSize: '1' + DesiredCapacity: '1' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet + diff --git a/06-auto-scaling/asg-6-1-4.yaml b/06-auto-scaling/asg-6-1-4.yaml new file mode 100644 index 00000000..7ab6daed --- /dev/null +++ b/06-auto-scaling/asg-6-1-4.yaml @@ -0,0 +1,55 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: t2.medium + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + UpdatePolicy: + AutoScalingReplacingUpdate: + WillReplace: true + Properties: + MinSize: '1' + MaxSize: '1' + DesiredCapacity: '1' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + PropagateAtLaunch: true + - Key: "stelligent-u-lesson" + Value: "6" + PropagateAtLaunch: true + diff --git a/06-auto-scaling/asg-6-2-2.yaml b/06-auto-scaling/asg-6-2-2.yaml new file mode 100644 index 00000000..7781113a --- /dev/null +++ b/06-auto-scaling/asg-6-2-2.yaml @@ -0,0 +1,54 @@ +AWSTemplateFormatVersion: 2010-09-09 +Description: Create basic ec2 instance + +Parameters: + LinuxAMI: + Type: String + Description: AMI ID for ec2 instance + + Ec2InstanceType: + Type: String + Description: Instance Type for ec2 + + LaunchTemplateVersionNumber: + Default: 1 + Type: String + +Resources: + + MyLaunchTemplate: + Type: AWS::EC2::LaunchTemplate + Properties: + LaunchTemplateData: + KeyName: fidelis + InstanceType: t2.medium + ImageId: !Ref LinuxAMI + TagSpecifications: + - ResourceType: instance + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + - Key: "stelligent-u-lesson" + Value: "6" + + MyAutoScalingGroup: + Type: AWS::AutoScaling::AutoScalingGroup + UpdatePolicy: + AutoScalingReplacingUpdate: + WillReplace: true + Properties: + MinSize: '1' + MaxSize: '3' + DesiredCapacity: '2' + LaunchTemplate: + LaunchTemplateId: !Ref MyLaunchTemplate + Version: !Ref LaunchTemplateVersionNumber + VPCZoneIdentifier: + - !ImportValue fidelisPubSubnet + Tags: + - Key: user + Value: fidelis.ogunsanmi.labs + PropagateAtLaunch: true + - Key: "stelligent-u-lesson" + Value: "6" + PropagateAtLaunch: true \ No newline at end of file diff --git a/06-auto-scaling/exec.sh b/06-auto-scaling/exec.sh new file mode 100755 index 00000000..c7c1944b --- /dev/null +++ b/06-auto-scaling/exec.sh @@ -0,0 +1,21 @@ +#!/bin/bash + +PROFILE="labmfa" +STACK_NAME="fidelisasg" +TEMPLATE="asg-6-1-4.yaml" +PARAMETER="file://params.json" +KEY_NAME="fidelis" +REGION="us-east-1" + +# deploy stack +aws cloudformation deploy --template-file $TEMPLATE \ + --stack-name $STACK_NAME --profile $PROFILE \ + --parameter-overrides $PARAMETER \ + --region $REGION + +# create ec2 keypair +# aws ec2 create-key-pair --key-name $KEY_NAME \ +# --query 'KeyMaterial' \ +# --region $REGION --profile $PROFILE \ +# --output text > fidelis.pem + diff --git a/06-auto-scaling/params.json b/06-auto-scaling/params.json new file mode 100644 index 00000000..035a037a --- /dev/null +++ b/06-auto-scaling/params.json @@ -0,0 +1,6 @@ +{ + "Parameters": { + "LinuxAMI": "ami-052efd3df9dad4825", + "Ec2InstanceType": "t2.small" + } +} \ No newline at end of file diff --git a/06-auto-scaling/vpc.yaml b/06-auto-scaling/vpc.yaml new file mode 100644 index 00000000..59088405 --- /dev/null +++ b/06-auto-scaling/vpc.yaml @@ -0,0 +1,102 @@ +AWSTemplateFormatVersion: "2010-09-09" + +Description: This template creates an autoscaling group with EC2 instances in a VPC with 2 public subnets. The instances have an apache web server installed. + +Parameters: + + SSHLocation: + AllowedPattern: '(\d{1,3})\.(\d{1,3})\.(\d{1,3})\.(\d{1,3})/(\d{1,2})' + ConstraintDescription: must be a valid IP CIDR range of the form x.x.x.x/x. + Default: 0.0.0.0/0 + Description: The IP address range that can be used to access the web server using SSH. + MaxLength: '18' + MinLength: '9' + Type: String + +Resources: + VPC: + Type: AWS::EC2::VPC + Properties: + CidrBlock: 192.168.0.0/16 + EnableDnsHostnames: True + EnableDnsSupport: True + InstanceTenancy: default + + InternetGateway: + Type: AWS::EC2::InternetGateway + Properties: + Tags: + - Key: Name + Value: fidelisGW + + InternetGatewayAttachment: + Type: AWS::EC2::VPCGatewayAttachment + Properties: + InternetGatewayId: !Ref InternetGateway + VpcId: !Ref VPC + + PublicSubnet: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select [ 0, !GetAZs '' ] + CidrBlock: 192.168.0.0/24 + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: Public Subnet 1 + VpcId: !Ref VPC + + PublicRouteTable: + Type: AWS::EC2::RouteTable + Properties: + Tags: + - Key: Name + Value: PublicRouteTable + VpcId: !Ref VPC + + PublicRoute: + Type: AWS::EC2::Route + DependsOn: InternetGatewayAttachment + Properties: + DestinationCidrBlock: 0.0.0.0/0 + GatewayId: !Ref InternetGateway + RouteTableId: !Ref PublicRouteTable + + PublicSubnet1RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet + + InstanceSecurityGroup: + Type: AWS::EC2::SecurityGroup + Properties: + GroupDescription: Open HTTP (port 80) and SSH (port 22) + VpcId: !Ref VPC + SecurityGroupIngress: + - IpProtocol: tcp + FromPort: 80 + ToPort: 80 + CidrIp: 0.0.0.0/0 + - IpProtocol: tcp + FromPort: 22 + ToPort: 22 + CidrIp: !Ref SSHLocation + +Outputs: + VpcID: + Description: VPC ID + Value: !Ref VPC + Export: + Name: fidelisVpc + + SubnetId: + Value: !Ref PublicSubnet + Export: + Name: fidelisPubSubnet + + SecuritygroupID: + Value: !Ref InstanceSecurityGroup + Export: + Name: InstancegroupID + From 1b835f5fa81248228f53fc5efac414dbcafcd432 Mon Sep 17 00:00:00 2001 From: fidelis-ogunsanmi Date: Tue, 19 Jul 2022 12:17:37 -0400 Subject: [PATCH 2/3] added public subnet 2 --- 06-auto-scaling/vpc.yaml | 24 +++++++++++++++++++++++- 1 file changed, 23 insertions(+), 1 deletion(-) diff --git a/06-auto-scaling/vpc.yaml b/06-auto-scaling/vpc.yaml index 59088405..badca11b 100644 --- a/06-auto-scaling/vpc.yaml +++ b/06-auto-scaling/vpc.yaml @@ -46,6 +46,17 @@ Resources: Value: Public Subnet 1 VpcId: !Ref VPC + PublicSubnet2: + Type: AWS::EC2::Subnet + Properties: + AvailabilityZone: !Select [ 1, !GetAZs '' ] + CidrBlock: 192.168.0.0/24 + MapPublicIpOnLaunch: true + Tags: + - Key: Name + Value: Public Subnet 2 + VpcId: !Ref VPC + PublicRouteTable: Type: AWS::EC2::RouteTable Properties: @@ -68,6 +79,12 @@ Resources: RouteTableId: !Ref PublicRouteTable SubnetId: !Ref PublicSubnet + PublicSubnet2RouteTableAssociation: + Type: AWS::EC2::SubnetRouteTableAssociation + Properties: + RouteTableId: !Ref PublicRouteTable + SubnetId: !Ref PublicSubnet2 + InstanceSecurityGroup: Type: AWS::EC2::SecurityGroup Properties: @@ -90,11 +107,16 @@ Outputs: Export: Name: fidelisVpc - SubnetId: + PublicSubnetId: Value: !Ref PublicSubnet Export: Name: fidelisPubSubnet + PublicSubnet2Id: + Value: !Ref PublicSubnet2 + Export: + Name: fidelisPubSubnet2 + SecuritygroupID: Value: !Ref InstanceSecurityGroup Export: From ec6bbabc9f579622cff32f834fd8747d00f60163 Mon Sep 17 00:00:00 2001 From: fidelis-ogunsanmi Date: Tue, 19 Jul 2022 12:25:44 -0400 Subject: [PATCH 3/3] addded changes --- 06-auto-scaling/exec.sh | 4 ++-- 06-auto-scaling/vpc.yaml | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/06-auto-scaling/exec.sh b/06-auto-scaling/exec.sh index c7c1944b..fd0686db 100755 --- a/06-auto-scaling/exec.sh +++ b/06-auto-scaling/exec.sh @@ -1,8 +1,8 @@ #!/bin/bash PROFILE="labmfa" -STACK_NAME="fidelisasg" -TEMPLATE="asg-6-1-4.yaml" +STACK_NAME="fidelisvPC" +TEMPLATE="vpc.yaml" PARAMETER="file://params.json" KEY_NAME="fidelis" REGION="us-east-1" diff --git a/06-auto-scaling/vpc.yaml b/06-auto-scaling/vpc.yaml index badca11b..ea7868ae 100644 --- a/06-auto-scaling/vpc.yaml +++ b/06-auto-scaling/vpc.yaml @@ -50,7 +50,7 @@ Resources: Type: AWS::EC2::Subnet Properties: AvailabilityZone: !Select [ 1, !GetAZs '' ] - CidrBlock: 192.168.0.0/24 + CidrBlock: 192.168.1.0/24 MapPublicIpOnLaunch: true Tags: - Key: Name