Terraform contd..
- Manual Steps:
- Create a mysql rds instance in the dbsubnet group
- instance size: db.t2.micro
- sql database engine: mysql
- version: 5.7
- security group
- credentials
- Create a mysql rds instance in the dbsubnet group
- Terraform Steps
- Security group creation: For changes Refer Here
- Lets create an rds instance. For changeset Refer Here
- Security group creation: For changes Refer Here
- Next Steps:
- Lets create an ec2 instance in app subnet
- Login into ec2 instance and execute the following commands
sudo apt update sudo apt-cache search tomcat sudo apt install tomcat8 tomcat8-admin tomcat8-common tomcat8-docs tomcat8-examples -y cd /var/lib/tomcat8/webapps/ sudo wget https://referenceappkhaja.s3-us-west-2.amazonaws.com/gameoflife.war - Automating above steps using terraform.
- Create a security group for app server Refer Here
- Creating an ec2 instance can be done by terraform resource but here we need to login into ec2 instance and install software/configuration. We have two options
- Try to create ec2 instance with image already containing software and configuration. (Automation of image creation can be done using Packer which we will be learning very soon)
- Create an ec2 instance from terraform and provision the application using
- shell scripts
- Ansible
- Salt Stack
- Chef
- Powershell Scripts
- To Perform provisioning terraform has provisioners. Refer Here
- When we are using provisioners we need to login into virtual machines which are generally windows or linux machines. To enable login into these vm’s terraform has Connection Refer Here
- Terraform has a file provisioner Refer Here which can copy the files from local machine (Where terraform is executing) into remote machine (Machine created by terraform)
- Terraform has a local-exec provisioner Refer Here which is used to run the executable on the local machine (where terraform is executing)
- Terraform has a remote-exec provisioner Refer Here which is used to run the executable on the remote machine (machine created by terraform)
- Terraform also has
- chef provisioner Refer Here
- habitat provisioner Refer Here
- Now if we observer our case,
- we need to create ec2 instance => We can use terraform resource
- login into the machine => We can use Provisioner Connection
- execute the set of linux commands => We can use remote-exec
- Refer Here for the changes done to the terraform script
- Create a security group for app server Refer Here
