Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
177 changes: 177 additions & 0 deletions .github/workflows/terraform-deploy.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,177 @@
name: Terraform Deploy to Azure

on:
workflow_dispatch:
inputs:
action:
description: 'Terraform action to perform'
required: true
default: 'plan'
type: choice
options:
- plan
- apply
- destroy
push:
branches:
- main
paths:
- 'Terraform/**'
- '.github/workflows/terraform-deploy.yml'
pull_request:
branches:
- main
paths:
- 'Terraform/**'

permissions:
id-token: write
contents: read
pull-requests: write

env:
TF_VERSION: '1.5.0'
WORKING_DIR: './Terraform'
# Terraform Backend Configuration
BACKEND_RESOURCE_GROUP: ${{ vars.TF_STATE_RESOURCE_GROUP }}
BACKEND_STORAGE_ACCOUNT: ${{ vars.TF_STATE_STORAGE_ACCOUNT }}
BACKEND_CONTAINER: ${{ vars.TF_STATE_CONTAINER }}
BACKEND_KEY: ${{ vars.TF_STATE_KEY }}
# Azure Auth
ARM_CLIENT_ID: ${{ vars.CLIENT_ID }}
ARM_SUBSCRIPTION_ID: ${{ vars.SUBSCRIPTION_ID }}
ARM_TENANT_ID: ${{ vars.TENANT_ID }}
ARM_USE_OIDC: true
# Terraform Variables
TF_VAR_resource_group_name: 'rg-vm-test1'
TF_VAR_location: 'eastus'
TF_VAR_function_app_name: fn-test-2026
TF_VAR_logic_app_name: lg-test-2026
TF_VAR_storage_account_name: ewutest2026
TF_VAR_container_app_name: ca-test-2026
TF_VAR_environment_name: development

jobs:
terraform-plan:
name: Terraform Plan
runs-on: ubuntu-latest
if: github.event_name == 'push' || github.event_name == 'pull_request' || (github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'plan')

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}

- name: Azure Login with OIDC
uses: azure/login@v1
with:
client-id: ${{ vars.CLIENT_ID }}
tenant-id: ${{ vars.TENANT_ID }}
subscription-id: ${{ vars.SUBSCRIPTION_ID }}

- name: Terraform Init
working-directory: ${{ env.WORKING_DIR }}
run: |
terraform init \
-backend-config="resource_group_name=${{ env.BACKEND_RESOURCE_GROUP }}" \
-backend-config="storage_account_name=${{ env.BACKEND_STORAGE_ACCOUNT }}" \
-backend-config="container_name=${{ env.BACKEND_CONTAINER }}" \
-backend-config="key=${{ env.BACKEND_KEY }}"

- name: Terraform Format Check
working-directory: ${{ env.WORKING_DIR }}
run: terraform fmt -check -recursive
continue-on-error: true

- name: Terraform Validate
working-directory: ${{ env.WORKING_DIR }}
run: terraform validate

- name: Terraform Plan
working-directory: ${{ env.WORKING_DIR }}
run: terraform plan

terraform-apply:
name: Terraform Apply
runs-on: ubuntu-latest
if: github.event_name == 'push' || (github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'apply')
environment: production

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}

- name: Azure Login with OIDC
uses: azure/login@v1
with:
client-id: ${{ vars.CLIENT_ID }}
tenant-id: ${{ vars.TENANT_ID }}
subscription-id: ${{ vars.SUBSCRIPTION_ID }}

- name: Terraform Init
working-directory: ${{ env.WORKING_DIR }}
run: |
terraform init \
-backend-config="resource_group_name=${{ env.BACKEND_RESOURCE_GROUP }}" \
-backend-config="storage_account_name=${{ env.BACKEND_STORAGE_ACCOUNT }}" \
-backend-config="container_name=${{ env.BACKEND_CONTAINER }}" \
-backend-config="key=${{ env.BACKEND_KEY }}"

- name: Terraform Apply
working-directory: ${{ env.WORKING_DIR }}
run: terraform apply -auto-approve

- name: Display Deployment URLs
working-directory: ${{ env.WORKING_DIR }}
run: |
echo "## Deployment Complete! 🚀" >> $GITHUB_STEP_SUMMARY
echo "" >> $GITHUB_STEP_SUMMARY
echo "### Deployed Resources:" >> $GITHUB_STEP_SUMMARY
echo "- **Container App:** $(terraform output -raw container_app_url)" >> $GITHUB_STEP_SUMMARY
echo "- **Function App:** $(terraform output -raw function_app_url)" >> $GITHUB_STEP_SUMMARY
echo "- **Logic App:** $(terraform output -raw logic_app_url)" >> $GITHUB_STEP_SUMMARY
echo "- **Resource Group:** $(terraform output -raw resource_group_name)" >> $GITHUB_STEP_SUMMARY

