I hope you can all hear me okay I'm so excited to be doing this project with you all it is all about terraform I think terraform has been one of the most in demand project topics that we've ever received and it's really cool that we get to now do our very very first introductory project together so this project is called create S3 buckets with terraform I promise you it is completely beginner friendly no terraform experience required no infrastructure as code experience required come as you are um and let's get started so when you arrive at the project page and the link to that is also in the description box you can unlock Pro this project and it looks gorgeous so we are going to be taking about 60 Minutes in today's project it is easy peasy lemon squeezy and we'll we'll be doing every single step together too um the services you'll be using today are terraform Amazon S3 awscli and AWS I am okay so all of these these four services are all going to play a very important role for us to create S3 buckets with terraform today okay so you might be wondering okay I've been hearing terraform all over the show I know that terraform is huge but I actually don't know what ter ter form does um so if that's you this is the right place to be okay so terraform is a way for you to automate the deployment or the management of the resources in your environment or really you can say it helps manage your it infrastructure in a very automated way you might be familiar with creating resources in the console you might have gone on the console before click click click launch launch launch delete delete delete and and you might have eventually graduated into using the CLI type type type launch launch launch delete delete delete you realize that you can do it all using text commands now with terraform it's almost like the next level up okay so from console you went to CLI now terraform is kind of this next level up of being able to Now launch delete manage your resources from configuration files why are configuration files so cool you know why do people love terraform so much much the big reason for this is because one you can save a lot of time by just writing one single file of all of the resources that you want how you want them to be set up and just deploy it straight away and boom terraform will go ahead and launch all of those resources in in the perfect way for you another reason why terraform is so good is because it's so consistent because you have a one single file defining what you want and how you want it what that means is every single time you use that you will be having a very consistent outcome every single time you launch the same file the same resources get get created now this is actually a much preferred way of managing your resources because the manual way you know using the console using the CLI invites a lot of opportunity for you to make a maybe a human error oh when I was like using the console I forgot to use this setting instead of this one oh I forgot to uncheck this checkbox it's so easy to to make those mistakes in in the CLI it's so easy to accidentally have a typo or accidentally forget a certain parameter when you're trying to repeat the same step but when it's all saved in one file of course you'll be able to save those settings and just deploy again and again and again um in a very consistent way okay so in the real world automation is really key in staying efficient in how you develop and deploy code it's also how develops teams cut out the manual work of creating new resources and the cloud environment which reduces the chances of Errors so that was a that's a really great summary of the longer intro I just went on for a second there a big shout out to Eric in the chat by the way hi Eric Eric says hello from Bolivia thanks for these tutorials well thank you so much Eric it's so good to have you here um it's really heartwarming to hear you say hi um Eric I'm gonna make a big request if you ever see that my audio is a bit loud or it's dropping please let me know in the chat chat as well um I'm going to be relying on you today um and for anyone else tuning in um just know that you know if you need me to go a bit faster go maybe speak a bit louder we're always here to adjust in real time okay so in this project we're going to get ready to install and configure terraform so you don't even need to have terraform in your computer yet we're going to learn how to install it and then we're going to learn how to configure your AWS credentials in the terminal so if you're familiar this means configuring AWS CLI in your local computer then we're going to be creating some S3 buckets and then we're going to be learning how to manage those buckets using terraform okay secret mission is that we'll get to upload those files using terraform upload files to the S3 bucket using terraform too so this is a uh this diagram really summarizes those steps that we're about to go through first is just even setting up terraform we need to install it first we need to set up our local computer to to be able to have a terraform project and then we're going to be doing something called planning your terraform configuration now the the the very concise explanation for planning is it's basically asking terraform hey with all the configuration I've set up can you repeat back to me how it's going to be affecting my AWS environment how is it going to be affecting my infrastructure can you just tell tell me what changes are going to happen to my account when I run what I've written up and there's going to be a bit of troubleshooting and this is for the people who don't have AWS CLI set up yet so we'll be taking one extra step where we're installing something called AWS CLI and then we're setting up AWS access Keys all of this so that we can run or use or get access to our AWS environment right from your local computers terminal so you don't need to into the console anymore just access your AWS environment from the terminal itself from your local ter computer's terminal um and yeah we're going to we're going to apply our terao configuration again um once you've solved this issue this troubleshooting and then we're going to launch an S3 bucket at the very end of it so when it's all successful you're going to see a beautiful new S3 bucket in your AWS account and yeah all of this without really using the console which is really satisfying um so shall we dive into it all right we're going to go for the high touch mode and this means that we're going to go through every single step together every single click every single thing you should be writing all of that together but if when you're ready to challenge yourself to do some parts of it on your own go for low Touch where you have a little few less fewer steps um and then no touch where pretty much none of the steps are guided but you we kind of tell you like this is the general goal this is what you need to do but we're not going to tell you where to click we're not going to tell you what to write um we'll start with high touch though we'll take it slow all righty so before we start step one it's always a good idea to recap what we're here to do today so let us answer this magic question in this project what do we here to do in this project project we will demonstrate using terraform to launch we will demonstrate how to use terraform to launch an bucket yeah the goal is to um Dina the goal is to install plus set up terraform what else are we doing troubleshoot any errors IE installing the CLI and then successfully plan plus apply our terraform configuration to launch and then successfully apply our terraform configuration to launch a bucket oh I think I might run out of characters guys please don't run out of characters that's so satisfying y'all all right so that's what we're doing today in this project we're going to demonstrate how to use terraform to launch an S3 bucket the goal is to install and set up terraform and then we're going to troubleshoot any errors which comes with wanting to install the CLI then we're going to successfully apply apply our tarform configuration to launch a bucket all sounds good team I hope so all right so uh I have been demonstrating these steps our project guide from the main screen but I'm actually just about to zoom away so that we can actually focus on the console or on the main terminal uh for the remaining of this project and that means I'll be writing the answers the responses to questions from this screen instead so let me actually copy this over all right and we're going to select done great all right and now we're ready to kick off okay let's kick things off by installing terraform our tool for building and managing infrastructure as code all right what is terraform we have a bit of an explanation about ter form and infrastructure as code here let's dive into it in a second I think it's going to be extra cool if I talk about it over this first step which is to head to the official terraform download page okay let's get started team oops I AC closed the wrong tab no no this isn't supposed to happen let me open that up again oh that's so funny well um I'll be quickly doing doing a cheeky setup you you'll see me set this up on the spot now um but this is such a bad habit of mine everyone I I always accidentally select the wrong window to close when I close something um I'll be more careful from now on I promise all right I'm going to just adjust the adjust this project screen so that the font is a little bit bigger so it's easier to see um so let's go for that now all righty okay I think this phone size is looking better okay good and then we have landed in our first step again installing terraform and let me properly get to the download page from our main screen okay so we're here now so the first step of this um the first part of the step is that we're we're going to just head to the download page for terraform and this is where we can have a little yarn you know like we've mentioned before terraform is a tool that helps you with building and managing your Cloud infrastructure using Code um so instead of clicking around in the console or using the CLI you're writing a piece of code that tells terraform exactly what you want in your Cloud infrastructure you could say hey terraform I want in my cloud infrastructure a new ec2 instance called this I want a new S3 bucket called this I want a VPC can you also make sure that it has this security group setting can you also make sure you have this network ACL setting I also want to launch these containers I want to be using this resource I want to create an i user you tell ter for exactly what you want and how you want to set those resources up and then terraform will read the entire script it's going to say okay I can see that you want this and you currently have this in your AWS infrastructure let me compare the two okay so you want this bucket you don't have this bucket right now in your current infrastructure let me build that for you oh okay you want this easy2 instance oh I can see you already have an ec2 instance with that name but I can see that what you want is a that you want to add this setting to your ec2 instance that you don't already have so let me do that for you all it goes and builds it um what what's another example you could also say oh terraform I already have this ec2 instance I also have the settings set up but I want to change this setting I want to go from this instance type maybe to another one I want to use something else to build this let's go and let's go and build it um and then you'll just you'll just write what you want in your terraform file and in terra's job is to read that file compare it with your current infrastructure and then go and build it so that your current infrastructure has everything that you've written out in your wish list and what you want so thank you terraform for almost being like a like a Santa Claus for our infrastructure we just write our like Dear Santa dear terraform I want this in my infrastructure and then terraform goes and delivers it so because of because of this terraform is known as a very very popular infrastructure as code tool and what infrastructure as code means is is essentially um what terraform does which is to use code to set up your infrastructure and your resources so it's kind of like saying if you've used AWS before it's like saying AWS is a top cloud service provider terraform is a top infrastructure is cod tool so yes that means terraform is not the only only tool out there in the world that can do infrastructure as code for you you can use other providers to write out what you want in code and then tell that provider or tell that tool to to deliver that or build that for you so why is it that terraform is the top you know why is it so good it's because it supports multiple Cloud providers which means it's Cloud agnostic you can use terraform to create resources in AWS Azure Google class platform and you can even just manage it all with the same language which actually makes things really really easy in the real world you're not really likely to see a huge company a huge operation all just using a sole cloud service provider it's becoming more of a thing that companies actually touch at least two maybe even three so that they can get the best out of each cloud service providers services so because of that it's now become more of a trend for you to use form because it is it supports multiple Cloud providers and it can it can help you create all these different resources across everything using the same system the same configuration um tool you know compare that with um aws's cloud formation tool which is also infrastructure as code you use cloud formation to write yaml files that tell AWS what you want in your a AWS infrastructure but because it is AWS only you can't use cloud formation for example to create resources in Azure um so really goes to show why terraform is so loved um and terraform also uses a pretty simple configuration language that we're about to see okay so that is your overview of terraform and step one is all about just downloading and installing terraform in this step we will install terraform into our local computer because we need a local terraform file to use it I.E run commands locally great so now that we're here it's time for you to select which package you want for your operating system you'll notice that it's not just like one download for Windows one download for Linux so on and so forth so so please use these instructions to figure out which of the options underneath your operating system you should pick for myself I know I'm using a m64 arm64 under Mac OS so I'll be downloading that one great and we'll take a screenshot of the installation page before we move on yeah tell the world you've been here you're installing terraform well let me refresh this page hopefully it's a little kinder to me when I take that screenshot not really that's okay I was really hoping that I can see the um the terraform logo at the top I was honestly just wanting to get that but it's okay um I can take my screenshot without it it's still going to look pretty cool and make sure to drag your screenshot into the project guide nice so what is terraform so this is where we can say terraform is what's terraform terraform is a tool for managing our it resources using Code you can use terraform you use ter you use teror form to process a configuration file you've prepared that details that details the desired state of your infrastructure terraform then builds to set up that desired State oh I would say actually terraform then creates maybe updates deletes to set up that desired State nice I think that's better okay so what is infrastructure as code terraform is one of the most popular tools use for infrastructure as code which is which is what do you think before I write down my response what do you think uh infrastructure's code is okay infrastructure is code is a way to manage your it structure instead of manually managing resources using the console or text commands and CLI IAC automates that process with code great so once we've downloaded terraform it's time to open up our our beautiful package yeah I think we're ready um so let's open up that package you can see it in your downloads folder okay it's going to look like this and we're about to do something funky called moving that terraform binary to a path two funny words here that you might be feeling a a bit new to binary and path a terraform binary is this core file that you use to run terraform it's called an executable file okay a binary is an executable file which means your operating system executes that file or runs that file to run the commands um that it covers so what that means is when you when you run a command in your terminal that says terraform something or AWS something who who is the actual file or who is the actual like application that is running those commands for you your terminal doesn't inherently know how to run those commands you had to install terraform for example so it's actually the terraform binary that is actually capable of running those commands for you and your terminal is simply kind of like the engine that's powering that application that's now going to be running your command so that's why the tarform binary is so important um it's not like we're just giving our terminal suddenly the powers to run terraform commands it's more that when we run terraform commands there's a specific application or specific software that's doing that running for us and that software is the binary okay so you can even see it here look at that even says little exec it's a nice little surprise um it says exec at the top left which goes to show that it's an executable file okay and we're adding this to our path so a path is a list of directories in your computer the whole reason why it exists is so that when you run a terraform command or when you run an AWS command you can run that command successfully from anywhere in the terminal the way the terminal Works can be a little funky sometimes where when you want to run a file that file needs to be in your current directory or you to specify how to get there you know from your current directory for example um I can't just from here in my computer say oh let me run Google Chrome like I I can't just do it from here I kind of have to go search and then I have to search for Google Chrome and then I have to find Google Chrome and I have to open Google Chrome or I have to go into into my applications folder um and then find Google Chrome from my list of applications you know so so it's not like even when we're using clicks on our computer we can't just run any file from anywhere we sometimes need to be able to find that file locate it you know locate it okay find it and then click and open it it's kind of the same for your terminal your terminal doesn't just know where every single file is and be able to run it from anywhere it needs to locate it from its current place from its current directory so when we have a path we're basically writing this massive list of directories that says okay the teram file is here um the AWS file is here we're setting all of this up in this really really um neat little folder that is going to let your terminal find your file from anywhere anywhere that it is this way you won't have to type out the full path to your terraform software every time you try to run a terraform um command you're going to see this in a second how easy it is to run commands because you've been able to um add this file to your path all right so the instructions for moving that terraform binary so this thing um depends on your operating system and I'm running a Mac so I'll be using option one if you're using Windows please skip all of this and go straight to option two here below here great all right so what's happening in the world of Max and Linux to be able to move this file to our out path we're going to be opening the terminal let me zoom in for us and then we're going to be going navigating our terminal into that unzipped folder so do you see how we have this unzipped folder in our downloads folder we're going to tell a terminal to get to this get inside this folder okay so to do that you're going to need to use the CD command so I I can use this great and that takes me straight into this folder because I used CD change directory change directory go into the downloads folder and go inside this foldo that's called terraform um 1.10.2 so on and so forth okay and when you're there we're just going to double check we're at the right directory Great and then this is a magic moment where we're adding it to our path so the moment we add this to our path we're now able to run terraform commands from anywhere in the local terminal great work so we can now just skip the heading um option to Windows cuz I'm using Mac instructions and then we can verify that we've run it correctly by doing the iconic version command and this version command is how we see what version of terraform we're using nice the fact that there's even a version number popping up means that terraform must be working do you see how we just ran a terraform command by the way this is your very first terraform command great work you were able to run terraform version which out the version of terraform that you're using this command wouldn't work if you didn't install it properly so Props to you all right now we're on to step two in step two we already have terraform installed now it's here with us so let's set up the project directory let's set up how we're going to use the local terminal to create a terraform project and that terraform project is how we write the files for saying get me an S3 bucket um so here we are in the second part of our process today in this set we will set up a terraform project from our local computer because this will be where we write the configuration files that sets up the S3 bucket using terraform nice work okay so on your desktop we're going to be creating a new directory called ni terraform by directory it basically just means a new folder it's going to live in your computer somewhere and it's going to be called nextwork teror form so we're going to create that directory right in your desktop which means you should be able to see it right away okay in fact oh I already have NEX T from here so let me let me delete that first but uh in your in your desktop you can check now check for the folders there do you see any folder let me see if I can just get this down yeah do you see any folder that's called nextwork terraform probably not okay this is my desktop so let me run that command Now to create that directory and boom next terraform has been created great work and then inside NEX terraform what we want to do is create a file called main.tf okay that's what we're doing here to do that we're going to have to tell our our terminal can you navigate inside this folder that we've created okay navigate inside the folder we've created all right okay so our terminal should now be inside this folder and then we're going to run this magic command that tells um our terminal to create a file in that folder so first I'm going to make sure I'm in the right place do you see how now our terminal is inside the NEX workk terraform folder very good and then we're going to oh we're going to run the commands for creating that file called touch uh called main.tf and the command for creating that is called touch whoa look at here so at the moment we run touch main.tf or if you're using Windows it will be this command here here that file gets created straight away cool so what is this mysterious file we've just created what is main.tf main.tf is that Central File in a terraform project it is the place where you tell T form what you want your infrastructure to look like it's where you write that wish list we'll be using terraform language which is why it's a TF not really like a txt or text file um and think of it as the blueprint for building your Cloud resources so this is going to be a very important file for us to work with today and how does terraform actually use configuration files you know how what is the relationship between main.tf and terraform so we've actually covered this before I just realized I got ahead of myself we covered this already but how it really works is terraform files the describe the desired state of your infrastructure it tells terraform this is what I want in my infrastructure and terraform has to read that file to figure out how to achieve that state how to achieve that desired state so you're almost not telling Teri form build this build this create this it's more that you're telling terraform this is what I wish was in my AWS infrastructure and in tform I has to read that wish list to see if you already have some of it if it does it doesn't need to create it if it doesn't or it needs to change then it'll change it you're not really giving terraform direct orders you're almost just giving them this wish list and then terraform figures it out for itself on what it should create or update from there okay so with that done let's talk about it terraforms uses configuration files to understand the desired state of our infrastructure main.tf is the main configuration file that we use in terraform that we use in Terra form to to describe the resources to describe that desired State true very good all right team I think it's time for us to now head into the world of main.tf and writing out what we actually want are we ready are we ready ready I hope you are um let us get into it and understand how we can write that terraform code to describe what we want how do we actually tell terraform what we want we'll find out in this step we will learn to tell we will learn to to write the main.tf file because it's how we tell terraform what we want the desired State great so you'll need to open main.tf in a text editor so this could be vs code it could be notepad++ or it could be text edit um anything that lets you write code um so I'll be using visuals to do code today it looks great all right let me actually drag it out so it's it's in its own window okay so this is my window where I'll get to write and edit main.tf great so what's going to happen now is we now get to copy this code and paste it into main.tf and correct if you're wondering is this going to be the configuration oh shout out to Shen shine shine in the chat for saying hello really good to meet you welcome so this is going to be the main configuration that we set up and let's break it down because we've copied a bunch of code here what have we really copied let's break down all 16 lines okay first things first we have provider AWS provider AWS is telling the terraform um terraform that you want to be using AWS as the cloud service provider for your infrastructure a provider in general is a plug-in it's like a software add-on that lets terraform interact with cloud services so because we have provider AWS we've given terraform the permission to use this software add-on that lets it connect to AWS otherwise we could be saying provider Azure provide a Google Cloud this is a cloud agnostic tool so it could be all different kinds of providers that we get to Define in here and then we say oh yeah when you connect to AWS please make sure that you're we're using my region here Us East One update this to the region that's closest to you so I'll be keeping us e one because it's my best region but make sure to change this to your Region's region code next up now we're creating a resource so this resource block is telling terraform that I want to create an S3 bucket now so I want to create an S3 bucket internally we can also call it my bucket which means later on in the code you can just refer to your bucket as my bucket like this so that you can indicate that this is the bucket that you want to update because imagine if in one file you wanted to launch 20 S3 buckets and you wanted to give special settings to one of them how would you tell your terraform file I want to update just one of them and update it this way not all my ter um not all my S3 buckets how you'd have to identify It Is by going AWS S3 bucket this is the res uh this is the resource type I want to affect or change and then this is the internal reference for it the internal name for it so it can identify ah this is the specific bucket that you want to um you want to update or change so notice that your bucket name is written out here so when you launch your S3 bucket it's going to have this name you might remember that S3 bucket names actually need to be completely unique in the entire world no two buckets in the world can have the same name so this is your challenge to please update your name to your actual name so I'm going to just use next work for us and then a random number I'm going to be doing one 2 3 four so great we figured out that this BL block is all about just creating that bucket and naming that bucket this thing next we unique bucket so on so forth next up we're creating another resource all right so we've already created our S3 bucket technically like we've written out that we want an S3 bucket up here but what's going to happen is you actually need to set up a separate resource just to say what are your S3 buckets um I think it's called H permission settings or access settings here we're basically telling terraform can you please just make sure we're blocking all public access to my S3 bucket that I'm creating really good um a big shout out to C9 again for saying I'm following your AWS project series it's amazing a very nice I'm glad it's amazing um and yeah once we have this resource here that tells Terra form that we want to block all public access to this bucket that's it that's our main.tf file we've set we set up the configuration file so you might be wondering why is it that this file or this block lives separately to the S3 bucket itself and a big thing with infrastructure as code is modularity a concept called modularity that means you're breaking up your code into separate blocks separate chunks so that they can be managed individually notice how instead of one big list of like oh provider AWS region us one like everything in one just continuous block of code we've actually split up all three things into three separate blocks one block two blocks three blocks this is modularity at work like we've managed to actually split up the definitions of these into independent pieces this is a very very great technique to use when you are are needing to for example when you're needing to just change one part of your configuration without really wanting to affect the performance or affect any other part of your configuration it's just super super helpful as well for even people working in a team that might be working on a configuration file together if these resources are split into blocks in the future they can split into entire files by themselves and when you're able to split up one big giant piece of work into individual pieces like this it's so much easier for a team to collaborate with each other without accidentally overriding someone else's work without actually accidentally um having a lot of conflicts you know between everyone's progress so it's that's also a great reason why modularity is so good it also really helps with being able to troubleshoot any errors because you can now see very very specifically which resource block could be running into to that error great stuff the configuration is structured in blocks instead of a single block of code the advantage of doing this I.E modularity is the ability to work on update different parts of main.tf without affecting other parts great for teams collaborating too so what are the three blocks in our main.tf file and what did they describe all right so what does that first block indicate okay the first block indicates that we are using AWS as our provider for this infrastructure the second block this one over here provisions and Amazon S3 bucket and gives it a unique name the third block manages the buckets permissions which means blocking all public access excellent staff team so as they mentioned before please make sure to update the region make sure to update the bucket name and then when you are done we can take a screenshot of your updated file let us take that screenshot like this and then we'll drag it in and upload the screenshot excellent work Team all right you are now seeing a hidden secret mission that's right the secret mission wasn't even showing uh in the sidebar because we wanted to keep it as a little surprise for you but did you know that you can also further customize your main configuration file this is great for anyone that's really wanting to go the extra mile and do something unique that maybe other students aren't doing with their configuration so let's unlock the secret mission very nice to do this secret mission we're going to be customizing the S3 bucket and it can be as simple as one line or just two lines to do that we're going to have to visit the terraform Registries documentation on S3 buckets and you'll notice that this registry is a huge information Source um on what you can do with terraform and how you should configure your resources that you try to create with it so in this case we can see that there's a dedicated page just on how to launch or manage S3 buckets using terraform really cool so what are we looking for here we're looking for ways to customize our um S3 bucket so hopefully this is going to be a great source of inspiration oh all right I we'll answer this question in the meantime for our project extension we visited the official terraform documentation to look for ways we can customize our buckets configurations the documentation shows look at all the things that it can show it can show example configurations wow all the available parameters for a resource so much information in here and don't get like too intimidated by it just know that documentation isn't supposed to be read in like one go it's more like you're supposed to use it to find the information that you're looking for so instead of forcing yourself to read everything you can go from the perspective of how can I answer the question that I have today using this piece of documentation all right so you can see that it just goes on and on um and it gives you a lot of information around how you can use the S3 bucket object and even the rules around it wow okay okay so we can say the documentation shows example configurations all the available parameters for resource and the rules for using it and usage rules great so off we go to the next part from the documentation you can now choose additional configuration that you might want to add okay so from this list of all the things that you can add to your um teram configuration what would you like to do so what helps is you can just even click around in these headings to pick something that you might find interesting you know you can even select what AWS region it side you can [Music] Define wow you can there's even a website configuration block if you're setting it up um to host a static website hi sahil good to see sahil in the chat here by the way hi um and wow like look at this like there's a destination all right cool if you're feeling a little overwhelmed that's totally okay you can start simple by just adding tags you know just tag your bucket with something that could work so you can add a tag and notice how there's even an example of how I can put it there's your bucket line give it an entty line and add your tags um kind of code block so let's do that here let's add our tags cool um and just one tag is enough personally I could say tag um environment equals Dev or we can say project equals what project am I create what project is this called again I feel like every time I release a project I get the project name mixed up um because I think about the next project that's coming up um create an S3 bucket with terraform okay so save your work know that this is super open-ended and take a screenshot of your C custom work be very proud of it okay um and once you've taken that screenshot do upload that into your project great so which customization did you pick for your bucket and why you know this is where you can add it I chose to customize my bucket by adding tags because that lets me identifi the project name identifi the project that I launched it for later on when I launch launch my bucket I can verify my customization by visiting the maybe the tags panel in the SV console for this bucket very nice so we've saved our changes to our configuration file and it's now time to actually run this configuration so let's get ready to get P form to create all of this you know now that we've set it up so we're going to initialize Tarra form and then we're going to plan our infrastructure changes which means previewing how your configuration will change your AWS environment so we're going to get terraform to wake up and then we're going to say to terraform hey I want to run this configuration file can you repeat back to me how this configuration file is going to change my infrastructure tell me what's going to change so I can review if everything looks okay nice in this step we will run terraform commands to initialize [Music] terraform and plan our changes because we want to review our configuration file and get it ready for launch C beans so in our local terminal what we're going to do now is we're going to initialize terraform we're going to go say wakey wakey uh with this command terraform in it great off it goes with all of these um feedback all of the stuff happening in the terminal there's things like initializing the backend there's things like downloading installing some plugins you know you can break this down like line by line with us in this um explanation here initializing the backend so yeah terraform has a backend and that backend is where it does the work of seeing your file your configuration and comparing it with the current state of your infrastructure and that's why State files exist State files is a piece uh is a file that terraform will store in the back end that continuously updates every time your infrastructure updates so can make the necessary comparison between what you want and what you currently have and this is also where initializing is also where you get to install the plugins hey can you please connect to AWS or can you please download the connection or the connection software that can connect us to AWS great so with that we'll be able to take a screenshot of this to show that we've initialized terraform my goodness what a big piece of code um very nice let us upload that over here and it's really cool to see that you the the terminal is really showing you step by step what terraform is doing in the background you know it's initializing the back end it's setting up those date files it's initializing the plugin so it's finding and um locking in which plugin that we want to install it's installing that plugin and then there's even a lock file which I think we would have mentioned earlier actually there you go so lock file is different from a state file by the way a lock file is how terraform is going to remember which provider you're using and which version of that provider you're using in our case we're using v5.8 1.0 how terraform is going to remember this that we're using this specific version is by storing it in a lock file and yeah there we go terraform has been success successfully initialized it's now ready to read your file your main.tf and then set up the resources inside okay so let's explain what terraform init does we ran terraform init to initialize terraform this means getting it to set up the backend to store State files and install the necessary plugins at the AWS provider plugin great work team so once we've initialized terraform it's now ready to run some terraform commands and create some things compare some compare your main.tf file with your current state it's ready to do all that now shall we run the command to say plan now plan and tell me back how my infrastructure is going to change um based on the comparisons that you've made Let's copy the code for terraform plan and run that now okay next we ran terraform plan to get terraform to compare the infrastructure or the resources in the main.tf file and compare that against our infrastructure's current state very cool okay so plan really creates an execution plan oh I just realized I got Tongue Tied here we're trying to compare the infrastructure or resources in main.tf against our infrastructure's current state then share back the execution plan I.E how running main.tf will impact our infrastructure EG creating a resource cool so when that's done notice how we did get an error oh no why is that so notice that the error says no valid credential source is found and why is that it failed to refresh case credentials all right a lot of um some suggestions here from terraform but what's most interesting is that we ran into this error in the very first line provider AWS why is that why is that okay so what's happening right now uh in my case if you don't see this error you can jump straight into step six by the way you don't need to uh head into step five you can jump straight to the next one but the reason why we've run into this error is because the provider AWS is here to help us connect to the AWS Network and then see what resources are in our um account but when it says no valid credential Source found it means that our terminal or terraform doesn't have any AWS credentials so when it doesn't have any AWS credentials could AWS let it into its Network show it some resources that's in your account no way what we're going to need to do is give our terminal AWS credentials which in turn will let us give terraform the permission to access AWS okay so the issue here we don't have our our terminal doesn't have permission to AWS so terraform doesn't have permission to AWS so the AWS provider is not going to let us in and see what's inside our account to solve that error we're going to have to set up AWS credentials within the terminal this will let terraform finally authenticate itself with AWS and then get into our account manage some resources for us so to do that we have to install AWS CLI and this is another tool that helps us with um that helps us with managing our AWS environment using text commands in the terminal so instead of using the AWS console to manage things we now need to manage resources within the terminal now this is a pro project big reminder here so we do actually come in with the expectation that you've created AWS um resources using the CLI before what this means is if you run into this era we're going to troubleshoot it together but just know that the troubleshooting steps probably won't be as detailed as what you might get if we didn't assume that you have CLI experience so if you don't have CLI experience what should you do absolutely continue on with this um demo because we will still go through every single step of setting up CLI from scratch but if you still get stuck or if you still don't really quite understand some parts of the setup just know that we have a link in the description box that goes through this in a lot more detail and in that project we don't assume any experience with CLIA at all great work so what are we doing in this step in this step we will set up the AWS CLI and access keys because our terminal currently doesn't have permissions to AWS because of that terraform encountered an error which will need to resolve to run our configuration file okay if we don't solve this issue terraform wouldn't be able to run our configuration file and create that S3 bucket for us you absolutely need credentials to do that great stuff cool so do feel feel free free to use these steps to check if you already have AWS CLI installed okay the best check always is a version check so here you can see I ran into an error it says I don't have AWS CLI in my local computer but if you see a version number it does mean that you have um AWS CLI installed so you can actually move on to another section within the step you can scroll down a little bit into the next section of the step but in our case we're going to need to run this command to install AWS CLI and set it up great stuff um and yeah it's really good to know that AWS CLI the command line tool you can install from the command line itself you don't need to you know find a package and install it like that um this is really easy to use okay so we're just getting it installed now and then once you've installed it make sure you can just skip the instructions under any operating system that you're not using so for our case um I'm using Mac so I've use the Mac OS instructions but you can skip the one for Windows and skip the one for Linux um but you can choose to go for you know the windows instructions if that's what you're using this is taking a bit of time so let me just try checking if I have my AWS version now oh uh sorry about that team um I just had someone outside asking if they can change the light bulb but it's just going to be another second before we finish the live um okay so this my terminal seems to be taking a bit of time to run that command so I'm just going to refresh it and see whether or not it can run the command a bit better it's really taking its time oh there we go okay so we have CLI installed now the version command now actually gives me a version number so we can move on to answering the questions here okay very cool um it says to take a screenshot of your local terminal showing the no valid credentials error from the previous step oopsies you can see my terminal doesn't have that but that's okay you can always try to run the same command oops and see whether you can recreate that error I say oops because uh I've changed I've refreshed my terminal so I don't think I'm in the right folder anymore so let us actually head to desktop and hit to the right folder for this are we in the right folder now we are so we can actually run our terraform plan will it work shall we see great great all right let's take a screenshot of this error and let us explain the error too when I try to plan my terraform configuration or really when we try to plan our terraform configuration we received an error message that says no valid credentials found because our local terminal was a setup with credentials with AWS credentials yet this needs to be set up to use the AWS provider plugin cool so we have confirmed that we have the version going now to confirm we've installed it perfectly and now we'll just quickly explain what the AWS CLI as well to resolve our error first we installed AWS CLI which is aws's command line tool for interacting with our AWS environment or you can call it an infrastructure as well instead of using the AWS Management console the CLI lets us run text commands to do the same things even from our local computer and I think that's the key part here too to resolve our error first we install AWS CLI which is aws's command line tool for interacting with AWS with our AWS environment I would say with our a list infrastructure instead of using the Management console the CLI is let's let us run text commands to do the same things from our local computer great so we've installed AWS CLI now we now have a way to interact with our AWS environment from the command line um and we need to configure it so let's go AWS configure ah and it's now going to ask us for our access key ID you might not have that yet because the access key ID is something you need to create as well from AWS so if you don't have that that's okay first of all just know that the access key is just your way of logging into AWS from the CLI from the terminal just like how in the Management console you have to type in your user name and password for the CLI you're typing in your access key and your secret access key ID okay so we need to set that up from scratch um I've prepared this account so that it doesn't have that yet which means we get the joy of doing all the steps of this project today um to do that visit I am in your console and then find your I am user to create that secret access key reminder if this is feeling a little fast just know that the description Box gives you a video with a more in-depth explanation of all the steps with using the CLI with using access Keys all right on the security credentials I'm going to create an access key to use it with the command line interface with the CLI and we can even give it a description tag like this and off we go creating the access key okay um Gustavo has a great question in the chat here asking should we choose a Mac OS or Linux based system is that better for working with automation like CLI uh I don't think there's a difference between using Mac OS Linux versus Windows when you're trying to use CLI or using uh infrastructure as code in general what you can do is the same it's more that the commands we doing it looks a bit different Gustavo so please don't hold back from doing this project or giving infrastructure as code a go if you're using Windows Mac OS and Linux you might see more of simply because um there are tons of people using Macs and Linux computers to create do these projects but there are absolutely so many windows users doing these projects and working with automation from a Windows computer too so I hope that that gives you um the reassurance that you can ab do that um and choosing a Mac or Linux based uh system doesn't really change a lot um in that sense Okay so we've created our secret access key which is the way to log into AWS using the CLI I'm going to download this file that saves our username and our password into a local file because you don't see this page anymore the moment you you click done so this Excel file that I've downloaded is just a backup copy of my login details but you can actually just copy it from here straight away and put that in the terminal to log in okay so I'm going to give in my access key ID and then the secret access key you can give it too and then you can give it your default region so we're using Us East one but put in your own regions code and in the default output format we don't really need to um do anything different from the default because the default is uh just Json but you can absolutely type in Json like this if You' like it doesn't change too much from the default great so we've just technically logged in to AWS from our local computers terminal which is great and so we're going to just explain what we we've just done we set up AWS access keys so that we have a way to log in to our AWS account over the CLI in our local computer once the access key ID and secret exess key are passed through AWS configure our terminal now has the necessary AWS credentials woohoo I love that I think that's definitely something to celebrate you know we just got AWS credentials sorted um in the terminal too so this is really good it sets us up for um planning our tform configuration again and hopefully being able to uh run it successfully this time so let us copy the code for making sure that our terminal is in the right directory and let's plan our Tero configuration again is it going to work this time do you think we're going to get out of Arizona oh my gosh we did I'm so glad look at that terraform plan looks much better now um we've just set up AWS CLI and access keys that helped us make terraform plan finally work because we now have the credentials to connect to AWS so now that our local computer has the credentials to AWS so does terraform so when we ran terraform plan it read our main.tf our configuration file and it could successfully goes to the AWS provider give them your credentials get into your account and then say okay does your account have the resources that you're describing in main.tf that was so successful very very glad to see it so terraform it's been initialized your configuration is now planned this is the configur uh the execution plan that terraform has prepared for you it's kind of written a report that says Dear you I've gone into your adws account I've compared it with the resources you've described in main.tf here are the things I'm going to need to create so that everything that you desire in main.tf is going to be in your infrastructure I'm going to be creating this a bucket will be created and I'm going to need to create this uh an access block which basically means your buckets permission settings created very good so the plan two resources to add no resources will'll need to change because we'll be creating them for the first time no resources that we're trying to destroy here we're not trying to delete anything yet so good so I just realized I went ahead of myself but that's okay um now that we know terraforms plan um what's going to be happening here is we need to apply that plan we're going to say great plan go and build it you have my full approval we need to run a specific command to do that terraform plan is just about creating the plan it's not about actually running um the configuration file so once we've run it we also so need to verify that we've successfully created that new resource all right in this project we will apply the configuration file and changes we've set up in main.tf because no resources are launched until those files are applied until I would say until our configuration is applied really good Okay so we've just I I did go ahead of myself get ahead of myself and yeah we did just go through what terraform plan is telling you so we're going to now just apply the terraform configuration we're going to say the plan looks good let's go and build everything terraform apply okay and you can see that again terraform apply will still make terraform double check with you that everything looks okay okay so okay just double checking I'm going to be creating all of this this is okay you're all good and then you say yes it is all good this sounds great so Offa goes into actually creating the bucket now terraform is now going into your AWS account and creating the bucket for you and it's also setting up all of those permission settings like you've described in your fi file so cool to see it's just so cool to see okay [Music] so we ran terraform apply we run terraform apply to get terraform to apply the changes or updates it showed us when we ran terraform plan running terraform apply will affect my AWS account by creating two resources yeah so you can see two resources added an S3 bucket and the set of permission settings and it's set of permission settings there you go red ooh so now let's explain the the relationship and Order of the terraform commands the sequence of running terraform init terraform plan and a terraform apply is crucial why is that we actually talk about it right above here okay in general you would run into an error if you didn't run terraform init that very first command because terraform init is about literally waking up terraform and getting it ready so that that it has the back end to store State files and so that it can actually install all the plugins that you're using if you don't have both there's pretty much no way that terone can even plan any changes because there's no State file which means there's no file available for it to even store what your current infrastructure looks like to do any comparisons at all it also needs the AWS plugin otherwise it can't even connect to your AWS account okay so terraform in it is so important to do first next one terraform plan technically you don't need to run terraform plan it's not like the it's not it's not going to let you run into an error if you don't run it but it's molded tform plan is just such good best practice because you need to review your plans review any changes before you go and run them okay so let's explain that now the sequence of running terraform init plan and apply is crucial because you need to initialize because we need to initialize terraform first before we get to come before we get to make any comparisons between main.tf and our current infrastructure or to connect to AWS in the first place great onwards enough words so we have created our S3 bucket and next what we're going to do is we're going to log back into the AWS Management console as our I am admin user to see the bucket in action great question from Eric asking if we want to modify the configuration of our bucket after creating it with terraform can we also use the console yeah yes you can so just because you've created it with terraform doesn't mean that you can't use other methods to modify the resources think of terraform as a way for you to make changes but it's not it doesn't lock those resources in for sure you can still make changes to your bucket from the console from CLI um even after creating it with terraform cool so shall we just go into our Management console now oh my gosh I'm so excited team um that let's go into our Management console okay and let's visit the S3 console all right and let's find our account's buckets can we see a new bucket oh my gosh I'm feeling quite excited team oh I have a lot of buckets here but do you see this one whoa dun dun dun next unique bucket next to 34 where else have you seen this yeah do you remember we this is the exact bucket name we defined in a terraform main configuration file so what does this mean it means that the exact bucket we defined with terraform has been created now shall we see what tags our bucket has we said in our hidden secret mission that we created a tags that we can verify so let's go check it out so I'm going to go into the properties Tab and you can see the tag I set up earlier in this project that says you know the project related to this bucket is create an S3 bucket with terraform ah it's almost perfect everyone that's perfect so very very big success there we've created the S3 bucket we could even very verify that the tag that I've created we've created sorry is in the uh is attached to the bucket too so let's take a screenshot of our AWS console uh of the newly created bucket and you know what if you like you can even make sure that the tags are showing too if you want oh whatever configuration you've customized you can also find a way to include that in your screenshot if you like um you know what's most important to me is that you can see at least the bucket name uh so we'll just make sure that's in the screenshot I'll make it bigger so we can all see okay let's take that screenshot now so good it looks so good oh makes me so happy everyone all right project done you've just learned how to set up terraform you've installed it you set up main.tf you learn how to run the commands to run terraform in your configuration and you just use it to launch an S3 bucket you should be so proud of yourself this is a huge achievement congrats on using terraform if you're ready for our secret mission which I'm going to be doing we're going to be uploading an object with ter ter form too so how do you get an image into your bucket using terraform so let's do this in this secret mission we will upload a bucket object using terraform hello didn't know that was possible it definitely is because uploading objects is a foundational action skill that comes with having an S3 bucket we absolutely need to be uploading objects once that bucket exists so why don't we learn how to do that with terraform okay so let's add a new image and easiest way is to just download this image that we've provided you today so you can open this and click on save link as and make sure that you're saving it as an image that's called image.png make sure it's image.png not image one image two copy of image yeah we don't we don't want that make sure it's just image.png if you like you can also pick an image that's already in your computer just make sure it actually has the name image. PNG like you've renamed it to that name and you can use your own image in your computer just the same okay once you have your image ready let's move it into your next terap folder it needs to be in the same let's it's going to be a lot easier when it's actually in the same uh directory so let me move that over here so good PS this is what the image looks like it's very cute yay it says nice work challenging yourself to the secret mission and a big shout out to all the lovely comments we've been getting on YouTube literally when we see a nice comment we turn around we're like oh my God there's been a nice comment and we read it out so that the rest of the team can hear it um it really makes a big difference so thank you so much for all the support um okay so we have the image it's in the same directory as our configuration file now so what's next is it uploaded do you think it's uploaded nah it's not uploaded yet so we have the image in our local computer but how do we actually get it into S3 so we need to actually make a change to our configuration file to now say can you also upload the this object into the bucket to do that all we got to do is upload this block of code into main.tf okay so you should be able to to see now main.tf over here has a new block okay this block is really saying you know that bucket over here that we created yeah this bucket I'm going to reference it again I want to put something in this bucket okay the bucket the object that I want to upload is called image.png and this is the this is the path from the configuration file look for image.png if let's say I had stored image.png in another folder then I might need to go oh the image is stored in downloads image.png for example now this is how you can get to the image we're not doing that though so we don't need that oh sorry I just realized I was explaining for the line below so you could you could also say oh the image is at is in my downloads folder so go into my downloads folder and then find image.png that's the image I want to upload but since it's in the same folder we can just reference the name directly you know they're just in the same place next up is the key so where should it be in the bucket this is a great place to put in a folder name you know images if you want to put it in a folder or if it should belong in a folder that already exists we're just uploading straight away we don't need to put in a folder name here so let us take a screenshot of that new resource block and let's add that into our documentation cool so what have we done here today we created a new resource block to upload an image called image.png into the S3 bucket the image will be uploaded straight away without being listed in a sub folder in the bucket great so let's save the file save the changes that we've made and then we're going to go back into our terminal to run the magic commands for um planning and then applying our changes so let's run terraform plan again okay and we're going to run terraform plan and apply again because we've changed something in our configuration it's just as simple as that when we've made changes to our configuration you need to to give them the same give them your updated file and then tter from now can you compare again my desired state with what's currently in my infrastructure and look this time how many resources are we adding just one last time it was two because we needed to create the bucket and we needed to set up the permission settings inside this time those two things are already created so what are we adding here all right there's only one object to add and it's the image itself really really smartly terraform could compare what's now in our infrastructure with what we've written in main.tf it can see that our current infrastructure is updated we already have the bucket now it's already set up with permission settings now so the one thing left in our updated main.tf that it doesn't that our infrastructure doesn't have is the image itself which is why it's the one thing that we're going to be creating okay so we need to run terraform apply again oh yeah let's run that now actually we've only run terraform plan you know tell me the changes that's going to happen but we need to run terraform apply to say now let's actually make those changes happen so we need to run terraform apply again because we've updated our terraform configuration file which means there are changes that terraform needs to review and compare with our current infrastructure again Eric in the chat says hi hello Eric cool this time only one new resource is created the image okay so oh let's type in yes the tell terraform we do want to be performing these actions and then so quickly the apply is already complete shall we go check our bucket and see if there's an object inside let's refresh the page so cool it's so cool it's so cool to see that with a few changes to our configuration file in terraform we've been able to upload something into our bucket no clicks on the console needed no need to run special text commands just tell terraform what you want in your desired State and terraform is going to do the comparisons and create those free resoures for you you can even click into the image download it back to you and verify ah did we upload the correct image that the correct image upload successfully does look okay was it altered ah perfect what we've uploaded is exactly what we've downloaded back to us is exactly what we were trying to upload so that's perfect okay so to validate that we've updated our configuration successfully we checked the S3 bucket and confirmed that a new image is in inside we also downloaded the image back to us and confirmed that it was the correct image that was initially uploaded huge win there so we've successfully uploaded an object into our S3 bucket using terraform I think that's awesome so to WRA up let us actually clean up the resources we created today we have two things to really delete here your Amazon S3 bucket which comes with you know deleting the objects inside if you have uh done that secret mission okay you can even take it off when that's done and then you also have your access key which we create in step five and this is optional because not everyone would have created this access key if he didn't initially run into that credentials issue okay you can actually delete resources so quickly with terraform as well by using a command CAU terraform destroy okay so let's run that command destroy now we are actually telling terraform to reverse all the changes we made to apply and what that means is it deletes the resources and brings your infrastructure back to where it was before this configuration file existed so do you see how when we destroyed it now gives us a plan that says there's going to be three resources we're destroying here and all the pluses those green pluses become minuses because we're now moving these things away so we're only going to type yes here because we do want to delete everything we want to delete the image we want to delete the bucket we want to delete the buckets permission settings all of that you can even go into your bucket refresh it and yeah your bucket doesn't exist anymore you know it's not there anymore um perfect we deleted it perfectly I would also recommend just deleting that I am access key that I set up earlier in this project because great for security if you don't have something that literally gives someone direct access to your a infrastructure and just have that floating in space it's best to just deactivate it and delete it and create a new one when you're ready to use the CLI again or when you're ready to create an an exess key for something else again great that was all the resources all done Mark and the chat says why not run from your terminal AWS S3 Etc um to see whether you have an S3 bucket I think that's totally possible it's a great way to validate that you've um created the S3 bucket you can do it it's more that using the console was simply a more visual way to see those changes that you've made but yeah Mark is correct you can use um awscli commands to verify that you've created the S3 bucket too cool stuff Services we use used in this project what were they today we're we're ready to recap everything now so we used Amazon S3 AWS terraform was there anything else and the AWS CLI key Concepts we learned include infrastructure as code [Music] creating configuration files modularity of code um using providers plugins State files even learned about lock files terraform Concepts great work so in overall this project took us approximately one and a half hours including demo time the most challenging part was H what would you say was most challenging I'd say the most challenging part was customizing our S3 configuration using the documentation using the official terone documentation it was super unguided but it really builds your skills there it was most rewarding to see the image a local image uploaded into the SV bucket wow both of them have secret missions the most challenging part and the most rewarding part secret missions for the win okay thank you so much for doing this project today and yeah let's reflect on why you did this project so please write from the heart share what you personally wanted to do personally felt from this project we did this project because we are complete beginners to terraform and wanted to make a start this project met our goals because we could actually install and set up terraform and use it to launch resources in our AWS environment that was amazing great great great work okay and that's a right for today you've learned how to install and configure terraform you've learned how to set up your AWS credentials in the terminal you've definitely learned how to create and manage S3 buckets using your terone configuration files oh big shout out to ks in the chat for saying hello ma'am hello ks in your secret missions you would have learned how to customize your configuration using J terraform documentation and then you've also learned how to upload files to that S3 bucket using terraform this is such a practical hence on way to get started with terraform understand what it does understand why people love it so much now you know how to use it you can actually start to learn how to automate the deployment of other projects you've done before if you created a VPC you can learn how you can use a terraform configuration file to do the same thing if you've used it to create a database H have a go do you think you can create that database just using terraform I hope you have all the fun using Terra form going forwards and with that all done we can now press mission accomplished and see our documentation very cool nice work everyone so let us just wait for that to load a little bit and let us download our documentation by the way away great work team and with our documentation downloaded we can actually open it up oops see daisies we can open it up check it out and you can also open up a prefilled LinkedIn post we've prepared for you that lets you share about the amazing work you've done today absolutely something to be proud of um what you've done is super super super in demand and cool and just shows you a great start in your AWS Journey oh I see that there's a bit of a spacing issue here with the post so let me just fix that right after this live but in the meantime you can uh let me just show you what this would look like yeah there we go cool it looks really good um so your post will give you a brief rundown of what you've done in today's project and it invites people to check out your documentation too which you can add right away as a document like this and add your title as well so create an S3 bucket with terraform nice work yeah the documentation itself looks amazing um you can see that these are all your responses things that you've written throughout this project and it sets things up from the start what are we doing in this project what was some of the tools you've used how did you reflect on this project today and then we dive into the steps as well you start to you start by explaining the key Concepts to the reader you even explain what is inside main.tf for yourself okay um you even this is a special little page that pops up if you've chosen to do a secret mission you get an extra page that explains how you customize your S3 bucket by seeing the official terraform documentation um there also terraform commands that you explained terraform init terraform plan yeah again a special page will pop up if you've chosen to set up your CL and access keys in this project and then finally launching the S3 bucket and verifying all your changes yes you've guessed it another special little page will pop up if you've chosen to do that secret mission so so many ways you can customize your documentation and so many ways you'll absolutely be showing your work with every single challenge you take it is just so cool to see um and it looks good in your document in your your LinkedIn post too so super slick work I hope you're extremely proud of yourself um you've done an amazing job today all right everyone that is a wrap for today's YouTube live for our project on creating an S3 bucket with terraform if you have any other projects you're wanting to see comment it down below you can also check out the community link to that is in the description box to ask any questions if you get stuck all right we'll see you in the next project thank you so much for the lovely energy today it was a lot of fun to be doing this project with you bye see you in the next project thank you thank you so much