Why: A company is migrating to AWS. It needs to migrate an App and its database from its on-prem server.
How: Instead of manually creating all the infrastructure and config the servers in the tediously and dangerously way, a better alternative is to automate the task using Terraform.
What it does:
- Creates a VNC, SG, IG, RT
- Creates a RDS and its 2 subnets
- Creates an EC2 instance
- Connects to EC2 and downloads the App requirements
- Creates an S3 bucket
- Copy on-prem data from source to S3
- Downloads the remaining data and deploys the App
- App accessible through Public IP
USAGE:
1 - Create a secret.tfvars
and add to it:
ssh_cidr_blocks = ["0.0.0.0/0"] // ← allowed SSH connection
db_name = "<your-db-name>"
db_username = "<your-db-username>"
db_password = "<your-db-passord>"
Run
terraform init
terraform plan -var-file="secret.tfvars"
terraform apply -var-file="secret.tfvars"
2 - Copy your ~/.aws/credentials
and ~/.aws/config
to the project root. Don't worry, they wont be uploaded to your Git Repo.
3 - Create afile dbpass
with your db password on it. Don't worry, it wont be uploaded to your Git Repo.
4 - Change dbbatch file to your user/pass and db.
4 - Run
terraform init
terraform validate
terraform plan -var-file="secret.tfvars"
terraform apply -var-file="secret.tfvars"
Wait some minutes and be happy