From the course: Learning Terraform

Get ready to scale

- [Instructor] Now that we've covered the basics of working with Terraform, we can get our code ready to scale. We'll want our blog server to have multiple instances and to scale those instances in response to load. But we should also set up multiple environments so that changes can be tested before they reach customers. First, we'll start by setting up our environment in a new VPC. So from the Terraform Registry, search for VPC and then select the terraform-aws-modules/vpc module. If we scroll down just a little bit, there's a usage example here that we can copy and then we'll open up our Repository and go into main.tf and we'll click the pencil icon and choose github.dev. So we want to look for a good place to paste this. And I think right below our default VPC is pretty good, so we can paste that in. If you'd like you can also delete this default VPC but let's leave it in there for now. Let's give this a custom name. We'll call it blog_vpc, just to follow the pattern we've been using. And for the name parameter, that's actually the name of the VPC we're creating, we'll call this dev. For availability zones, you'll want to change this to match what you've been using. Now I'm in us-west-2, so I'll change all these to match that. And we can delete these private subnets. We're just going to have these servers on public subnets. We also won't be using the NAT Gateway or the VPN gateway, so we can delete both of those. And this is correct, it's a dev environment, so we'll leave the tags the way they are. There are just a couple of changes we'll need to make so that we're using the new VPC. So we'll need to tell our blog instance which subnet to be created in for the network. So let's add a new line here, and we'll say subnet_id equals module.blog_vpc.public_subnets. I've got auto complete here. And then we'll select zero, which is just the first subnet. And we'll also need to update the security group. So we'll set the VPC ID here. We'll replace this with module.blog_vpc.vpc_id and let's add a commit message here of Create new dev vpc and will commit and push. Once those changes are merged, the Terraform Plan will just about recreate everything we've deployed. So when you're ready, go ahead and apply that. It will take a while to complete. If you run into any errors, double check your code against the solution branch and rerun Terraform. Even if you didn't have any bugs in your code, Terraform can sometimes have an error on the first run when you make big changes like this. So try rerunning it to see if that fixes the issue.

Contents