Terraform examples with AWS
In this section, we will create two sample modules to demonstrate how you would go about creating one and what you will need to consider when choosing the way it is supposed to create resources. The module we are going to create will be able to create one or more EC2 instances, a security group attached to it, and other needed resources, such as an instance profile. It will do almost everything we went through in Chapter 10, but with the use of the AWS CLI.
EC2 instance module
Let’s create a module that will be able to create EC2 instances. Consider the following directory structure:
├── aws │ └── eu-central-1 └── modules
The modules
directory is where we will put all our modules, aws
is where we will keep our AWS infrastructure, and eu-central-1
is the code of the infrastructure for the Frankfurt AWS region. So, let’s go ahead and start with...