terraform-destroy:
name: Terraform Destroy
runs-on: ubuntu-latest
if: github.event_name == 'workflow_dispatch' && github.event.inputs.action == 'destroy'
environment: destroy

steps:
- name: Checkout code
uses: actions/checkout@v4

- name: Setup Terraform
uses: hashicorp/setup-terraform@v3
with:
terraform_version: ${{ env.TF_VERSION }}

- name: Azure Login with OIDC
uses: azure/login@v1
with:
client-id: ${{ vars.CLIENT_ID }}
tenant-id: ${{ vars.TENANT_ID }}
subscription-id: ${{ vars.SUBSCRIPTION_ID }}

- name: Terraform Init
working-directory: ${{ env.WORKING_DIR }}
run: |
terraform init \
-backend-config="resource_group_name=${{ env.BACKEND_RESOURCE_GROUP }}" \
-backend-config="storage_account_name=${{ env.BACKEND_STORAGE_ACCOUNT }}" \
-backend-config="container_name=${{ env.BACKEND_CONTAINER }}" \
-backend-config="key=${{ env.BACKEND_KEY }}"

- name: Terraform Destroy
working-directory: ${{ env.WORKING_DIR }}
run: terraform destroy -auto-approve
51 changes: 13 additions & 38 deletions Assignment2.md
Original file line number Diff line number Diff line change
@@ -1,17 +1,15 @@
# EWU-CSCD396-2023-Fall

## Assignment 2 - DRAFT!!!
## Assignment 2

The purpose of this assignment is to solidify your learning of:

- Build and deploying containers
- Terraform IaC
- Fnctions and Logic Apps
- Messaging and Eventing

## Prerequisites

- Install VSCode Extension 'Azure App Service'
- All CLI tools used in doc/containers.md such as dotnet, docker, etc.

## Instructions

