This is very helpful if you want to launch free tier ubuntu ec2 instance in any Region.
Here is will show you how you can create ec2 instance, configure servers, deploy your web Application.
- OS : Ubuntu-16-LTS
- REGION: us-east-1 | us-east-2| Any other Region.
- VPC: default
- SUBNET: default
- KEYPAIR: create key locally and attach
- Allow Inbond rules - 80,443,22,8080
- Allow Outbond rules - all
- Allow SSH from Below ips only. we can access ec2 instance from these ips only.
- IP List 58.15.48.12/32,58.35.64.2/32,106.223.163.24/32
- Install Nginx web server.
- Create Virtual Host in site-available
- Deploy web page on Web server.
Hi Guys Before starting i would like to give short description about 
process how we gonna create infra,configure instance and deploy the 
code.
basically Here we are using Shell Scripting,Python,Terraform and ansible
 as backend automation.
To Create any infra we must have to create environment config files for passing Variables and infra Requirements.
$ cd mite_aws_plateform
$ ls
ansible  bin  configs  infra  main.sh  ReadMe.md  README.md  run_script  run_vars  ssl_cert  states  templates  tmp  utils
 
$ ./utils/create_environment.sh htdg
Creating Environment : /home/oem/Documents/Hari/mite_aws_plateform/configs/htdg
You entered htdg
running create_deploy_keys
Generating public/private rsa key pair.
Your identification has been saved in /home/oem/Documents/Hari/mite_aws_plateform/configs/htdg/htdg_deploy_key.
Your public key has been saved in /home/oem/Documents/Hari/mite_aws_plateform/configs/htdg/htdg_deploy_key.pub.
The key fingerprint is:
SHA256:WeRZAhWxb6n68N+jTrie3Zu+XMIyr5/whvgEW+BS528 oem@Hari-Vostro-3546
The key's randomart image is:
+---[RSA 2048]----+
|        .o*o.    |
|         o =     |
|          B .    |
|         = = .   |
|        S o *    |
|         . B o   |
|        . +.*.E .|
|         +.*.@o= |
|        .o*+B*&+ |
+----[SHA256]-----+
running write_config
 
Replace htdg with your environment name.
if you are able to see above console output it means you have created 
your config files successfully.
once you will run above command this is create your environment config 
files. You can Modify variables value accourding to infra Requirements. 
but Before any modification we must have to check out config files are 
working fine or not.
We need to run ./main.sh -e {your_environment_name} --plan command to Checking configuration files.
$ ./main.sh -e htdg --plan
    ./main.sh -e htdg --plan
    Please Provide AWS Credentials 
    running configure_aws_credentials main
    AWS A/c or Environment Owner Name: Harry
    Please Enter ENVIONMENT REGION: us-east-2
    Please Enter Access key and secret_key.
    Please Enter Access_key: AHDF*********
    Please Enter secret_key: NOfj1s********
    You have Provided Valid Key 
    running write_aws_creds
    aws region : us-east-2
    AWS ACCOUNT OWNER: HARRY 
    Access key: AHDF*********
    .....
    .....
    Plan: 3 to add, 0 to change, 0 to destroy.
    .....
 
- when you will run ./main.sh -e {your_environment_name} --plancommand it will ask AWS Account Holder name. and Region and AWS Access 
key and Secret key. once you will provide valid key it will not prompt 
again.
- Provide valid access key and secret key. 
- This i am user must have admin rights.
- At the end if you are able to see Plan: 3 to add, 0 to change, 0 to destroy.msg it means Default configration is Working Good.
just open Environment config (./configs/htdg/htdg.config) file and make some modifications as per infra Requirements.
$ vim ./configs/htdg/htdg.config
 
| Configs | Description | 
| export AWS_DEFAULT_REGION="us-east-2" | Change Variable value if you want to create instance in some other region. | 
| OS_NAME="ubuntu" | Modify OS Name if You want to launch ec2 with some other OS 
Distribution eg. centos,redhat,Amazon. but currently available only 
ubuntu | 
| export TF_VAR_instance_type="{INSTANCE_TYPE}" | Default value t2.micro - uncomment and Modify variable value with some other instance type. | 
| export TF_VAR_volume_size="8" | Default value 8GB | 
| declare -a WHITE_LIST_IP=('0.0.0.0/0' '10.52.2.5/32') | Default Value - Allow from anywhere | 
| output_ips=( PUBLIC_IPS PUBLIC_IPS ) | Default Value - instance public ip for executing Ansible playbook on this instance. | 
| declare -A ANSIBLE_HOST_ADD=( ["web"]="0" ["db"]="1"); | To Add Instance public ip in Ansible Hosts | 
Once we modified our environment config according to our infra requirement then we will test environment configs with ./main.sh -e {your_environment_name} --plan
$ ./main.sh -e htdg --plan
 
- If you are able to execute plan successfully. then you can execute ./main.sh -e {your_environment_name} --applyto create infra on aws Cloud.
- This infra will create on base of Environment Configs file.
Finally Now We are ready to Launch infra on AWS Cloud. To Create infra on aws cloud we will execute./main.sh -e htdg --apply.
$ ./main.sh -e htdg --apply
    .....
    .....
    Plan: 3 to add, 0 to change, 0 to destroy.
    .....
    ...
    Are you happy with this plan (yes/no)? yes 
 
- When we will execute this command it will plan and apply on aws cloud.
- If plan output looks good then pass value yeselseno.
- Once you passed yes it will start creating resource on AWS cloud.
Guys This is the one of most important part for R n D and Destroy Complete AWS environment that managed by MITE AWS Platformbash 
  ./main.sh -e htdg --destroy
./main.sh -e htdg --apply|--apply -y
 
- We can pass -yfor confirmation with apply and destroy.
- Thanks for Reading This 
- Author : Harry
- Email : HarryTheDevopsGuy@Gmail.com
- Visit My Blog
 
0 comments:
Post a Comment