Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Hack Update] 012-InfraAsCode-Terraform - Terraform hack rewrite & enhancements #619

Open
wants to merge 36 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
36 commits
Select commit Hold shift + click to select a range
5220d5f
Update README.md
larryclaman Mar 15, 2023
a0347f3
Merge branch 'microsoft:master' into master
larryclaman May 8, 2023
0181196
rewrite terraform hack
larryclaman May 8, 2023
218aba2
Update README.md
perktime May 12, 2023
1f202cd
Update Solution-00.md
perktime May 12, 2023
3d21637
Update Solution-01.md
perktime May 12, 2023
59aa02a
Update Solution-02.md
perktime May 12, 2023
4323d59
Update Solution-05.md
perktime May 12, 2023
7e6ae4d
Update Terraform-Challenge-00.md
perktime May 12, 2023
ad7cd01
Update Terraform-Challenge-01.md
perktime May 12, 2023
5b9af90
Update Terraform-Challenge-01.md
perktime May 12, 2023
5642f1b
Update Terraform-Challenge-02.md
perktime May 12, 2023
cd9091e
Update Terraform-Challenge-03.md
perktime May 12, 2023
e0ab00e
Update Terraform-Challenge-03.md
perktime May 12, 2023
de0758e
Update Terraform-Challenge-04.md
perktime May 12, 2023
8df4999
Update Terraform-Challenge-04.md
perktime May 12, 2023
be836fa
Update Terraform-Challenge-05.md
perktime May 12, 2023
9d2712d
Update Terraform-Challenge-06.md
perktime May 12, 2023
00829e2
Update Terraform-Challenge-07.md
perktime May 12, 2023
d8db60b
Update Terraform-Challenge-08.md
perktime May 12, 2023
c40e6cf
Rename Terraform-Challenge-00.md to Challenge-00.md
perktime May 12, 2023
028b164
Rename Terraform-Challenge-01.md to Challenge-01.md
perktime May 12, 2023
24d90f4
Rename Terraform-Challenge-02.md to Challenge-02.md
perktime May 12, 2023
2522b38
Rename Terraform-Challenge-03.md to Challenge-03.md
perktime May 12, 2023
37600c6
Rename Terraform-Challenge-04.md to Challenge-04.md
perktime May 12, 2023
1214c73
Rename Terraform-Challenge-05.md to Challenge-05.md
perktime May 12, 2023
00e30cf
Rename Terraform-Challenge-06.md to Challenge-06.md
perktime May 12, 2023
830f290
Rename Terraform-Challenge-07.md to Challenge-07.md
perktime May 12, 2023
8357823
Rename Terraform-Challenge-08.md to Challenge-08.md
perktime May 12, 2023
d4b1b1c
Update Challenge-03.md
perktime May 12, 2023
ac0ecf1
Update Challenge-04.md
perktime May 12, 2023
9c5ead4
Update Challenge-03.md
perktime May 12, 2023
4c46b5e
Update Challenge-04.md
perktime May 12, 2023
d4f4c62
Update Challenge-05.md
perktime May 12, 2023
657de06
Update Challenge-07.md
perktime May 12, 2023
64ac4a2
Update readme.md
perktime May 12, 2023
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
16 changes: 16 additions & 0 deletions 012-InfraAsCode-Terraform/.devcontainer/devcontainer.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"image": "mcr.microsoft.com/devcontainers/universal:2",
"features": {
"ghcr.io/devcontainers/features/azure-cli:1": {
"version": "latest"
},
"ghcr.io/devcontainers/features/terraform:1": {
"version": "latest",
"tflint": "latest",
"terragrunt": "latest"
},
"ghcr.io/devcontainers-contrib/features/terraform-ls-asdf:2": {
"version": "latest"
}
}
}
3 changes: 3 additions & 0 deletions 012-InfraAsCode-Terraform/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
.terraform
.terraform.lock.hcl
*.tfstate
10 changes: 10 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# What The Hack - Infrastructure As Code: Terraform - Coach's Guide

