Three-tier architecture is a well-established software application architecture that organizes applications into three logical and physical computing tiers: the presentation tier, or user interface; the application tier, where data is processed; and the data tier, where the data associated with the application is stored and managed.
Terraform is an open-source infrastructure as code software tool created by HashiCorp. Users define and provision data center infrastructure using a declarative configuration language known as HashiCorp Configuration Language, or optionally JSON.
- One virtual network tied in three subnets.
- Linux Scale Set should use minimum 1 instance ; Linux Scale Set will create its own Traffic Manager that is accessible from the internet
- First virtual machine -> allow inbound traffic from internet only.
- Create Azure MySQL to use with wordpress autoscaling group.
Note: Keep main and variable files different for each component
├── main.tf // The primary entrypoint for terraform resources.
├── vars.tf // It contain the declarations for variables.
├── output.tf // It contain the declarations for outputs.
├── terraform.tfvars // The file to pass the terraform variables values.
A module is a container for multiple resources that are used together. Modules can be used to create lightweight abstractions, so that you can describe your infrastructure in terms of its architecture, rather than directly in terms of physical objects.
For the solution, we have created and used five modules:
- resourcegroup - creating resourcegroup
- networking - creating azure virtual network and required subnets
- securitygroup - creating network security group, setting desired security rules and associating them to subnets
- compute - creating availability sets, network interfaces and virtual machines
- database - creating database server and database
All the stacks are placed in the modules folder and the variable are stored under terraform.tfvars
To run the code you need to append the variables in the terraform.tfvars
Each module consists minimum two files: main.tf, vars.tf
resourcegroup and networking modules consists of one extra file named output.tf
Step 1 terraform init
used to initialize a working directory containing Terraform configuration files
Step 2 terraform plan
used to create an execution plan
Step 3 terraform validate
validates the configuration files in a directory, referring only to the configuration and not accessing any remote services such as remote state, provider APIs, etc
Step 4 terraform apply
used to apply the changes required to reach the desired state of the configuration