You definitely get more complex ones. And so now if I were to show you the main.tf file which contains the module for my front end pipeline, you'll see over here I'm making use of the data API for a Terraform and this is a really neat way of pulling in some existing sources. And so in here, I'm pulling my secret that I created for GitHub and this is a really neat way of actually pulling that in and injecting it into some of the resources that you're creating, it keeps it secure and none of that sensitive information gets leaked in any way.
And so over here, similar to the module that I showed you previously, because there are some additional resources that I'm setting up, there are obviously more values to be or properties rather to be populated over here and all of these are just variables. You'll see over here, my application name, which I'm using across the project, the s3 bucket destination, the pipeline bucket name and code, build bucket name. In case you're wondering what those are for, these are not related to the S3 bucket for a static site hosting, these are primarily working for caching purposes so that when dependencies are installed on our particular, when our pipeline is running, that cache will make the things a lot faster in terms of every successive time that the pipeline gets run.
Okay, and lastly, we come to the infra live and over here, you'll see that I've split the folders into the respective environments and so what we have is a CICD pipeline and a web app, just reflecting the modules that we actually have and I'm also gonna open my Terragon config file, the parent file. And one of the child files. So the parent file is used to actually generate a provider and the provider is what we'll obviously make use of to specify the cloud provider that we wanna make use of to build out our infrastructure. I specify the region that I want my resources to be built in and the profile that I'm gonna be using for that. In addition, you get to specify some additional information in terms of the versions that you wanna use for the API. So in this particular case for AWS, what version I wanna be making use of and what version of Terraform that I'm also gonna be making use of. And over here, very important this last block, remote states and state is what is used to actually keep track of every, all the resources that have been created or that are alive or have been deployed. And so there has to be an optimal way of keeping track of those resources. And so you can have that set up locally or remote. A good practice is to have that set up remotely because if it's local and something happens to that local file, then you don't have a way of actually keeping track of what's been built out. And so I'm making use of S3 to store a Terraform state file, as you can see over here. And that Terraform state file is essentially a JSON file that contains all the resources that have been built out. In addition, I'm making use of state locking and my state locking is being done using a DynamoDB table. This is very useful when you're working in a team because what happens is when you're making use of state locking, it provides a protective approach to having several people working on the same kind of state. And so when one person is deploying something or is in the middle of some kind of execution, then they will essentially, the state will be locked from anyone else acting on that, which is a great protective measure when it comes to working in a team. So, sorry about that background noise. And now I'm going to show you a child TerraGrant config file over here. And this child TerraGrant config file is for the CICD pipeline. The one for the web app or the website will actually look very, very similar. I'm just going to collapse this over here and inside of it, for the pipeline, I specify the branch name and the environment. And this is a nice way of keeping things dry, like I mentioned, what TerraGrant essentially offers you is all the CLI steps that you would have in Terraform, but it essentially makes things more streamlined for you with these configuration files. And it runs all of those commands under the hood, and it's essentially a wrapper. Something I want to do, I do want to draw your attention to over here is this Terraform block, and it points to the particular module that you're going to be deploying resources from. And in addition to that, you can have some common variables and it will be able to source them from parent folders.
Comments