Expand All @@ -25,46 +23,23 @@ Complete the following Tutorials and do not clean up resources until assignment
{https://learn.microsoft.com/en-us/azure/app-service/quickstart-dotnetcore?tabs=net70&pivots=development-environment-cli}
Note: Deploy application code using az cli, not the VSCode extension

- Web App Created ❌✅
(You can use the below steps to publish your app OR use the 'az webapp up' command in the above tutorial)
- Container App Created ❌✅
(You can use the below steps to publish your app)

- Run command from your terminal 'dotnet publish SampleApp/MyFirstAzureWebApp'. This builds the application and files are genearted in SampleApp/MyFirstAzureWebApp/bin/Debug/net7.0/publish folder
- Zip the items in your created publish folder
- Use 'az webapp deploy' command to deploy your zip file to the application
- Create a new app using dotnet new command
- See docs/containers.md for how to create and deploy an image of your new app code to azure container registry

- Url Accessible ❌✅
- Create a terraform main.tf and variables.tf files within a terraform folder. These files should contain relevant HCL for deploying a container app. ❌✅
- Use a variable for the container image name so that your workflow must pass this value into the terraform apply ❌✅
- Create a workflow that deploys your container app with Terraform using the init, plan, and apply commands adn passes your container image name into the apply ❌✅

2. Create and deploy an Auzre Function Bound to Service Bus. The function should write messages received to a storage account
- Url Accessible (and working) ❌✅
- Successful Workflow Run to Deploy Infrastructure ❌✅

{https://learn.microsoft.com/en-us/azure/app-service/scenario-secure-app-access-storage?tabs=azure-cli}

- Enabled Managed Identity on Web App ❌✅
- Created Storage Account ❌✅
- Web App Granted Access to Storage Account ❌✅

3. Add a feature to the web app to write a message to the Service Bus from step 2. Ideally this ia a text box for the message and a button to submit the message to the bus. You can use the Azure SDK for .NET to send messages to the bus from your web app.




4. Create a PowerShell script called Assignment2.ps1 on your branch within the Assignment2 folder ❌✅

- Copy the following text into your PowerShell script and fill in your specific values for the variables
```
$SubscriptionId = ""
$ResourceGroup = ""
$WebAppName = ""
$WebAppUrl = ""
$KeyVault = ""
$SecretName = ""
$StorageAccount = ""
```
- You can test if your assignment will pass by running the PS script at Scripts/Assignment2Grading.ps1. Run your Assignment2.ps1 script to set local variables first.

5. Please add jcurry9@ewu.edu as a contributor to your subscription, otherwise grading will not be possible.
4. Please add jcurry9@ewu.edu as a contributor to your subscription, otherwise grading will not be possible.


## Extra Credit

- Have the web app write the message to an Azure SQL Table in addition to the message bus
-

82 changes: 21 additions & 61 deletions Assignment3.md
Original file line number Diff line number Diff line change
@@ -1,85 +1,45 @@
# EWU-CSCD396-2023-Fall

## Assignment 3
## Assignment 3 - DRAFT!!!

The purpose of this assignment is to solidify your learning of:

- Virtual Machines
- Container Registry
- Event Grid
- Configuration of Event Grid to Subscribe to Container Registry Events
- Using Azure PowerShell
- Azure Container Instances
- Event Hub
- Build and deploying containers
- Terraform IaC
- Fnctions and Logic Apps
- Messaging and Eventing

## Prerequisites

Please add jcurry9@ewu.edu as a contributor to your subscription, otherwise grading will not be possible.
- Install VSCode Extension 'Azure App Service'

## Instructions

Complete the following Tutorials and do not clean up resources until assignment is graded.

1. Create Virtual Machine
https://learn.microsoft.com/en-us/azure/virtual-machines/windows/tutorial-manage-vm?source=recommendations

- Virtual Machine Created ❌✅

2. Create Container Registry
Note: Be sure you have docker desktop installed and running
https://learn.microsoft.com/en-us/azure/container-registry/container-registry-get-started-powershell

- Container Registry Created ❌✅
- Image tagged 'hello-word:v1' is pushed to container registy ❌✅
- All cloud infrastructure should be built with Terraform. Terraform State should be maintained in a Storage Account
- All services should be deployed through a GitHub Action workflow

3. Create an Event Grid and Send Container Registry Events (Event Grid System Topic)
https://learn.microsoft.com/en-us/azure/container-registry/container-registry-event-grid-quickstart
https://learn.microsoft.com/en-us/azure/container-registry/container-registry-event-grid-quickstart#subscribe-to-registry-events


- Event Grid Web Viewer Endpoint Available ❌✅
- Subscribe Event Grid to Container Registry Events to Create an Event Grid System Topic ❌✅

- New Image Version Pushed to Container Registry from Step 2 ❌✅
- Event Grid Subscription is Configured to Send Events to Event Viewer Web Endpoint❌✅
Complete the following Tutorials and do not clean up resources until assignment is graded.

4. Create a container instance
https://learn.microsoft.com/en-us/azure/container-instances/container-instances-quickstart
1. Create and deploy an Azure Function Bound to Service Bus. The function should write messages received to a storage account

- Container instance created ❌✅
{https://learn.microsoft.com/en-us/azure/app-service/scenario-secure-app-access-storage?tabs=azure-cli}

5. Create Event Hub
https://learn.microsoft.com/en-us/azure/event-hubs/event-hubs-quickstart-powershell
- Enabled Managed Identity on the function app ❌✅
- Create Storage Account ❌✅
- Function App Identity Granted Access to Storage Account ❌✅

- Event Hub Namespace Created ❌✅
- Event Hub Created ❌✅
- Events have been sent to your Event Hub (Submit a screenshot in your PR of Events that have been sent to your Event Hub) ❌✅
https://learn.microsoft.com/en-us/azure/event-hubs/send-and-receive-events-using-data-generator
[Screenshot Example](https://learn.microsoft.com/en-us/azure/event-hubs/send-and-receive-events-using-data-generator#view-events-using-event-hubs-data-generator)
2. Add a feature to the container app to write a message to the Service Bus from step 2. Ideally this ia a text box for the message and a button to submit the message to the bus. You can use the Azure SDK for .NET to send messages to the bus from your container app.

6. Create a PowerShell script called Assignment3.ps1 on your branch within the Assignment3 folder ❌✅
- Add an identity to the container app (by updating your terraform configuration) ❌✅
- Assign the container app identity adequate permissions on your service bus to send messages. ❌✅
- Can I enter a message on your site and see the message appear in your storage account ❌✅

- Copy the following text into your PowerShell script and fill in your specific values for the variables
```
$SubscriptionId = ""
$ResourceGroup = ""
$EventGridAppUrl = ""
$VirtualMachineName = ""
$ContainerRegistryName = ""
$ContainerRegistryPassword = ""
$EventHubNamespaceName = ""
$EventHubName = ""
$EventGridSystemTopicName = ""
$ContainerGroupName = ""
```


## Script Grading
You can test if your assignment will pass by running the PS script at Scripts/Assignment3Grading.ps1. Run your Assignment3.ps1 script to set local variables first.
4. Please add jcurry9@ewu.edu as a contributor to your subscription, otherwise grading will not be possible.

Be sure to install the Az Powershell modules that are listed as dependencies

## Extra Credit

- Create a custom image from your virtual machine named 'vm-image:v1" and push the image to your container registry. ❌✅
https://learn.microsoft.com/en-us/azure/virtual-machines/linux/tutorial-custom-images
- Have the web app write the message to an Azure SQL Table in addition to the message bus
-
Loading
Loading