## Introduction
Welcome to the coach's guide for the Infrastructure As Code: Terraform What The Hack. Here you will find links to specific guidance for coaches for each of the challenges.

Also remember that this hack includes an optional [lecture presentation](tbd) that features short presentations to introduce key topics associated with each challenge. It is recommended that the host present each short presentation before attendees kick off that challenge.

**NOTE:** If you are a Hackathon participant, this is the answer guide. Don't cheat yourself by looking at these during the hack! Go learn something. :)

## Coach's Guides
129 changes: 129 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-00.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,129 @@
# Challenge 0: Pre-requisites - Ready, Set, Go! - Coach's Guide

**[Home](./README.md)** - [Next Challenge>](./Solution-01.md)

## Notes & Guidance

Below are more details on the pre-requisites which you may wish to share with students if they have questions about the details of any one of these.

## Azure Subscription

You will need an Azure subscription to complete this hackathon. If you don't have one...

[Sign Up for Azure HERE](https://azure.microsoft.com/en-us/free/)

Our goal in the hackathon is limiting the cost of using Azure services.

If you've never used Azure, you will get:
- $200 free credits for use for up to 30 days
- 12 months of popular free services (includes storage, Linux VMs)
- Then there are services that are free up to a certain quota

Details can be found here on [free services](https://azure.microsoft.com/en-us/free/).

If you have used Azure before, we will still try to limit cost of services by suspending, shutting down services, or destroying services before the end of the hackathon. You will still be able to use the free services (up to their quotas) like Azure App Service or Functions.

## Windows Subsystem for Linux

The Windows Subsystem for Linux (WSL) lets developers run Linux environments -- including most command-line tools, utilities, and applications -- directly on Windows, unmodified, without the overhead of a virtual machine.

WSL is an essential tool Azure admins should have on their workstations if they are running Windows! If you work with Linux servers in Azure (or anywhere), having access to WSL enables you to easily connect to them and use all the tools you're used to.

[Install the Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10)

If you drive a Mac or Linux workstation, then you've already got Terminal access, carry on! :)

## Managing Cloud Resources

We can manage cloud resources via the following ways:

- Web Interface/Dashboard
- [Azure Portal](https://portal.azure.com/)
- CLI
- [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli)
- [Azure PowerShell Cmdlets](https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps)
- CLI within Web Interface
- [Azure Cloud Shell (Bash)](https://shell.azure.com/bash)
- [Azure Cloud Shell (PowerShell)](https://shell.azure.com/powershell)


### Azure Portal

Build, manage, and monitor everything from simple web apps to complex cloud applications in a single, unified console.

Manage your resources via a web interface (i.e. GUI) at [https://portal.azure.com/](https://portal.azure.com/)

The Azure Portal is a great tool for quick prototyping, proof of concepts, and testing things out in Azure by deploying resources manually. However, when deploying production resources to Azure, it is highly recommended that you an automation tool, templates, or scripts instead of the portal.

**Note:** That's why you're participating in this "Infrastructure as Code" hackathon!

### Azure CLI

The Azure CLI is a cross-platform command-line tool providing a great experience for managing Azure resources. The CLI is designed to make scripting easy, flexibly query data, support long-running operations as non-blocking processes, and more. It is available on Windows, Mac, and Linux.

The Azure CLI will be the preferred (and supported) approach for this event, so please install the Azure CLI on your workstation. If you are not able to install the Azure CLI, or are using a workstation that is not your own, you can use the Azure CLI in the browser via the Azure Cloud Shell from the Azure Portal.

For Windows users, see the note below about how and where to install the Azure CLI!


- [Install on Windows](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?view=azure-cli-latest)
- [Install on macOS](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-macos?view=azure-cli-latest)
- Install on Linux or Windows Subsystem for Linux (WSL)
- [Install with apt on Debian or Ubuntu](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-apt?view=azure-cli-latest)
- [Install with yum on RHEL, Fedora, or CentOS](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-yum?view=azure-cli-latest)
- [Install from script](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?view=azure-cli-latest)
- [Run in Docker container](https://docs.microsoft.com/en-us/cli/azure/run-azure-cli-docker?view=azure-cli-latest)

#### Note for Windows Users

The Azure CLI can be installed locally on Windows. If you do this, you will access and use the Azure CLI from the Windows Command Prompt or PowerShell Console.

While majority of the documentation should work fine locally on Windows, as you search the web for examples of how to use the Azure CLI, the examples frequently show Azure CLI commands used in Bash shell scripts. Bash shell scripts will not run in the Windows Command Prompt or PowerShell Console.

For this reason, we recommend using [Windows Subsystem for Linux](https://docs.microsoft.com/en-us/windows/wsl/install-win10) for interacting with the Azure CLI. This means you should install the Azure CLI within your WSL environment by following the instructions for the Linux distro you are using.

Alternatively, you can use the [Azure Cloud Shell](https://shell.azure.com/bash). This is discussed shortly in the next section.

### Azure PowerShell CmdLets

Azure PowerShell provides a set of cmdlets that use the Azure Resource Manager model for managing your Azure resources.

[Install the Azure PowerShell Cmdlets](https://docs.microsoft.com/en-us/powershell/azure/install-azurerm-ps)

The Azure PowerShell Cmdlets are functionally equivalent to the Azure CLI and can be used to complete all of the challenges instead of the Azure CLI. However, the Azure PowerShell Cmdlets are required for the PowerShell DSC challenges.


### Azure Cloud Shell

The Azure Cloud Shell is a free interactive Bash or PowerShell shell that you can use to run the Azure CLI or PowerShell Cmdlets needed to complete the hackathon challenges. It has common Azure tools pre-installed and configured to use with your account. Just click the **Copy** button to copy the code, paste it into the Cloud Shell, and then press enter to run it. There are a few ways to launch the Cloud Shell:

| | |
|-----------------------------------------------|---|
| Click **Try It** in the upper right corner of a code block. | ![Cloud Shell in this article](https://github.com/MicrosoftDocs/azure-docs/raw/master/includes/media/cloud-shell-try-it/cli-try-it.png) |
| Open Cloud Shell in your browser. | [![https://shell.azure.com/bash](https://github.com/MicrosoftDocs/azure-docs/raw/master/includes/media/cloud-shell-try-it/launchcloudshell.png)](https://shell.azure.com/bash) |
| Click the **Cloud Shell** button on the menu in the upper right of the [Azure portal](https://portal.azure.com). | ![Cloud Shell in the portal](https://github.com/MicrosoftDocs/azure-docs/raw/master/includes/media/cloud-shell-try-it/cloud-shell-menu.png) |
| | |


**Note:** If you use the Azure CLI or PowerShell from the Azure Cloud Shell, you will need to copy the template files you will be creating and editing on your workstation during the hackathon to the Cloud Shell environment.


## Visual Studio Code

Visual Studio Code is a lightweight but powerful source code editor which runs on your desktop and is available for Windows, macOS and Linux. It comes with built-in support for JavaScript, TypeScript and Node.js and has a rich ecosystem of extensions for other languages (such as C++, C#, Java, Python, PHP, Go) and runtimes (such as .NET and Unity).

[**Install Visual Studio Code**](https://code.visualstudio.com/)

VS Code runs on Windows, Mac, and Linux. Yes, Mac AND Linux! It's a quick install, NOT a 2 hour install like its namesake full-fledged IDE tool on Windows.

### Visual Studio Code plugins for Bicep

VS Code is lightweight because there is an ecosystem of plugins that help provide support for many different programming languages and file types. There are two plugins available which we recommend for creating and editing ARM templates in VS Code. We will be using these during the hackathon.

[**Bicep Plugin**](https://marketplace.visualstudio.com/items?itemName=ms-azuretools.vscode-bicep)

This extension provides language support for Bicep and its language expressions. It adds syntax color-coding support and intellisense for editing Bicep file in VS Code.

[**Bicep CLI**](https://github.com/Azure/bicep/blob/main/docs/installing.md)

Compiles Bicep files into ARM templates. Cross-platform.
9 changes: 9 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-01.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
# Challenge 1: Basic Terraform - Coach's Guide

[< Previous Challenge](./Solution-00.md) - **[Home](./README.md)** - [Next Challenge>](./Solution-02.md)

## Notes & Guidance

This is the "Hello World" challenge. The goal is to deploy an Azure Storage Account to a targeted resource group. This storage account will be accessed again in Challenge 2.

If you are self-hosting, it is recommended that you prefix your resources with your initials to avoid conflicts.
8 changes: 8 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-02.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Challenge 2: Terraform Expressions and Referencing Resources - Coach's Guide

[< Previous Challenge](./Solution-01.md) - **[Home](./README.md)** - [Next Challenge >](./Solution-03.md)

## Notes & Guidance

Please review the solution in the Solutions folder.

7 changes: 7 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-03.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Challenge 3: Advanced Resource Declarations - Coach's Guide

[< Previous Challenge](./Solution-02.md) - **[Home](./README.md)** - [Next Challenge>](./Solution-04.md)

## Notes & Guidance

Please review the solution in the Solutions folder.
11 changes: 11 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-04.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Challenge 4: Secret Values with Azure Key Vault - Coach's Guide

[< Previous Challenge](./Solution-03.md) - **[Home](./README.md)** - [Next Challenge >](./Solution-05.md)

## Notes & Guidance

This challenge, while conceptually straightforward, has a number of "gotchas" that can complicate getting it working.

+ Make sure you are using the latest version of the azurerm provider (eg >= 3.52.0). Earlier versions had problems with timing out when configuring the AKV.
+ The terraform access_policy definitions can be tricky to get working, especially if you are using cli auth. I found that most online examples use `data "azurerm_client_config" "current" {}` to grab the tenant id and current user id; however, this failed for me. I was able to get it working using `data "azuread_client_config" "current" {}`. See the file `kv.tf` for a working solution.

7 changes: 7 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-05.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Challenge 5: Deploy a Virtual Machine - Coach's Guide

[< Previous Challenge](./Solution-04.md) - **[Home](./README.md)** - [Next Challenge >](./Solution-06.md)

## Notes & Guidance

Be aware that while the sample at https://learn.microsoft.com/en-us/azure/virtual-machines/linux/quick-create-terraform is very useful/helpful, it is not 100% aligned with our challenges. Be sure that the participants do not blindly cut/paste the samples without understanding what they do.
11 changes: 11 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-06.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
# Challenge 6: Modules - Coach's Guide

[< Previous Challenge](./Solution-05.md) - **[Home](./README.md)** - [Next Challenge >](./Solution-07.md)

## Notes & Guidance

In this challenge, the student is learning about modules. A VM and VNET are separated into modules to show how to break up monoliths and promote reuse.

A dependent module should not assume anything about how a prior module operated. It's not a good practice to pass in the name of a resource-to-be-created to a module and then recreate a resource ID in the next module using that same name. Instead, the module that created the resource should output its resource ID, name, and other properties that might be required. The dependent module should use those output values as input parameters.

Please review the solution in the Solutions folder.
7 changes: 7 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-07.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Challenge 7: Azure Container Apps (ACA) - Getting started - Coach's Guide

[< Previous Challenge](./Solution-06.md) - **[Home](./README.md)** - [Next Challenge>](./Solution-08.md)

## Notes & Guidance

Please review the solution in the Solutions folder
8 changes: 8 additions & 0 deletions 012-InfraAsCode-Terraform/Coach/Solution-08.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
# Challenge 8: Advanced Azure Container Apps (ACA) - Coach's Guide

[< Previous Challenge](./Solution-07.md) - **[Home](./README.md)**

## Notes & Guidance

Please review the solution in the Solutions folder

This file was deleted.

This file was deleted.

This file was deleted.

This file was deleted.

Loading