Oracle Cloud ❤️'s Terraform

Video Statistics and Information

Video
Captions Word Cloud
Reddit Comments
Captions
[Music] [Music] hey what's up everybody it's ned bellevants ned1313 on twitter and welcome to terraform tuesday today we are going to be talking about oracle cloud infrastructure aka oci yes oracle has a cloud haha let's get all the jokes out of the way ahead of time i like you have been fairly skeptical about oracle's attempts to build a public cloud but when i think zoom moved over to it in not entirely but large portions of it moved over and kind of had to start taking it a little more seriously right there's still the big three or four depending on how you count it but oracle's putting up a fight and they're actually doing some interesting stuff how do i know i was a delegate at cloud field day 10 and oracle gave a presentation and they talked about like some pretty cool stuff but they also acknowledged that their early versions of the cloud that they tried to build were they weren't great and they also have an image problem because they're part of oracle a few jokes were made about licensing and how oracle is a company of lawyers that does a little engineering on the side and then we kind of moved on from that because while it's fun to make fun of oracle from time to time it's not particularly productive so we got past that and then they did this whole presentation about how they use terraform as their native resource manager infrastructure as code language and if that sounds weird i thought it sounded a little weird and i'd heard like rumors of this in the past but in this case they're actually doing it so that is what i want to cover today before i do that hey if you are enjoying this terraform tuesday stuff and you'd like to get it a week early hey you can do that by joining my patreon yes i have a patreon and if you do that you not only get early access to the terraform tuesday videos you also get a weekly newsletter and who knows i might throw some other stuff in there too we'll see what happens it starts at two dollars two dollars a month so that is definitely within most people's reach so if you'd like to do that and support me you can do that on patreon now that's all i want to talk about when it comes to that let's move swiftly on to the topic of using terraform with oracle cloud oci all right so i've laid down the basic premise right oracle cloud is a thing that exists and if i had to give my opinion on what it's best for if your goal is to consume infrastructure as a service without too much service layered on top of that by which i mean a lot of the other major public cloud platforms have a platform as a service offering multiples and they're very robust in the way that they manage that platform as a service oracle doesn't have that so much they have a bunch of services but they're mostly at the infrastructure level or the basic cloud building blocks level and that's fine if that's what you need to build your solution you can go ahead and do that if you want to use one of these more advanced platforms something like app service or something from aws that's a managed service like their macy platform or something go use it on that platform it's fine you can use more than one cloud multi-cloud is a thing but if you don't need any of that and you want something that's a little cheaper oracle cloud is actually a little cheaper than the other ones so you certainly have that option now the thing that piqued my interest obviously was the fact that for their resource manager they use terraform for iac what does that actually mean right because surely they're not using only terraform for all of their scripting and everything they do in the oracle cloud and that's true that is that is not what's happening here there's still an sdk they're still an api but there is also deep integration with terraform what do i mean by that well let's go over to a view of the browser and dive in a little deeper on that okay this is the oracle cloud console and the feature that we're talking about here is called stacks so let's go ahead and go to this resource manager link that we have here to create a stack i'll just go ahead and click on that now what does that actually mean a stack if you've ever used cloud formation a stack is just like a cloud for formation deployment basically and instead of using the cloud formation yaml or json you're submitting your configuration using terraform and the state of that deployment is using terraform's state mechanism instead of whatever cloud formation is using on its back end to detect drift and apply updates to the configuration i'd like to say that azure has something similar and they kind of do with blueprints but i'm going to be honest i haven't been super impressed by that i would just use terraform if i wanted to do the same thing on azure anyway so there's a number of different ways you can move forward here you can upload your own existing terraform configuration you can use a template that they've provided to you you could pull it from a source control system or if you have an existing compartment that has a stack in it you could copy it over now just a little terminology lesson here when oracle cloud talks about compartments it's very similar in nature to resource groups in azure so if you worked in azure you'll feel somewhat comfortable the main difference here is that compartments can be nested so you have one root compartment and then when is within that compartment you can have nested compartments so it's almost more like gcp's folders in a project i think it might be the closest analogy and i think you can apply permissions to the various compartment levels so you could give someone permissions to manage something in one compartment versus another some resources have to exist inside compartments i'm not going to get that deep into it because i don't understand it that well but what you need to know is the compartment is sort of the unit in which resources exist and a stack is a resource so verbage lesson over getting back to oracle cloud so if we wanted to we could import from a source control system we could use one of their existing templates we've got a lot of options here if we wanted to just use an existing template we could click on change template here and just do something like a default vcn a default vcn is their equivalent of a vcp or a v-net if we select the template now that template is selected we can scroll down and give the stack a name a description we have to select a compartment in which to create this vcn and then we have to select a terraform version we want to run right now they're using dot 12 which is weird because dot 14 is down i think dot 15 is about to drop but you know whatever and then you can add some tags if you're all good on that we can go ahead and click on next then we get to required configuration information so these are the input variables for the stack you're basically submitting variables for the terraform configuration so we can specify some information here the citer for the vcn a subnet that's going to be created and then a vcn label so those are all optional the only thing you need to give is a display name we can call this one let's call it taco test because that's what i want to call it and then click on next here and it will tell us some information about the stack before it provisions and if we go ahead and click on create now it's going to go out and deploy that stack so let me hide this cloud shell here and we'll get back to the cloud shell in a moment and we can see here's the stack now has it actually deployed anything no it's just created the stack for us the next step in this process would be to run some terraform actions that are run as jobs to get this stack deployed so we can click on plan and that's just going to run straight up terraform plan so we'll see the terraform plan appear in the logs down below we're currently looking at the job within this stack once that plan is complete if we're happy with the output you know we can do the standard one two three of doing a plan doing an apply and just checking for it so i'm gonna go ahead and fast forward things a little bit so you can see what the result of the plan is okay so the plan has completed successfully if we scroll down the logs we can see this is just standard terraform output right we can scroll all the way down and see what things it's going to create for this vcn and if we get down to the bottom we can see it's going to add six things zero to change zero to destroy if that looks good we can go back to the stack details go under terraform actions and go ahead and click on apply and set it to automatically approve and it's going to create this vcn for us now i don't want to do that we can skip that portion of it because now we're going to do something a little bit different let's go back to our stacks this part's kind of cool we're going to create a new stack but in this case we are going to use source control to do that so to set up the situation here you can store a stack configuration which is really just a terraform configuration on github or git lab and then you set up a source provider on the oracle cloud side that points it at your github account or your git lab account then when you want to create a new stack you can point it at that source control provider select the repository the branch and the directory where you have your terraform configuration and use that to create a stack now it's not a ci cd pipeline it's not going to do all these actions for you once you have the connection built but from there it can import the configuration and you can run plan and apply plan and apply as you want so i already have one of those configurations set up if we go over to visual studio code i'll show you what i got going on all right so we are now in visual studio code and you can see in the left side i've got this 2021 030 oracle cloud folder that is when i started developing this thing and we've got a github folder i'll expand that and it's got a main.tf so this is the configuration that i have stored up on github and you can go ahead and step through this with me if you want standard terraform config i've got my required providers i've got my provider defined with a region which is a requirement and then i have a few variables now my region and my prefix have a default so i don't actually have to specify anything with that but my parent compartment id does not have a default so you do have to submit a value along with that then scrolling down what is it creating it's going to create a compartment to hold some resources and it's then going to create a vcn and lastly it could create a subnet so that's what it's going to do now before i do anything i'm going to comment out this resource like this so we'll go ahead and comment that out there we go and i'll save that and then what i'm going to do is i'm going to push this change up to the github repository so when i do my initial stack creation it is not going to create this subnet and then we'll uncomment it run a plan and apply to show that it's pulling the newest version from github so this is my basic configuration let's go back to the browser and walk through creating the stack now i should say that you can do all this from the cli you don't have to go through the console to do this but i thought it'd be easier to show than just running some arcane commands in the console all right i've already configured a source provider so all i have to do is hit the drop down here and pick my current configuration source provider which i named ned1313 because i am super creative and then we have to select a repository within that now i know my repository is called terraform tuesday and because i've done this before that comes up right away so i'll select that repository and then my branch is it's master right now i've been meaning to rename this and then finally the working directory is going to be today's working directory we're going to start with today with the 20 21 03 30 oracle cloud and the select github so that's the directory in which we want to work we can give it a name but i'll just accept the default name and then the terraform version for whatever reason it offers dot 13 when you pull it from github but not when you use the template which is super weird but whatever and that's it all we have to do is click on next and now it's going to ask us for the variable values that we want to use for our stack and remember the only one that we actually have to specify is the parent compartment id and if we bring back up the cloud shell that i was using i ran a command that's included in the code that's in visual studio i ran a command that queries what the compartment parent compartment id is so i'm just going to go ahead and copy that value right now it's not the sort of thing that you could remember easily and we'll shrink that back up and paste it in here there we go that's my parent compartment id we're all set with that we'll go ahead and click on next we've got our stack information when we will select create now again just a quick reminder at this point it hasn't actually deployed anything it's just created the stack now we need to go ahead and run a terraform action which is a plan so i'm going to go ahead and kick off a plan and it should tell me that it's going to create a compartment and a vcn with some properties around that vcn so i'll go ahead and let that run and we'll fast forward to when the plan has completed all right our plan has completed successfully if we scroll down a little bit we can see it is creating a compartment for us it is creating some standard objects that are part of the vcn if we scroll down to the bottom we can see five things are being added that all sounds good to me what's the next thing we'll do we'll go back to the stack details we'll go under terraform actions and select apply automatically approve it's going to go out and create those resources for us now once again i will fast forward this process so you don't have to wait for all these things to be created okay it has successfully completed that's exciting if we scroll down let's go down to the end and see apply complete it created all of our resources that's awesome now if we go back to stack details i want to point out a few other things that are available to us for instance under more actions we can run drift detection and that basically runs a plan in the background and sees what the diff is between what's currently deployed and what should be deployed that seems fairly useful if we look under terraform actions we can import an existing state if we have it we can also destroy what's there and that's pretty much all we have under here now remember i said that i'd commented out that subnet so let's go back to visual studio code and uncomment that subnet okay we're back in visual studio code i'm going to uncomment this subnet resource from the configuration and it's simply adding an addition a well there's no subnet there right now it's simply adding a subnet i'll go ahead and save that and add in a comment here and commit that and push it so it's committed go ahead and push it all right so that change has now been pushed up to github now because this stack is linked to github we should simply be able to run another plan and apply and the new subnet will be added let's go back to the console all right we're back in the console and i'm going to go ahead and run a terraform plan and i'm going to verify that it grabs the latest version of the code from github so go ahead and run a plan here and just validate that it actually plans to add the additional subnet so it is running now i'm going to go ahead and fast forward to when it finishes okay it has succeeded so let's go ahead and scroll down and see what it's planning to do and we can see it's planning to add a subnet that's exactly what we would expect so it did grab the latest code and if i want to apply that config i can go back to stack details over here go under terraform actions and click on apply and click apply here and it's going to go ahead and add that subnet as a job all right and through the magic of video i've fast forwarded to the part where it has successfully applied that additional subnet you can see one thing has been added that's awesome what's interesting is if you look over in the resources you can actually view the current state of our terraform configuration and that's interesting what could you do with that state information well i'm glad you asked now what if you wanted to move off of this stack mechanism maybe you're adopting a different pipeline maybe you want to use a different back end yeah there's a whole bunch of different reasons you're not locked into using the stack mechanism at all you can simply copy the state that i just showed you into the directory or whatever the backend destination is that you want to use and then use the terraform config you already have in source control pointing at that updated back end that's all you need to do it's all good if you delete the stack itself it doesn't actually delete the resources you have deployed it simply deletes the stack so we could copy this state put it in a directory and we'll put it in the directory that we have our terraform config save it in a file called terraform.tf state and if you run terraform init and then plan it'll say no infrastructure change is needed because you're already up to date so it's very cool i've tested it it absolutely works if you wanted to do that you can let's go back to the console and we'll go back to the stack detail and i just want to show this if we go under here and say delete stack it's going to tell us that all the resources persist after stack deletion if you don't want that you can run a terraform destroy before you delete the stack otherwise those resources just keep on living on now we don't necessarily want to do that what i actually want to do is run a destroy action and get rid of these resources because i don't need them anymore and that'll do it for today's terraform tuesday i leave it as an exercise to you to take that state file and bring it down to your visual studio code directory so let me just show this real quick if we go under the directories i have one in here that's called basic this is basically the exact same configuration and i have a terraform.tf vars file right there for you all you need to do is copy that state and then paste it into a file in this directory called tf state and then you can run terraform in it and terraform plan and it should say nothing needs to change i mean you need to change this parent compartment id but i'm going to leave that as a challenge for you to do it's using the built-in authentication from the oracle cli so you're going to have to install the oracle cli as well and that can take a little while it uses python just like the aws cli does but for whatever reason it seems to run slower i don't know anyway so that is an example of how oracle is leveraging terraform for its resource manager and i just thought it was really cool that they've just gone full-on native with that and for me it makes it that much easier if i want to use terraform with oracle because i know it's a first-class citizen whenever they develop a new resource for oracle cloud it's immediately going to have terraform support because they rely on it so heavily and i just thought that's pretty cool so hopefully you found it interesting hey you know quick reminder if you are finding this stuff interesting you can all support me on patreon if that's not your thing please subscribe to the channel i really do appreciate that i you don't have to hit that notification button that i find that thing super annoying so just feel free to skip that if you don't mind liking the video apparently that helps with engagement or something i don't know if you're interested in getting a more net in the cloud of some kind i just want to let you know i do have a daily podcast it's about 10 minutes every day on a subject of my choosing you never know what it's going to be but hopefully i make it relatively interesting and i also have a podcast with my buddy ethan banks that is called day two cloud so if that's of interest there are links down in the description that's going to do it for me for today thank you so much for watching until next time stay healthy stay safe out there bye for now [Music]
Info
Channel: Ned in the Cloud
Views: 321
Rating: undefined out of 5
Keywords: HashiCorp Terraform, Terraform tutorials, Oracle Cloud Infrastructure, CFD10, Cloud Field Day
Id: rILZB7zjfwQ
Channel Id: undefined
Length: 22min 3sec (1323 seconds)
Published: Tue Apr 13 2021
Related Videos
Note
Please note that this website is currently a work in progress! Lots of interesting data and statistics to come.