‫So, if we look at the first template
‫we've been using, called 0-just-ec2.yaml,
‫we've been seeing it's a very simple template,
‫and we'll look at the structure of it
‫in detail in the future lectures,
‫but just from reading it,
‫I think it's quite clear we are creating resources
‫called MyInstance of type EC2::Instance,
‫and in terms of properties,
‫we specify the AvailabilityZone, the ImageId,
‫so the AMI ID,
‫and this is why we have to use us-east,
‫and because we also specify
‫the AvailabilityZone, specifically.
‫And finally, the instance type t2.micro.
‫Now what we want to do is to update the stack,
‫and so I've created a second stack called ec2-with
‫security group called eip.
‫So, that means that here we're going
‫to have a lot more complicated template.
‫I won't go over it too much,
‫but we are adding a parameter.
‫We're adding, we're changing
‫a little bit of that EC2::Instance.
‫We're adding an elastic IP.
‫We're adding a security group
‫and a second security group.
‫So, we can expect a lot of updates.
‫So, lets see how we can go in CloudFormation
‫and apply this update.
‫So we're going here
‫and then click on updates.
‫And then, you have to choose how you're going to update.
‫You're going to use the current template,
‫replace it or edit it.
‫I'm going to replace the template,
‫upload a new file,
‫and this time, I'm going to upload the
‫file: 1-ec2-with-sg-eip.
‫So, the file is being loaded.
‫It's uploaded onto Amazon S3
‫and then, I can click on next.
‫Now, I get prompted
‫with entering the value of a parameter.
‫That's because we have to find a new section
‫in our template.
‫And so, we'll say: "This is a cool security group"
‫and this is intended to become
‫my security group description.
‫So, I click on next,
‫and in terms of tag options,
‫we'll leave the tag permissions and so on, as is.
‫We're not turning anything new here.
‫And now, we review everything.
‫So, the template, the parameter's values.
‫So, this is great, we scroll down
‫and at the bottom we have something called:
‫a change set preview.
‫So, this is CloudFormation figuring out
‫from the original template, okay.
‫So, from this template right here
‫to this new template right here,
‫what is the difference?
‫What are the differences
‫and what needs to change?
‫So, as we can see here,
‫an elastic IP needs to be added,
‫and the EC2::Instance needs to be modified,
‫and the replacement, true.
‫So that means the previous EC2::Instance will be terminated
‫and a new one will be created.
‫That's because replacement is true.
‫If the replacement was false,
‫that means the EC2::Instance will stay in place.
‫So, as we can see, we have three new things:
‫an elastic IP and two security groups,
‫and we have the EC2::Instance being modified
‫and even replaced.
‫So, if we are happy with this changed set,
‫with these changes in advance,
‫then we can click on update stack
‫and we're good to go.
‫So, we go back into the events,
‫and as we can see now, this stack
‫is in update_in_progress, the status,
‫and we need to just wait and see, what happens.
‫So, I'm going to refresh this page
‫and as we can see now,
‫two security groups are created for me.
‫So, the create is complete.
‫And then, if I keep on refreshing,
‫my EC2::Instance will be updated.
‫So, as we can see,
‫there's a new creation of a new physical EC2::Instance
‫because replacement was true.
‫So, we need to wait for this.
‫So if I go back to my EC2:Instance page
‫and refresh, I should see, yes
‫my second instance being created right now,
‫due to this update,
‫and so a cool thing to see is that,
‫the EIP is not being created yet.
‫The reason is, CloudFormation,
‫even though we haven't specified an order
‫of which resources should be created,
‫knows from the Stack template,
‫what to create first.
‫So it knew to create the first security groups,
‫then to update the EC2::Instance,
‫and finally, it will add an elastic IP.
‫So this is something CloudFormation does for you,
‫and figures out the right order
‫for your template creation.
‫So, really, really cool.
‫Now I need to wait for everything to be created.
‫So, MyInstance is now created
‫and now we're getting into the
‫elastic IP creation process.
‫So, the create is in progress,
‫and we should be done very, very soon.
‫And so, as soon as we're done,
‫well, we expect the replacement to be complete.
‫So, we expect our previous EC2::Instance
‫to be terminated.
‫So, lets just refresh again to see how we are.
‫Yes, the ESP has been created.
‫Now the first stack is in update complete,
‫clean up in progress,
‫and during this cleanup,
‫my previous EC2:Instance is being deleted.
‫So that means that my previous EC2::Instance in here,
‫should be shutting down,
‫and then being terminated.
‫So, it's really cool.
‫This CloudFormation template
‫did a lot things for us
‫based on just a few lines of code,
‫of yaml description code.
‫Okay, so you if go into resources now,
‫we can see we have a lot more things.
‫We have a link to the elastic IP,
‫the EC2::Instance and these two security groups.
‫And so, if we check it out,
‫let's just click on the EC2::Instance right now.
‫So, I'm taken to the EC2::Instance directly,
‫and what I can see is that yes, indeed,
‫an elastic IP is attached to it.
‫So, if I click on the elastic IP,
‫I can see it is right here,
‫and if I look at this elastic IP,
‫and look at the tags, for example,
‫we can see it is again,
‫tagged by CloudFormation.
‫So, just like my EC2::Instances,
‫this one is tagged,
‫and we can also have a look at our security groups.
‫So, here we have two security groups.
‫So I'm going into my two security groups
‫and I'm going to just look for the word:
‫stack, here we go,
‫we have two security groups created for me.
‫So we have our SSH security group
‫which contains an inbound rule
‫for the SSH,
‫and we also have a server security group
‫which contains a rule for Port 80.
‫Okay, and then finally, if we look at the description
‫of this security group,
‫it says, "This is a cool security group."
‫So, that means that the parameter
‫is somehow that we defined in here
‫and we gave a value to,
‫was applied to the value of the description
‫of that security group,
‫and we'll see how that works as well,
‫later on in this section.
‫So, very, very cool.
‫We've created our CloudFormation template
‫and updated it.
‫So now what we can do,
‫is look at deletion.
‫So, if we go into our CloudFormation stack,
‫and we're happy where were are,
‫one way we can do things
‫is go into your instances,
‫right-click here,
‫and then terminate it,
‫but the problem with this is that,
‫as soon as you do this,
‫then, your other things that were created
‫by CloudFormation still remain.
‫So, that includes your security groups
‫and that includes your EC2,
‫and your elastic IP address.
‫So, what we can do instead,
‫is to take this CloudFormation stack
‫and then we can click on delete.
‫And by doing so,
‫it will delete everything in our CloudFormation stack.
‫So, I'll just click on delete stack
‫and then, CloudFormation will go into
‫delete in progress.
‫And again, if we look at the event list,
‫it knows what to delete first.
‫So, it's going to delete the elastic IP first,
‫then it will go ahead
‫and delete the EC2::Instance.
‫And finally, it'll go ahead
‫and delete the security groups.
‫And that's the whole power of CloudFormation.
‫It is very easy to create resources,
‫update them, but as well
‫delete them, without trying to figure out
‫in which order to do things.
‫So, as soon as you go and do infrastructure AS-code.
‫It is extremely important for you
‫to understand that every resource
‫creation, update and delete
‫has to happen through CloudFormation,
‫and when you get the hang of it,
‫it becomes really, really handy
‫and something you will no be able to go back to.
‫So, I'll just wait for this stack to be deleted,
‫but it should work on my end
‫and I will see you in the next lecture.