- Github: https://github.com/michaelkedey
- Linkedin: https://www.linkedin.com/in/michaelkedey
This is a cloud project which involves provissioning AWS infrastracture via terraform and automating the deployment and subsequent destruction via git actions.
- A secure VPC environment with an EC2 instance residing within a private subnet, running an Nginx web server with a proxy server, accessible to the outside world via a load balancer with a public facing listener. Traffic to the EC2 instance is routed through a NAT gateway.
- I have a src directory, .github/workflows directory, a README.md file and, test_my_code.go file in the repository.
- terraform-project-jomacs-/README.md
- terraform-project-jomacs-/test_my_code.go
- terraform-project-jomacs-/src
- .github/workflows/actions.yaml
- The src directory serves as the root of the project. It contains a main.tf file in which I created resources from modules already deffined. It also has other configurations as needed.
- terraform-project-jomacs-/src
-
The .github directory conatins a sub-directory workflows, which in turn contains an actions.yaml file. The particular placement of this file (actions.yaml) is necesarry for the succesful implementation of the cicd pipelin (create, and destroy after 10 minutes) aka automation
-
I have another directory called modules in src which contains reusable modules defined
- terraform-project-jomacs-/src/modules
- Inside the modules directory, I have 2 sub-directories which define 2 seperate reusable modules, vpc and ec2. In these sperate module directories, I defined the components and resources perculiar to each.
- terraform-project-jomacs-/src/modules/vpc
- terraform-project-jomacs-/src/modules/ec2
-
The vpc module conatins all configurations for the vpc resource, the main vpc.tf file, viriables definitions (var.tf), outputs (outputs.tf), providers configuration (providers.tf), and a store.tf file which passes neceasry values to the ssm parameter store.
-
The Ec2 module also contains all configurations for the instance, the main ec2.tf file, viriables definitions (var.tf), outputs (outputs.tf), providers configuration (providers.tf), and a data.tf file where I defined a data resource for my ami.
-
I have a vpc with 3 subnets; two public subnets in two different avaliabilty zones, and a private subnet which contains my instanace.
-
I also have a load balancer and a listener, associated with the public subnet, which distributes traffic to the security group in which the instance resides.
-
I have an Internet Gateway in the vpc which has a public route table, with routes defined which send traffic to the internet.
-
I also have a NAT Gateway residing in the public subnet, which has a route table with a route diffined which only sends outbound traffic from the private subnet through the Internet Gateway.
-
I have different security groups for the ec2 and the load balancer
-
I have an Ec2 instance, with a shell script which runs at boot time, installs nginx, sets up reverse proxy, and change the default ssh port.
-
I have automated the deployment of the infrastracture by creating a ci/cd pipeline where I have a .github/workflows directory in my root directory, in which i deffined an action.yaml file The resources get created when I push to main.
-
I have automated the testing of my code by including a test_my_code.go in my repository directory.
-
If you clone the repo, and push to github sometime, remember to take out or modify the .githiub/workflows content
- download and install terraform by adding the path to your system environent variables
- Fork or clone the repository to your local environment
- Move into the cloned repository, ceate a branch and switch to it
- Change directory into the src directory, which contains the main.tf file
- Go through the code and read the comments, and modify the code as necessary
- Run terraform init, to initialize the terraform provider configuration
- Run terraform plan, and terraform apply to have the resources created.
- Run terraform destroy to destroy all resources after you're done
- Cd into the cloned repository
- Install go and run go mod init to initialize go in the respo directory
- Run the test_my_code.go file in the repo by running go test
- UPDATE
- the test_my_code.go file is not operational
- This will create the resource, checks for some specifics like the vpc and subnets, load balancer and instance, and then destroy them when done
- vpc
- subnet 1
- subnet 2
- subnet 3
- nat gateway
- internet gateway
- load balancer
- load balancer listener
- eip
- target group
- security group 1
- security group 2
- route table association 1
- route table association 2
- route 1
- route 2
- target group attachement
- ssm parameter resource 1
- ssm parameter resource 2
- ssm parameter resource 3
- ssm parameter resource 4
- ssm parameter resource 5
- ec2