-
Clone the GitHub Repository:
git clone <repository_url>
-
Ensure that Terraform is installed on your local machine or Install it
-
Set Up your AWS Credentials AWS_ACCESS_KEY_ID, AWS_SECRET_ACCESS_KEY.
-
Generate SSH Key pair:
ssh-keygen -f mykey
This command generates 2 files mykey (private key) and mykey.pub (public key). Place the public key file in the root directory of your terraform code.
You can also reference an AWS key pair if you have already one. You should update ec2_bastion_host.tf accordingly.
-
Initialize Terraform:
terraform init
-
Review Terraform Plan (Optional):
terraform plan
You can preview the changes Terraform will make to your infrastructure. For this, you should provide the Input Variables defined in variables.tf. You can define its values as default in the variables.tf file, or you can define it as parameters of terraform plan and terraform apply commands, or Terraform will prompt you to provide their values during the terraform apply process.
😱 USERNAME and DB-PASSWORD are secrets and It's important to note that using these methods for secrets is not a best practice in production environments. For handling secrets securely, consider using more robust methods available in Terraform, such as using external secret management systems or environment variables.
-
Apply Terraform Changes:
terraform apply
Wait for Terraform to Complete, this process may take some time. Once complete, Terraform will display a summary of the changes made.
- Define the secrets of the GitHub Actions Workflow: Settings --> Secrets and Variables --> Actions --> New repository secret
The secrets to define in your github repo are listed in the next screenshot
- Trigger the pipeline by modifiying the script_bd.sql file and pushing the modification, or by manual execution as shown in the screenshot below.
If everything is fine ✔️, a connection to the DB will be established to execute the SQL code in script_db.sql. You receive a result like the screeshot below 🎉:
Destroy Resources (Optional): terraform destroy
Once you have finished testing, it's important to destroy the test environment to avoid incurring unnecessary charges from AWS 😉.
Additional details can be found here
Please note that the environment presented here is designed solely for testing purposes and may not adhere to best practices.