Skip to content

Commit

Permalink
Merge branch 'Azure:master' into aistudiobasic
Browse files Browse the repository at this point in the history
  • Loading branch information
andyaviles121 authored Jul 10, 2024
2 parents 85af378 + b355126 commit b54a5ae
Show file tree
Hide file tree
Showing 33 changed files with 612 additions and 21 deletions.
25 changes: 25 additions & 0 deletions quickstart/101-aks-cluster-windows/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
# Windows-based Azure Kubernetes Service (AKS) cluster

This template deploys an AKS cluster with Windows nodes.

## Terraform resource types

- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
- [azurerm_kubernetes_cluster](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster)
- [azurerm_kubernetes_cluster_node_pool](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/kubernetes_cluster_node_pool)

## Variables

| Name | Description | Default |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |
| `node_count_linux` | Initial quantity of Linux nodes for the node pool. | 1 |
| `node_count_windows` | Initial quantity of Windows nodes for the node pool. | 1 |
| `admin_username` | Admin username for the Windows node pool. | azureuser |
| `admin_password` | Admin password for the Windows node pool. | Passw0rd1234Us! |

## Example
73 changes: 73 additions & 0 deletions quickstart/101-aks-cluster-windows/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,73 @@
# Generate random resource group name
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}

resource "azurerm_resource_group" "rg" {
location = var.resource_group_location
name = random_pet.rg_name.id
}

resource "random_pet" "azurerm_kubernetes_cluster_name" {
prefix = "cluster"
}

resource "random_pet" "azurerm_kubernetes_cluster_dns_prefix" {
prefix = "dns"
}

resource "random_string" "azurerm_kubernetes_cluster_node_pool" {
length = 6
special = false
numeric = false
lower = true
upper = false
}

resource "azurerm_virtual_network" "vnet" {
name = "myvnet"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
address_space = ["10.1.0.0/16"]

subnet {
name = "subnet1"
address_prefix = "10.1.1.0/24"
}
}

resource "azurerm_kubernetes_cluster" "aks" {
name = random_pet.azurerm_kubernetes_cluster_name.id
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
dns_prefix = random_pet.azurerm_kubernetes_cluster_dns_prefix.id

identity {
type = "SystemAssigned"
}

default_node_pool {
name = "agentpool"
vm_size = "Standard_D2_v2"
node_count = var.node_count_linux
vnet_subnet_id = element(tolist(azurerm_virtual_network.vnet.subnet), 0).id
}

windows_profile {
admin_username = var.admin_username
admin_password = var.admin_password
}

network_profile {
network_plugin = "azure"
load_balancer_sku = "standard"
}
}

resource "azurerm_kubernetes_cluster_node_pool" "win" {
name = random_string.azurerm_kubernetes_cluster_node_pool.result
kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id
vm_size = "Standard_D4s_v3"
node_count = var.node_count_windows
os_type = "Windows"
}
20 changes: 20 additions & 0 deletions quickstart/101-aks-cluster-windows/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "kubernetes_cluster_name" {
value = azurerm_kubernetes_cluster.aks.name
}

output "kubernetes_cluster_dns_prefix" {
value = azurerm_kubernetes_cluster.aks.dns_prefix
}

output "kubernetes_cluster_node_pool_name" {
value = azurerm_kubernetes_cluster_node_pool.win.name
}

output "kubernetes_cluster_kube_config_raw" {
value = azurerm_kubernetes_cluster.aks.kube_config_raw
sensitive = true
}
19 changes: 19 additions & 0 deletions quickstart/101-aks-cluster-windows/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
terraform {
required_version = ">= 1.0"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}

provider "azurerm" {
features {
}
}
35 changes: 35 additions & 0 deletions quickstart/101-aks-cluster-windows/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}

variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}

variable "node_count_linux" {
type = number
description = "The initial quantity of Linux nodes for the node pool."
default = 1
}

variable "node_count_windows" {
type = number
description = "The initial quantity of Windows nodes for the node pool."
default = 1
}

variable "admin_username" {
type = string
description = "The admin username for the Windows node pool."
default = "azureuser"
}

