forked from stacksimplify/terraform-on-azure-cloud
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
7a0be99
commit 55c1689
Showing
921 changed files
with
49,131 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
# Infrastructure as Code Basics | ||
|
||
## Step-01: Understand Problems with Traditional way of Managing Infrastructure | ||
- Time it takes for building multiple environments | ||
- Issues we face with different environments | ||
- Scale-Up and Scale-Down On-Demand | ||
|
||
## Step-02: Discuss how IaC with Terraform Solves them | ||
- Visibility | ||
- Stability | ||
- Scalability | ||
- Security | ||
- Audit |
147 changes: 147 additions & 0 deletions
147
02-Install-Tools-TerraformCLI-AzureCLI-VSCodeIDE/README.md
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,147 @@ | ||
--- | ||
title: Install Terraform, Azure CLI and VSCode Editor | ||
description: Install all the tools required for learning Terraform on Azure Cloud | ||
--- | ||
|
||
## Step-01: Introduction | ||
- Install [Terraform CLI](https://www.terraform.io/downloads.html) | ||
- Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) | ||
- Install [VS Code Editor](https://code.visualstudio.com/download) | ||
- Install [HashiCorp Terraform plugin for VS Code](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform) | ||
- Install [Git Client](https://git-scm.com/downloads) | ||
|
||
[![Image](https://stacksimplify.com/course-images/azure-terraform-install-1.png "HashiCorp Certified: Terraform Associate on Azure")](https://stacksimplify.com/course-images/azure-terraform-install-1.png) | ||
|
||
## Step-02: MACOS: Terraform Install | ||
- [Download Terraform MAC](https://www.terraform.io/downloads.html) | ||
- [Install CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli) | ||
- Unzip the package | ||
```t | ||
# Copy binary zip file to a folder | ||
mkdir /Users/<YOUR-USER>/Documents/terraform-install | ||
COPY Package to "terraform-install" folder | ||
|
||
# Unzip | ||
unzip <PACKAGE-NAME> | ||
unzip terraform_0.15.4_darwin_amd64.zip | ||
|
||
# Copy terraform binary to /usr/local/bin | ||
echo $PATH | ||
mv terraform /usr/local/bin | ||
|
||
# Verify Version | ||
terraform version | ||
|
||
# To Uninstall Terraform (NOT REQUIRED) | ||
rm -rf /usr/local/bin/terraform | ||
``` | ||
|
||
## Step-03: MACOS: IDE for Terraform - VS Code Editor | ||
- [Microsoft Visual Studio Code Editor](https://code.visualstudio.com/download) | ||
- [Hashicorp Terraform Plugin for VS Code](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform) | ||
- Configure [Course Github Repository](https://github.com/stacksimplify/hashicorp-certified-terraform-associate-on-azure) using VS Code Editor | ||
|
||
|
||
## Step-04: MACOS: Install Azure CLI | ||
- [Azure CLI Install](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli) | ||
- [Install Azure CLI - MAC](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-macos) | ||
```t | ||
# Install XCode | ||
brew update | ||
xcode-select --install | ||
Observation: Verify images for reference in "image-reference" folder | ||
|
||
# Sample Error (Without Xcode if we try az cli install it will through this error) | ||
Error: python@3.8: the bottle needs the Apple Command Line Tools to be installed. | ||
You can install them, if desired, with: | ||
xcode-select --install | ||
|
||
|
||
# AZ CLI Current Version (if installed) | ||
az --version | ||
|
||
# Install Azure CLI (if not installed) | ||
brew update | ||
brew install azure-cli | ||
|
||
# Upgrade az cli version | ||
az --version | ||
brew upgrade azure-cli | ||
[or] | ||
az upgrade | ||
az --version | ||
``` | ||
|
||
[![Image](https://stacksimplify.com/course-images/xcode-install-1.png "HashiCorp Certified: Terraform Associate on Azure")](https://stacksimplify.com/course-images/xcode-install-1.png) | ||
|
||
[![Image](https://stacksimplify.com/course-images/xcode-install-2.png "HashiCorp Certified: Terraform Associate on Azure")](https://stacksimplify.com/course-images/xcode-install-2.png) | ||
|
||
[![Image](https://stacksimplify.com/course-images/xcode-install-3.png "HashiCorp Certified: Terraform Associate on Azure")](https://stacksimplify.com/course-images/xcode-install-3.png) | ||
|
||
[![Image](https://stacksimplify.com/course-images/xcode-install-4.png "HashiCorp Certified: Terraform Associate on Azure")](https://stacksimplify.com/course-images/xcode-install-4.png) | ||
|
||
|
||
## Step-05: Terraform - Authenticating using the Azure CLI | ||
- [Azure Provider: Authenticating using the Azure CLI](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/guides/azure_cli) | ||
```t | ||
# Azure CLI Login | ||
az login | ||
|
||
# List Subscriptions | ||
az account list | ||
|
||
# Set Specific Subscription (if we have multiple subscriptions) | ||
az account set --subscription="SUBSCRIPTION_ID" | ||
``` | ||
|
||
## Step-06: Install Git Client | ||
- [Download Git Client](https://git-scm.com/downloads) | ||
- This is required when we are working with `Terraform Modules` | ||
|
||
## Step-07: WindowsOS: Terraform & Azure CLI Install | ||
### Step-07-01: Install Git Client | ||
- [Download Git Client](https://git-scm.com/downloads) | ||
- This is required when we are working with `Terraform Modules` | ||
|
||
### Step-07-02: Install Azure CLI | ||
- Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-windows?tabs=azure-cli) | ||
- `Step-05:Terraform - Authenticating using the Azure CLI` is going to be same for WindowsOS too. | ||
```t | ||
# Azure CLI Login | ||
az login | ||
|
||
# List Subscriptions | ||
az account list | ||
|
||
# Set Specific Subscription (if we have multiple subscriptions) | ||
az account set --subscription="SUBSCRIPTION_ID" | ||
``` | ||
|
||
### Step-07-03: Install Terraform | ||
- [Download Terraform](https://www.terraform.io/downloads.html) | ||
- [Install CLI](https://learn.hashicorp.com/tutorials/terraform/install-cli) | ||
- Unzip the package | ||
- Create new folder `terraform-bins` | ||
- Copy the `terraform.exe` to a `terraformbins` | ||
- Set PATH in windows | ||
|
||
### Step-07-04: Configure Course Git Repo | ||
- [Course Git Repo](https://github.com/stacksimplify/hashicorp-certified-terraform-associate-on-azure) | ||
- Shorten Course folder name to smaller one. Put it in C:\ Drive root path | ||
|
||
### Step-07-05: Install Visual Studio Code and Terraform Plugin | ||
- [Microsoft Visual Studio Code Editor](https://code.visualstudio.com/download) | ||
- [Hashicorp Terraform Plugin for VS Code](https://marketplace.visualstudio.com/items?itemName=HashiCorp.terraform) | ||
- Configure [Course Github Repository](https://github.com/stacksimplify/hashicorp-certified-terraform-associate-on-azure) using VS Code Editor | ||
|
||
### Step-07-06: WindowsOS: Long Path Issues for Terraform CLI | ||
- [Windows10 Long File Name or Path](https://github.com/hashicorp/terraform/issues/21173) | ||
- [Microsoft fix](https://answers.microsoft.com/en-us/windows/forum/all/windows-10-commands-with-long-path-name-are-not/13f0f7c7-d55c-4c6c-b19d-9dfec099dd45) | ||
- Our fix is to shorten our git repo names to see if that helps | ||
|
||
## Step-08: LinuxOS: Terraform & Azure CLI Install | ||
- [Download Terraform](https://www.terraform.io/downloads.html) | ||
- [Linux OS - Terraform Install](https://learn.hashicorp.com/tutorials/terraform/install-cli) | ||
- Install [Azure CLI](https://docs.microsoft.com/en-us/cli/azure/install-azure-cli-linux?pivots=script) | ||
- `Step-05:Terraform - Authenticating using the Azure CLI` is going to be same for LinuxOS too. | ||
- [Course Git Repo](https://github.com/stacksimplify/hashicorp-certified-terraform-associate-on-azure) |
Binary file added
BIN
+237 KB
...tall-Tools-TerraformCLI-AzureCLI-VSCodeIDE/images-reference/xcode-install-1.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+90.1 KB
...tall-Tools-TerraformCLI-AzureCLI-VSCodeIDE/images-reference/xcode-install-2.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+70.5 KB
...tall-Tools-TerraformCLI-AzureCLI-VSCodeIDE/images-reference/xcode-install-3.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file added
BIN
+54.3 KB
...tall-Tools-TerraformCLI-AzureCLI-VSCodeIDE/images-reference/xcode-install-4.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
--- | ||
title: Terraform Command Basics | ||
description: Learn Terraform Commands like init, validate, plan, apply and destroy | ||
--- | ||
|
||
## Step-01: Introduction | ||
- Understand basic Terraform Commands | ||
1. terraform init | ||
2. terraform validate | ||
3. terraform plan | ||
4. terraform apply | ||
5. terraform destroy | ||
|
||
[![Image](https://stacksimplify.com/course-images/azure-terraform-workflow-1.png "HashiCorp Certified: Terraform Associate on Azure")](https://stacksimplify.com/course-images/azure-terraform-workflow-1.png) | ||
|
||
[![Image](https://stacksimplify.com/course-images/azure-terraform-workflow-2.png "HashiCorp Certified: Terraform Associate on Azure")](https://stacksimplify.com/course-images/azure-terraform-workflow-2.png) | ||
|
||
## Step-02: Review terraform manifests | ||
- **Pre-Conditions-1:** Get Azure Regions and decide the region where you want to create resources | ||
```t | ||
# Get Azure Regions | ||
az account list-locations -o table | ||
``` | ||
- **Pre-Conditions-2:** If not done earlier, complete `az login` via Azure CLI. We are going to use Azure CLI Authentication for Terraform when we use Terraform Commands. | ||
```t | ||
# Azure CLI Login | ||
az login | ||
|
||
# List Subscriptions | ||
az account list | ||
|
||
# Set Specific Subscription (if we have multiple subscriptions) | ||
az account set --subscription="SUBSCRIPTION_ID" | ||
``` | ||
- [Azure Regions](https://docs.microsoft.com/en-us/azure/virtual-machines/regions) | ||
- [Azure Regions Detailed](https://docs.microsoft.com/en-us/azure/best-practices-availability-paired-regions#what-are-paired-regions) | ||
```t | ||
# Terraform Settings Block | ||
terraform { | ||
required_version = ">= 1.0.0" | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = ">= 2.0" # Optional but recommended in production | ||
} | ||
} | ||
} | ||
# Configure the Microsoft Azure Provider | ||
provider "azurerm" { | ||
features {} | ||
} | ||
# Create Resource Group | ||
resource "azurerm_resource_group" "my_demo_rg1" { | ||
location = "eastus" | ||
name = "my-demo-rg1" | ||
} | ||
``` | ||
|
||
## Step-03: Terraform Core Commands | ||
```t | ||
# Terraform Initialize | ||
terraform init | ||
|
||
# Terraform Validate | ||
terraform validate | ||
|
||
# Terraform Plan to Verify what it is going to create / update / destroy | ||
terraform plan | ||
|
||
# Terraform Apply to Create Resources | ||
terraform apply | ||
``` | ||
|
||
## Step-04: Verify Azure Resource Group in Azure Management Console | ||
- Go to Azure Management Console -> Resource Groups | ||
- Verify newly created Resource Group | ||
- Review `terraform.tfstate` file | ||
|
||
## Step-05: Destroy Infrastructure | ||
```t | ||
# Destroy Azure Resource Group | ||
terraform destroy | ||
Observation: | ||
1. Verify if the resource group got deleted in Azure Management Console | ||
2. Verify terraform.tfstate file and resource group info should be removed | ||
3. Verify terraform.tfstate.backup, it should have the resource group info here stored as backup. | ||
|
||
# Delete Terraform files | ||
rm -rf .terraform* | ||
rm -rf terraform.tfstate* | ||
``` | ||
|
||
## Step-08: Conclusion | ||
- Re-iterate what we have learned in this section | ||
- Learned about Important Terraform Commands | ||
1. terraform init | ||
2. terraform validate | ||
3. terraform plan | ||
4. terraform apply | ||
5. terraform destroy | ||
|
||
|
||
|
||
|
21 changes: 21 additions & 0 deletions
21
03-Terraform-Command-Basics/terraform-manifests/azure-resource-group.tf
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
# Terraform Settings Block | ||
terraform { | ||
required_version = ">= 1.0.0" | ||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = ">= 2.0" # Optional but recommended in production | ||
} | ||
} | ||
} | ||
|
||
# Configure the Microsoft Azure Provider | ||
provider "azurerm" { | ||
features {} | ||
} | ||
|
||
# Create Resource Group | ||
resource "azurerm_resource_group" "my_demo_rg1" { | ||
location = "eastus" | ||
name = "my-demo-rg1" | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,63 @@ | ||
--- | ||
title: Terraform Configuration Language Syntax | ||
description: Learn Terraform Configuration Language Syntax like Blocks, Arguments, Comments etc | ||
--- | ||
|
||
## Step-01: Introduction | ||
- Understand Terraform Language Basics | ||
1. Understand Blocks | ||
2. Understand Arguments, Attributes & Meta-Arguments | ||
3. Understand Identifiers | ||
4. Understand Comments | ||
|
||
|
||
## Step-02: Terraform Configuration Language Syntax | ||
- Understand Blocks | ||
- Understand Arguments | ||
- Understand Identifiers | ||
- Understand Comments | ||
- [Terraform Configuration](https://www.terraform.io/docs/configuration/index.html) | ||
- [Terraform Configuration Syntax](https://www.terraform.io/docs/configuration/syntax.html) | ||
```t | ||
# Template | ||
<BLOCK TYPE> "<BLOCK LABEL>" "<BLOCK LABEL>" { | ||
# Block body | ||
<IDENTIFIER> = <EXPRESSION> # Argument | ||
} | ||
|
||
# Azure Example | ||
# Create a resource group | ||
resource "azurerm_resource_group" "myrg" { # Resource BLOCK | ||
name = "myrg-1" # Argument | ||
location = "East US" # Argument | ||
} | ||
# Create Virtual Network | ||
resource "azurerm_virtual_network" "myvnet" { # Resource BLOCK | ||
name = "myvnet-1" # Argument | ||
address_space = ["10.0.0.0/16"] | ||
location = azurerm_resource_group.myrg.location # Argument with value as expression | ||
resource_group_name = azurerm_resource_group.myrg.name # Argument with value as expression | ||
} | ||
``` | ||
|
||
## Step-03: Understand about Arguments, Attributes and Meta-Arguments. | ||
- Arguments can be `required` or `optional` | ||
- Attribues format looks like `resource_type.resource_name.attribute_name` | ||
- Meta-Arguments change a resource type's behavior (Example: count, for_each) | ||
- [Additional Reference](https://learn.hashicorp.com/tutorials/terraform/resource?in=terraform/configuration-language) | ||
- [Resource: Azure Resource Group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | ||
- [Resource: Azure Resource Group Argument Reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group#arguments-reference) | ||
- [Resource: Azure Resource Group Attribute Reference](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group#attributes-reference) | ||
- [Resource: Meta-Arguments](https://www.terraform.io/docs/language/meta-arguments/depends_on.html) | ||
|
||
## Step-04: Understand about Terraform Top-Level Blocks | ||
- Discuss about Terraform Top-Level blocks | ||
1. Terraform Settings Block | ||
2. Provider Block | ||
3. Resource Block | ||
4. Input Variables Block | ||
5. Output Values Block | ||
6. Local Values Block | ||
7. Data Sources Block | ||
8. Modules Block | ||
|
Oops, something went wrong.