Installing Magento 2 on AWS with Terraform and Ansible

Updated 10 March 2021

In this blog we will see Installing magento 2 on AWS with Terraform and Ansible, at the end of this blog you will be able to deploy magento 2 on AWS using terraform.

Prerequisites

  • Ubuntu 18.04
  • Account on AWS
  • Account on Magento
  • Install terraform and ansible in server

In this Blog we will see

  • What AWS resources are build
  • How we create Access Key and Secret Key in AWS
  • How we create Key Pair in AWS
  • Create Public Key and Private Key in Magento
  • What’s inside the tf files
  • Ansible Script
  • Build AWS resources by terraform script
  • Initialize the folder
  • Plan for the magento 2 setup
  • Apply for the magento 2 setup
  • Test magento 2 site
  • Conclusion

What AWS resources are build

By the help of this terraform files the AWS resources which are build.

  • EC2 Instance with
    • t2.micro instance type
    • Attached elastic IP
  • EBS Volume with
    • 30 GB Storage
    • Volume type is General Purpose 2.
  • RDS DB Instance with
    • 20 GB storage
    • Mysql version 5.7.23
    • db.t2.micro instance class
    • Parameter Group attached with DB
    • Enabled backup and maintenance mode
  • Security Group with
    • EC2 instance security group with inbound ports 22, 80, 443.
    • RDS DB instance security group with inbound ports 3306.

How we create Access Key and Secret Key in AWS

To create access key and secret key follow the procedure:

  • Login to your AWS account.
  • In the service section choose for “IAM” service,
  • In “IAM” service in the left side slider you will find “Users”.
  • Click on “Users” it will get you on users page.
  • At the top left of users page you will find “Add user”.
  • Click on “Add user” then enter the “username” and select the access type as “Programmatic access”.
  • When we choose “Programmatic access” at the end of this process you get Access key and Secret Key.
  • Now press “next” to add permissions for the user.
  • Then in this part choose “Attach existing policies directly” by searching and selecting for “AmazonEC2FullAccess” and “AmazonRDSFullAccess”. After this press “next”.
  • Want to use tags for user then add key and value and then press “next’.
  • Now in this part you can review all your configuration. And then click on “Create User”.
  • After creating user successfully you will find button to “Download .csv” which contains Access key and Secret key.

How we create Key Pair in AWS

If you don’t have any “Key Pair” or wants to create new one then follow this steps.

  • Open AWS account.
  • In “Compute” services go for “EC2” service.
  • Then at left side slider of EC2 service you will find “Network and Security”.
  • In “Network and Security” click on “Key Pair”.
  • In “Key Pair” at the top right corner you will find “Create Key Pair” click on it.
  • Enter the name of Key Pair, choose file format “pem” and then click on “Create”.
  • After creating the Key Pair the .pem extension file will automatically downloaded in your system.

Create Public key and Private key in Magento

To create Public key and Private key follow the steps:

  • Create account on https://magento.com/
  • In “My Account” you will find “Marketplace”, click on it.
  • Then in “My Products” check for “Access Keys”, and then client on “Create A New Access Key”.
  • After this you will find the Public key and Private key.

What’s inside the tf files

In this tf files you will get the following terraform code.

  • ec2.tf – By this we build EC2 instance along with elastic ip address.
  • provider.tf – Is use for terraform plugins which are used in this terraform script.
  • random.tf – Is use to generate password for RDS admin user.
  • rds.tf – By this we build RDS DB instance along with parameter group.
  • security-group.tf – Which is use to build security groups for EC2 instance and RDS DB instance.
  • variables.tf – Is use to take the values for all variables use under this script.

Ansible Script

Download the ansible script from link in terraform directory and unzip the script.

Link – https://github.com/siddharthchouradiya/project-silver/archive/main.zip

When you unzip the script you will find var.yml file, please update the file according to key-value pair before run the script.

Build AWS resources by terraform script

Before we start if you didn’t install terraform in your ubuntu 18.04 then follow link.

Create a folder and then add terraform script inside the folder.

Now edit “variables.tf” files to use the terraform script.

And enter the values of variables according to your AWS account. After that save the file by “ctrl+x” to exit, “y” to save and press “enter”.

Initialize the folder

In this step go to the location where all the terraform “.tf” files are located.

With the help of this initialize command terraform will download the required plugins like AWS, mysql, etc.

After completion of this command you will find hidden directory with name .terraform.

Plan for the magento 2 setup

In this step after initialize the folder, with the help of this command you will check the plan of resources which are going to create after apply command.

By this command all the resources which are going to create are shown.

Apply for the magento 2 setup

By this step we will get the execution plan to confirm the installation.

In execution plan it will show all the details of resources which will be created after installation.

After using this command it will show the execution plan and ask us to confirm that plan for further installation.

Test magento 2 site

After all this process go to your browser and open the magento 2 site with the help of “IP address”.

http://<ip-address>

It will show the Installation page of magento 2.

Conclusion

With this we can easily setup LAMP server and configure ec2 and RDS in our AWS account by some commands. After completion of this we can run our magento 2 site in the browser.

In case of any help or query, please contact us or raise a ticket.

Category(s) AWS cloud
author
. . .

Leave a Comment

Your email address will not be published. Required fields are marked*


Be the first to comment.

Start a Project






    Message Sent!

    If you have more details or questions, you can reply to the received confirmation email.

    Back to Home