Sunday, August 30, 2020

Terraform create dev instance and deploy mariadb+springboot+vusjs+apache.

 This short blog post shows how to use terraform to provision first dev springboot+mariadb+vuejs+apache on aws linux instance(ec2).

This cloud be useful if you provision ec2 instance oftentimes.(sometimes for aws different regions-just change region)

The application I will deploy is just basic crud from frontend(vuejs)+apache2->backend springboot-> mariadb on just one amazon ec2 instance.(t2.micro)

Based on "https://grokonez.com/frontend/vue-js/spring-boot-vue-js-example-spring-data-jpa-rest-mysql-crud", I added bootstrap into main.js and java spring boot linux service library into pom.xml.

To deploy, I used a few shell scripts. 


1. Install terraform. I used latest version as of today.(LINUX DISTRO ISUBUNTU18.04+XUBUNTU)

 *)terraform install page: https://learn.hashicorp.com/tutorials/terraform/install-cli

oyj@controller:~/prac/terra-aws-dp/aws-terra-dev-dp$ terraform --version

Your version of Terraform is out of date! The latest version
is 0.13.1. You can update by downloading from https://www.terraform.io/downloads.html
Terraform v0.13.0
+ provider registry.terraform.io/hashicorp/aws v2.70.0
+ provider registry.terraform.io/hashicorp/http v1.2.0


2. Install node-https://nodejs.org/en/download/

#The fronted will need node(npm etc)

oyj@controller:~/tst/aws-terra-dev-dp$ which node
/home/oyj/node/node-v12.14.1-linux-x64/bin/node
oyj@controller:~/tst/aws-terra-dev-dp$ node --version
v12.14.1
oyj@controller:~/tst/aws-terra-dev-dp$ npm --version
6.13.4


3.Clone my github and do terraform init.(Of course after aws ec2 cli setting completed-https://docs.aws.amazon.com/cli/latest/userguide/cli-chap-configure.html)

oyj@controller:~/tst$ git clone https://github.com/ohyoungjooung2/aws-terra-dev-dp.git
Cloning into 'aws-terra-dev-dp'...
remote: Enumerating objects: 12, done.
remote: Counting objects: 100% (12/12), done.
remote: Compressing objects: 100% (10/10), done.
remote: Total 49 (delta 3), reused 9 (delta 2), pack-reused 37
Unpacking objects: 100% (49/49), done.
oyj@controller:~/tst$ ls
aws-terra-dev-dp
oyj@controller:~/tst$ cd aws-terra-dev-dp/

oyj@controller:~/tst/aws-terra-dev-dp$ terraform init

Initializing the backend...

oyj@controller:~/tst/aws-terra-dev-dp$ bash apply.sh
data.http.myip: Refreshing state...
aws_key_pair.dev_pub: Creating...
aws_vpc.dev-vpc: Creating...
aws_key_pair.dev_pub: Creation complete after 0s [id=dev_pub]
aws_vpc.dev-vpc: Creation complete after 1s [id=vpc-083def0ce4c22a2e8]
aws_internet_gateway.dev-gw: Creating...
aws_subnet.dev-db-subnet-2: Creating...


Apply complete! Resources: 10 added, 0 changed, 0 destroyed.

Outputs:

instance_ip_addr = 52.79.216.26


4. Connect  52.79.216.26 (oupputted by run terraform apply) with browser.




5. Let's destry after testing.

oyj@controller:~/tst/aws-terra-dev-dp$ bash destroy.sh
 Destroy complete! Resources: 10 destroyed.
 

 

*Conclusion)

Well, this automation is somewhat useful for studying and practicing.
I think, after provisioning this instance, each instance should be managed by  
configuration manager such "ansible,chef,puppet and etc".