Terraform Tutorial in 2020 - Getting started on Google Cloud

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
make no mistake multi-cloud is the future gnorga nation is going to just use one cloud to manage their resources if you look at Microsoft and Oracle partnership that's one such example where even at a service provider level multiple you know clouds are getting together to offer better services for companies choosing the right infrastructure as a core tool is very important for the all nations to manage multiple cloud service providers and learning the right IAC tool for your future is also very important so one such tool that's trending year-over-year and if you look at the Google Trends you will see that the graph is just going up and the reason why is that it supports multiple cloud service providers and it has libraries for as your Oracle AWS and Google cloud and and it is an open source tool so that tool is called Ted of hey what's up guys my name is GK bind-off this video you're going to learn terraform how do you start off home to provision resources in google cloud so basically the scenario is that you know you're going to use terraform from a client location for example from my desktop and from my desktop I'm going to control the resources of Google cloud and you know create resources in Google Cloud so before I go into the demo we're going to click on the subscribe button so that you're going to get more such videos on terraform or any such tools so let's go into the demo and learn about this tool and this is going to be a super helpful video it's going to be easy video for you all to learn terraform and start playing around with that what you're seeing here is a very high-level overview of how the use case will look like so when you are using terraform and you want to provision resources in multiple clouds you would ideally want you to terraform to be outside of the cloud in my case I'm using terraform in my laptop and then I'm going to provision resources on Google cloud so you can also do the same thing with AWS or as your the syntax also is very declarative you don't have to learn any programming language to code it so it has its own syntax and it has its own configurations the way you want like for example the way you write and simple enamel so as part of this demo I'm going to fire the terraform from my desktop and then I'm going to create a compute engine in Google Cloud now for that I need to install terraform so currently I have a bun - which is running on my Windows desktop so we want to install terraform for that let's go to the website and download the Linux terraform package I would rather get copy link address and then alright so once you have the package you can unzip it by using terraform so you you can see that it's in executable format you know you can set this path something like this export path is equal to dollar path and all right so once you said this so you can do terraform to check the version of terraform so right now we have Terra Firma installed so next thing what we what we have to do is we have to write the terraform file so basically terraform file like i've said is a very simple file you know it's a it's in a declarative format and for that you can either use code your favorite ID I use code because it it recognizes the extension of the terraform and it can give you it can highlight the syntax is properly so the extension of the file is dot TF you know create that file dot TF wherever you're running from for instance if you are running terraform from Windows you can directly do it from your Windows desktop itself and since I'm running Linux on top of Windows you know I would have to create the file here in my Linux client the syntax starts with the provider so here what we're saying is provided is Google and the version number and credentials obviously we have to give the service account if you remember my last video when I was discussing about the service account you know if you want to connect to Google from your desktop or laptop or from anywhere outside of Google you have to use service account so which I'm going to create right now I'm going to pass the service icon JSON file here and the project ID as well you know you have to give the right project ID so I have to fill that information here so this is the provider block and if you're using for AWS then you would use a double ace as a provider and I'm going to share all the links of terraform website where you can get the provide provider and the syntax of the provider so this block once you write this block the next is the important thing which is a resource so in the resource block we have to mention the resources that we are trying to create so as you know here it is Google underscore computers code instance so if you have a prefix Google styrofoam we'll assume that you know the provider is from Google and it should it tries to create computing stens and this is an app server you can give any name here basically you can give in a web server name so this whole thing will form the resource ID so you can reference this in the future blocks so I'll come up with more videos on how we can use different you know configuration items but for now we are going to just use provider and resource for this demo to create a resource in DCP so as you can see terraform supports many providers you know Google Cloud you know Alibaba cloud AWS RabbitMQ and even OCI is your this is a beauty of open source where you know people will try to contribute as much as they can and they can obviously you will have more providers supporting that with respect to Google Cloud you can see the documentation specifically from the Google cloud provider so when you go to this providers link when you click on this link you know it comes takes you to here and then you can see specifically for which resource you want to create since we are trying to create for compute engine right instance in compute engine we have to click on that and then you will get an example here which is what I have used in in my file here as well and you can play around with this descriptions you know you can attach disk or you can change the network interface etc etcetera you can also create multiple other resources so the next thing that we have to do is we have to create a service account so obviously I have showed you how to create a service account but right now I'm going to create a new one for this demo so I already have my console opened up in a new tab I am going to I am service account or you can just try service account directly in such tab now there are few default service accounts but let's create a new service account for this and I'm going to name it as demo DF so role ideally if you if you are trying to create only for compute engine we would want to use for compute engine but for this demo I'm just going to use project editor which is not at all recommended like I was mentioning in my previous I am videos you know you would want to you always go with the roles of the least privileged principal so you would either you only create the role that is required for this action but for now I'm just going with editor continue and create a key Jason all right so I have a service account and now I have to populate this file so for that I need my project ID which is YouTube demo so let me copy the project ID here and then the file that I've created is this JSON file so I'll copy that JSON file here so zone US Central once see since I've mentioned zone already there I'll remove this from here okay so this looks good I'll copy the whole configuration from here and then create main dot TF okay so you have all the contents save it there are three main important commands that you have to remember in terraform right so first command is there are four minute so whatever for meaning in it does basically is it will identify that you are using a Google provider so it will download all the packages of the Google provider and then so the beauty of terraform again is you don't have to provision the resource to know actually where the configuration is working or not so there is a command called terraform plan we it will tell you what is the thing that's going to happen before even your infant is created and then the actual command is terraform apply that will apply the configuration and you know provision the resources on the provider we are going to do terraform in it okay so the output here is download downloading plugin for provided Google so it found out the provider from the file the main dot TF so see if you give main dot TF you don't have to explicitly mention the file that you're trying to execute when you do initialization so when I ran the initial terraform plan I got a couple of errors I'll show you there're switch I got so basically there are it was expecting a mandatory parameter called network underscore interface and it was also expecting boot underscore disk missing argument so these two are the arguments that it was expecting before and obviously the block type so you know for these you can either get these parameters from here so that that way it'll be easier for you or you can search for any Google documentation so I got the information from here and then I made the changes to the file I want to copy the file in the description as well now if you see the file the final file that I have is this so the provider I haven't changed anything there and the resource is where I have made the changes with respect to boot underscore disk because you know you have to obviously choose the image type when you're trying to provision compute engine right so I mean instance in the compute engine which I haven't done before so this is what I have changed here and the network interface I kept it as default now let's try to run terraform plan and see what is the output so terraform straight in memory prior to plan so what it's saying is that it is going to create the resource this resource is going to be created and these are the things that are going to happen so the boot disk is true you know and the mode is readwrite and the image is so and so which we have provided in the in the settings in the confusion file the default is network so let's run that our form apply one change yes it's error creating a trading inter instance invalid value of field interfaces so the reference network resource cannot be found okay so the reason for that is I might have deleted the default network so there is no network at all so I'm going to create a new VPC network and then make it as a default automatic into no loopy SSH and then create ok so now I have the default network which have created so let's try again this command and let's see what we want to get this time yes ok I think it is doing something right now because I'm not getting there so let's go to the compute engine ok as you can see it created successfully in my project in US central one C and the name of the instance is primary application server so let us quickly check that ok have a primary application server successfully created the good thing about terraform is it maintains the state of the infrastructure that you have created so all you have to do if you want to destroy the infrastructure that you have created is just say terraform destroy my word destroy and then it will try to destroy the instances that you have created or the infrastructure that you have created I would strongly suggest to use terraform even right now when you're playing around with any cloud size provider that way it will be easy for you to you know delete the resources because sometimes what happens is you create resources you practice and you forget and of the day you will be billed for that if you're not using the free tire so while this is destroying one quick question I have for you all feel free to put that in the comment section let's say we don't want to use terraform so what is the equivalent infrastructure as a code tool inside GCP to provision resources leave that in the comment section and we will discuss more about the tool in the future video so that's all for this video and thanks for watching and let me know in the comments section if you are facing any issues with this and I hope this was very helpful for you all thank you bye
Info
Channel: Cloud Advocate
Views: 40,852
Rating: undefined out of 5
Keywords: Google Cloud, Cloud Computing, Cloud Technologies, GCP exam, GCP Associate exam, Google Associate exam, Cloud Engineer, AWS Cloud, DevOps tools, terraform tutorial, terraform tutorial for beginners, terraform tutorial for beginners gcp, terraform tutorial gcp, terraform ec2, terraform for beginners, terraform in aws, aws terraform, devops tutorial, cloud computing, devops course, infrastructure as code, linux web server
Id: 5_DHR5wVVRo
Channel Id: undefined
Length: 15min 36sec (936 seconds)
Published: Sun Feb 23 2020
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.