Skip to content

Commit fbfee28

Browse files
authored
Merge pull request #15 from thomast1906/updates
initial updates
2 parents e338715 + f1ec2a2 commit fbfee28

28 files changed

+358
-240
lines changed

.github/workflows/main.yml

Lines changed: 70 additions & 46 deletions
Original file line numberDiff line numberDiff line change
@@ -1,62 +1,86 @@
11
name: CI
22

33
on:
4+
push:
5+
branches:
6+
- main
7+
pull_request:
8+
branches:
9+
- main
410
workflow_dispatch:
511

612
jobs:
7-
terraform:
8-
name: 'Terraform'
13+
terraform-fmt-check:
14+
if: github.event_name == 'pull_request'
15+
defaults:
16+
run:
17+
working-directory: "./Terraform-AZURE-Services-Creation/AKS"
18+
name: Terraform
19+
environment: production
20+
runs-on: ubuntu-latest
21+
permissions:
22+
contents: write
923
env:
1024
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
1125
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
1226
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
1327
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
14-
TF_VERSION: 1.5.7
15-
runs-on: ubuntu-latest
16-
environment: production
17-
18-
# Use the Bash shell regardless whether the GitHub Actions runner is ubuntu-latest, macos-latest, or windows-latest
19-
defaults:
20-
run:
21-
shell: bash
22-
28+
tf_resource_group_name: "thomasthorntoncloud"
29+
tf_storage_account_name: "thomasthorntontfstate"
30+
tf_state_container: "devopsthehardwaygithub"
31+
tf_state_key: "terraform.tfstate"
2332
steps:
24-
# Checkout the repository to the GitHub Actions runner
25-
- name: Checkout
33+
- name: Checkout Code
2634
uses: actions/checkout@v4
27-
28-
- name: 'Terraform Format'
29-
uses: hashicorp/terraform-github-actions@master
30-
with:
31-
tf_actions_version: ${{ env.TF_VERSION }}
32-
tf_actions_subcommand: 'fmt'
33-
tf_actions_working_dir: "./Terraform-AZURE-Services-Creation/AKS"
34-
35-
- name: 'Terraform Init'
36-
uses: hashicorp/terraform-github-actions@master
37-
with:
38-
tf_actions_version: ${{ env.TF_VERSION }}
39-
tf_actions_subcommand: 'init'
40-
tf_actions_working_dir: "./Terraform-AZURE-Services-Creation/AKS"
41-
42-
- name: 'Terraform Validate'
43-
uses: hashicorp/terraform-github-actions@master
35+
36+
- name: Setup Terraform
37+
uses: hashicorp/setup-terraform@v3
4438
with:
45-
tf_actions_version: ${{ env.TF_VERSION }}
46-
tf_actions_subcommand: 'validate'
47-
tf_actions_working_dir: "./Terraform-AZURE-Services-Creation/AKS"
48-
49-
- name: 'Terraform Plan'
50-
uses: hashicorp/terraform-github-actions@master
39+
terraform_version: 1.7.4
40+
terraform_wrapper: true
41+
42+
- name: Terraform Init
43+
id: init
44+
run: terraform init
45+
env:
46+
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
47+
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
48+
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
49+
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
50+
working-directory: "./Terraform-AZURE-Services-Creation/AKS"
51+
52+
- name: Terraform Fmt
53+
id: fmt
54+
run: terraform fmt
55+
working-directory: "./Terraform-AZURE-Services-Creation/AKS"
56+
57+
- name: Auto Commit Changes
58+
uses: stefanzweifel/git-auto-commit-action@v5
5159
with:
52-
tf_actions_version: ${{ env.TF_VERSION }}
53-
tf_actions_subcommand: 'plan'
54-
tf_actions_working_dir: "./Terraform-AZURE-Services-Creation/AKS"
55-
56-
- name: Terraform Apply
60+
commit_message: "Terraform fmt"
61+
file_pattern: "*.tf *.tfvars"
62+
commit_user_name: "github-actions[bot]"
63+
64+
- name: Terraform Plan
65+
id: plan
66+
run: terraform plan -no-color -input=false
67+
env:
68+
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
69+
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
70+
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
71+
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
72+
DEPLOYMENT_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
73+
working-directory: "./Terraform-AZURE-Services-Creation/AKS"
74+
continue-on-error: false
75+
76+
- name: Terraform Apply
77+
id: apply
78+
run: terraform apply -auto-approve -input=false
5779
if: github.ref == 'refs/heads/main'
58-
uses: hashicorp/terraform-github-actions@master
59-
with:
60-
tf_actions_version: ${{ env.TF_VERSION }}
61-
tf_actions_subcommand: 'apply'
62-
tf_actions_working_dir: "./Terraform-AZURE-Services-Creation/AKS"
80+
env:
81+
ARM_CLIENT_ID: ${{ secrets.AZURE_AD_CLIENT_ID }}
82+
ARM_CLIENT_SECRET: ${{ secrets.AZURE_AD_CLIENT_SECRET }}
83+
ARM_SUBSCRIPTION_ID: ${{ secrets.AZURE_SUBSCRIPTION_ID }}
84+
ARM_TENANT_ID: ${{ secrets.AZURE_AD_TENANT_ID }}
85+
working-directory: "./Terraform-AZURE-Services-Creation/AKS"
86+
continue-on-error: false