variable "admin_password" {
type = string
description = "The admin password for the Windows node pool."
default = "Passw0rd1234Us!"
}
22 changes: 22 additions & 0 deletions quickstart/101-app-service-backup/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# Azure Windows Web App with Backup

This template deploys an Azure Windows Web App with a backup configured.

## Terraform resource types

- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet)
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group)
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string)
- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account)
- [azurerm_storage_container](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_container)
- [azurerm_service_plan](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/service_plan)
- [azurerm_windows_web_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/windows_web_app)

## Variables

| Name | Description | Default value |
|-|-|-|
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg |
| `resource_group_location` | Location of the resource group. | eastus |

## Example
121 changes: 121 additions & 0 deletions quickstart/101-app-service-backup/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
resource "random_pet" "rg_name" {
prefix = var.resource_group_name_prefix
}

resource "azurerm_resource_group" "rg" {
location = var.resource_group_location
name = random_pet.rg_name.id
}

resource "random_string" "storage_account_name" {
length = 8
lower = true
numeric = false
special = false
upper = false
}

resource "azurerm_storage_account" "example" {
name = random_string.storage_account_name.result
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
account_tier = "Standard"
account_replication_type = "LRS"
}

resource "random_string" "storage_container_name" {
length = 8
lower = true
numeric = false
special = false
upper = false
}

resource "azurerm_storage_container" "example" {
name = random_string.storage_container_name.result
storage_account_name = azurerm_storage_account.example.name
container_access_type = "private"
}

resource "random_string" "service_plan_name" {
length = 8
lower = true
numeric = false
special = false
upper = false
}

resource "azurerm_service_plan" "example" {
name = random_string.service_plan_name.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
os_type = "Windows"
sku_name = "S1"
}

data "azurerm_storage_account_sas" "example" {
connection_string = azurerm_storage_account.example.primary_connection_string
https_only = true

resource_types {
service = false
container = false
object = true
}

services {
blob = true
queue = false
table = false
file = false
}

# Please change the start_date variable (in variables.tf) to the appropriate
# value for your environment.
start = formatdate(var.start_date, timestamp())
expiry = formatdate(var.start_date, timeadd(timestamp(), "8765h"))

permissions {
read = false
write = true
delete = false
list = false
add = false
create = false
update = false
process = false
tag = false
filter = false
}
}

resource "random_string" "windows_web_app_name" {
length = 8
lower = true
numeric = false
special = false
upper = false
}

resource "azurerm_windows_web_app" "example" {
name = random_string.windows_web_app_name.result
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
service_plan_id = azurerm_service_plan.example.id

backup {
name = "Example"
storage_account_url = "https://${azurerm_storage_account.example.name}.blob.core.windows.net/${azurerm_storage_container.example.name}${data.azurerm_storage_account_sas.example.sas}&sr=b"
schedule {
frequency_interval = 30
frequency_unit = "Day"
}
}

site_config {
application_stack {
dotnet_version = "v6.0"
current_stack = "dotnet"
}
}
}
23 changes: 23 additions & 0 deletions quickstart/101-app-service-backup/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "storage_account_name" {
value = azurerm_storage_account.example.name
}

output "storage_container_name" {
value = azurerm_storage_container.example.name
}

output "service_plan_name" {
value = azurerm_service_plan.example.name
}

output "windows_web_app_name" {
value = azurerm_windows_web_app.example.name
}

output "windows_web_app_default_hostname" {
value = azurerm_windows_web_app.example.default_hostname
}
18 changes: 18 additions & 0 deletions quickstart/101-app-service-backup/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">=1.0"

required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>3.0"
}
random = {
source = "hashicorp/random"
version = "~>3.0"
}
}
}

provider "azurerm" {
features {}
}
18 changes: 18 additions & 0 deletions quickstart/101-app-service-backup/variables.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
variable "resource_group_name_prefix" {
type = string
default = "rg"
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
}

variable "resource_group_location" {
type = string
default = "eastus"
description = "Location of the resource group."
}


variable "start_date" {
type = string
default = "2024-06-01"
description = "Start date."
}
Loading

0 comments on commit b54a5ae

Please sign in to comment.