Azure/1-Configure-Terraform-Remote-Storage.md

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ The purpose of this lab is to create the location that will store the remote Ter
55
## Create Blob Storage location for Terraform State file
66
1. Edit the [variables](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/blob/main/Azure/create-terraform-storage.sh#L3-L4)
77
2. Run the script `./create-terraform-storage.sh`
8-
3. The script will create
9-
- Azure Resource Group
10-
- Azure Storage Account
11-
- Azure Blob storage location within Azure Storage Account
8+
3. The script will:
9+
- Create an Azure Resource Group
10+
- Set up an Azure Storage Account
11+
- Establish an Azure Blob storage location within the Azure Storage Account

Docker/1-Create-Docker-Image.md

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -34,11 +34,11 @@ Now that the Docker image is created, you can run the container locally just to
3434
1. To run the Docker container, run the following command:
3535
`docker run -tid uberapp`
3636

37-
- `t` stands for a TTY console
38-
- `i` stands for interactive
39-
- `d` stands for detach so your terminal isn't directly connected to the Docker container
37+
- `t` enables a TTY console.
38+
- `i` enables an interactive session.
39+
- `d` detaches the terminal from the Docker container.
4040

41-
2. To confirm the Docker container is running, run the following command:
41+
2. Confirm that the Docker container is running by running the following command:
4242
`docker container ls`
4343

44-
You should now see the container running.
44+
You should now see the container running successfully.

Docker/2-Push Image To ACR.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,9 @@
22

33
The ACR repo will be where you store the Docker image that you created on your local computer in step 1.
44

5+
Ensure to replace `devopsthehardwayacr` with your ACR name and `v1` with the appropriate version tag if needed.
6+
7+
58
## Log Into The ECR Repository
69
1. Log in to ACR with Azure CLI
710
`az acr login --name devopsthehardwayacr`
@@ -14,3 +17,4 @@ The ACR repo will be where you store the Docker image that you created on your l
1417
## Push The Docker Image To ACR
1518
1. Push the Docker image to ACR
1619
`docker push devopsthehardwayacr.azurecr.io/uberapp:v1`
20+

README.md

Lines changed: 20 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
# DevOps-The-Hard-Way-Azure
22

3-
This tutorial contains a full, real-world solution for setting up an environment that is using DevOps technologies and practices for deploying apps and cloud services/cloud infrastructure to Azure.
3+
Welcome to the DevOps-The-Hard-Way-Azure tutorial! This comprehensive guide provides a real-world solution for implementing DevOps practices and technologies to deploy applications and cloud services/infrastructure on Microsoft Azure.
44

55
The repository contains free labs, documentation, diagrams, and docs for setting up an entire workflow and DevOps environment from a real-world perspective in Azure.
66

@@ -9,8 +9,9 @@ The scenario that you're currently facing is you work in an organization that is
99

1010
You're brought in to the company and team to make things more modern so the organization can not only succeed, but stay ahead of their competition. Management now understands the needs and complexity that comes with staying ahead of their competition and they know that they need to. Otherwise, the organization will fall...
1111

12+
1213
## DevOps Solution
13-
The solution is to deploy the Uber API for the sign-up page. Currently this solution is sitting on a bunch of baremetal, but it's time to sprinkle a little DevOps on it.
14+
The solution is to deploy the Uber API for the sign-up page. Currently this solution is sitting on a bunch of baremetal, but it's time to sprinkle a little DevOps on it. Although we won't be coding the application itself, we'll cover the deployment process using DevOps tools and methodologies.
1415

1516
![](images/uber.png)
1617

@@ -21,26 +22,16 @@ As a DevOps Engineer, you're more or less (most likely) not writing the app, but
2122
https://github.com/AdminTurnedDevOps/Python-Sample-Application
2223

2324
## Technology Details
24-
You will be using the following technologies and platforms to set up a DevOps environment.
25-
26-
1. Azure
27-
- Azure will be used to host the application, cloud infrastructure, and any other services we may need to ensure the Uber app is deployed properly.
28-
2. GitHub
29-
- To store the application and infrastructure/automation code
30-
3. Python
31-
- Python will be used for the Uber app (it is written in Python) and some automation efforts that aren't in Terraform.
32-
4. Terraform
33-
- Create an Azure ACR repository with Terraform
34-
- Create an AKS cluster
35-
5. Docker
36-
- Create a Docker image
37-
- Store the Docker image in Azure ACR
38-
6. Kubernetes
39-
- To run the Docker image that's created for the containerized Uber app. Kubernetes, in this case, AKS, will be used to orchestrate the container.
40-
7. CI/CD
41-
- Use GitHub Action to create an AKS cluster
42-
8. Automated testing
43-
- Testing Terraform code with Checkov
25+
Get ready to utilise a range of cutting-edge technologies and platforms to establish your DevOps environment:
26+
27+
1. Azure: Hosts the application, cloud infrastructure, and necessary services.
28+
2. GitHub: Stores application and infrastructure/automation code.
29+
3. Python: Powers the Uber application and some automation tasks.
30+
4. Terraform: Orchestrates Azure resources, including Azure Container Registry (ACR) and Azure Kubernetes Service (AKS).
31+
5. Docker: Creates containerized images for the Uber app and stores them in Azure ACR.
32+
6. Kubernetes: Orchestrates Docker containers, with AKS managing our Kubernetes clusters.
33+
7. CI/CD: Automates deployment using GitHub Actions.
34+
8. Automated Testing: Ensures Terraform code integrity using Checkov.
4435

4536
## Labs
4637
1. [Prerequisites](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/blob/main/prerequisites.md)
@@ -67,3 +58,10 @@ In this scenario, the Terraform State file will be stored in remote state locati
6758
- [Install And Run Checkov](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/blob/main/Terraform-Static-Code-Analysis/1-Checkov-For-Terraform.md)
6859
6. CICD - The purpose of this section is to automatically create an AKS cluster with CICD using GitHub Actions
6960
- [Create a GitHub Actions CICD pipeline](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/blob/main/Terraform-AZURE-Services-Creation/5-Run-CICD-For-AKS-Cluster.md)
61+
62+
## Conclusion
63+
By following this tutorial, you'll not only deploy an example app on Azure but also gain valuable insights into modern DevOps practices and tools.
64+
65+
Let's embark on this journey to transform your organization into a lean, agile, and competitive force in the digital landscape. Happy deploying! 🚀🔧
66+
67+

Terraform-AZURE-Services-Creation/1-Create-ACR.md

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
# Create an Azure Container Registry Repository
22

3+
Before proceeding, ensure that the values in the terraform.tfvars file are accurate for your environment. You may need to customize these values to match your specific configuration.
4+
35
In this lab you will create a repository to store the Docker image that you created for the Uber app.
46

57
## Create the ACR Terraform Configuration
68

79
1. You can find the Terraform configuration for Azure Container Registry (ACR) [here](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/tree/main/Terraform-AZURE-Services-Creation/ACR). The Terraform configuration files are used to create a repository in Azure Container Registry (ACR).
810

9-
The Terraform `main.tf` will do a few things:
11+
The Terraform `acr.tf` will:
1012
- Use a Terraform backend to store the `.tfstate` in an Azure Storage Account
1113
- Use the `uksouth` region, but feel free to change that if you'd like
1214
- Use the `azurerm_resource_group` Terraform resource to create a new Resource Group.
Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,33 @@
11
# Create an Azure VNET
22

3-
In this lab you will create a Virtual Network (VNET) that will be used to deploy your AKS instance into
3+
Before proceeding, ensure that the values in the terraform.tfvars file are accurate for your environment. You may need to customize these values to match your specific configuration.
4+
5+
In this lab you will:
6+
- Create a Virtual Network (VNET) that will be used to deploy your AKS instance into
7+
- Create a Network Security Group (NSG) and assign to the relevant subnets
8+
- Create an Azure Application Gateway for Containers and associate it with the VNET
49

510
## Create the Azure VNET Terraform Configuration
611

712
1. You can find the Terraform configuration for Azure Virtual Network [here](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/tree/main/Terraform-AZURE-Services-Creation/VNET). The Terraform configuration files are used to create an Azure Vitual Network.
813

9-
The Terraform `main.tf` will do a few things:
14+
The Terraform `vnet.tf` will:
15+
- Use a Terraform backend to store the `.tfstate` in an Azure Storage Account
1016
- Use the `azurerm_virtual_network` Terraform resource to create a VNET.
1117
- Use the `azurerm_subnet` Terraform resource to create relevant subnets.
1218
- Use the `uksouth` region, but feel free to change that if you'd like
1319

14-
2. Create the VNET by running the following:
20+
The Terraform `nsg.tf` will:
21+
- Use the `azurerm_network_security_group` Terraform resource to create a NSG.
22+
- Use the `azurerm_subnet_network_security_group_association` Terraform resource to associate the NSG to the relevant subnets.
23+
24+
The Terraform `alb.tf` will:
25+
- Use the `azurerm_application_load_balancer` Terraform resource to create an Azure Application Gateway for Containers.
26+
- Use the `azurerm_application_load_balancer_subnet_association` Terraform resource to associate the Azure Application Gateway with the VNET.
27+
- Use the `azurerm_application_load_balancer_frontend` Terraform resource to create a frontend for the Azure Application Gateway.
28+
29+
30+
2. Create the VNET, NSG & Azure Application Gateway for Containers by running the following:
1531
- `terraform init` - To initialize the working directory and pull down the provider
1632
- `terraform plan` - To go through a "check" and confirm the configurations are valid
1733
- `terraform apply` - To create the resource

Terraform-AZURE-Services-Creation/3-Create-Log-Analytics.md

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,15 @@
11
# Create an Azure Log Analytics Workspace
22

3+
Before proceeding, ensure that the values in the terraform.tfvars file are accurate for your environment. You may need to customize these values to match your specific configuration.
4+
35
In this lab you will create a Log Analytics workspace that will be used to view container insights of your AKS Cluster
46

57
## Create the Log Analytics Workspace Terraform Configuration
68

79
1. You can find the Terraform configuration for Log Analytics [here](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/tree/main/Terraform-AZURE-Services-Creation/Log-Analytics). The Terraform configuration files are used to create the Log Analytiocs workspace.
810

9-
The Terraform `main.tf` will do a few things:
11+
The Terraform `la.tf` will:
12+
- Use a Terraform backend to store the `.tfstate` in an Azure Storage Account
1013
- Use the `azurerm_log_analytics_workspace` Terraform resource to create a Log Analytics workspace.
1114
- Use the `azurerm_log_analytics_solution` Terraform resource to enable the Log Analytics solution ContainerInsights.
1215
- Use the `uksouth` region, but feel free to change that if you'd like

Terraform-AZURE-Services-Creation/4-Create-AKS-Cluster-IAM-Roles.md

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Create An AKS Cluster and IAM Roles
22

3+
Before proceeding, ensure that the values in the terraform.tfvars file are accurate for your environment. You may need to customize these values to match your specific configuration.
4+
35
In this lab you will create:
46
- The AKS cluster
57
- The appropriate IAM roles for AKS
@@ -8,11 +10,19 @@ In this lab you will create:
810

911
1. You can find the Terraform configuration for AKS [here](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/tree/main/Terraform-AZURE-Services-Creation/AKS). The Terraform configuration files are used to create an AKS cluster and IAM Role/Policy for AKS.
1012

11-
The Terraform `main.tf` will do a few things:
13+
The Terraform `aks.tf` will:
1214
- Use the `azurerm_kubernetes_cluster` Terraform resource to AKS Cluster
1315
- Use the `azurerm_role_assignment` Terraform resource to create the two neccessary role assignments
1416
- Use the `uksouth` region, but feel free to change that if you'd like
1517

18+
The Terraform `managed_identity.tf` will:
19+
- Use the `azurerm_user_assigned_identity` Terraform resource to create a user assigned identity as part of the Azure Application Gateway for Containers setup
20+
- Use the `azurerm_federated_identity_credential` Terraform resource to create a federated identity credential as part of the Azure Application Gateway for Containers setup
21+
22+
The Terraform `rbac.tf` will:
23+
- Use the `azurerm_role_assignment` Terraform resource to create the necessary role assignments for the AKS cluster
24+
- Use the `azurerm_role_definition` Terraform resource to create the necessary role definitions for the AKS cluster
25+
1626
2. In line 8 of `terraform.tfvars` replace the actual Azure AD Group ID you noted down [earlier](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/blob/main/Azure/2-Create-Azure-AD-Group-AKS-Admins.md)
1727

1828
3. Create the bucket by running the following:

Terraform-AZURE-Services-Creation/5-Run-CICD-For-AKS-Cluster.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
# Create AKS Cluster With CICD
22

3+
Before proceeding, ensure that the values in the terraform.tfvars file are accurate for your environment. You may need to customize these values to match your specific configuration.
4+
35
In this lab, you'll learn how to create an AKS cluster using GitHub Actions. The code can be found [here](https://github.com/thomast1906/DevOps-The-Hard-Way-Azure/tree/main/Terraform-AZURE-Services-Creation/AKS)
46

57

@@ -33,16 +35,16 @@ Now that the secrets are created, it's time to create the pipeline.
3335

3436
1. Under the GitHub repository, click on the **Actions** tab
3537
2. You will see a workflow already called `CI`
36-
3. Select `CI` workflow and then select `Run workflow` `from` main branch
38+
3. Select `CI` workflow and then select `Run workflow` `from` main branch (Also note, the pipeline is configured to run also during a Pull Request and or a Push to the main branch)
3739

3840
The pipeline does a few things:
39-
- On line 4, you'll see `workflow_dispatch`, which means the pipeline won't automatically run unless you kick it off. You can of course change this to have the pipeline automatically run if you, for example, push code to the `dev` or `main` branch.
41+
- On line 10, you'll see `workflow_dispatch`, which means the pipeline won't automatically run unless you kick it off. You can of course change this to have the pipeline automatically run if you, for example, push code to the `dev` or `main` branch.
4042
- The code is checked-out
4143
- Authentication occurs to Azure
4244
- Terraform is set up
43-
- Terraform format occurs
45+
- Terraform format occurs & formats incorrect terraform, then pushes back into the branch
4446
- Terraform init occurs
4547
- Terraform plan occurs
4648
- Terraform apply occurs
4749

48-
4. Run the pipeline and watch as the pipeline automatically creates the AKS cluster
50+
4. Run the pipeline and watch as the pipeline automatically create the AKS cluster

0 commit comments

Comments
 (0)