Merge branch 'Azure:master' into aistudiobasic
This commit is contained in:
commit
b54a5ae10f
25
quickstart/101-aks-cluster-windows/README.md
Normal file
25
quickstart/101-aks-cluster-windows/README.md
Normal file
@ -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
quickstart/101-aks-cluster-windows/main.tf
Normal file
73
quickstart/101-aks-cluster-windows/main.tf
Normal file
@ -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
quickstart/101-aks-cluster-windows/outputs.tf
Normal file
20
quickstart/101-aks-cluster-windows/outputs.tf
Normal file
@ -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
quickstart/101-aks-cluster-windows/providers.tf
Normal file
19
quickstart/101-aks-cluster-windows/providers.tf
Normal file
@ -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
quickstart/101-aks-cluster-windows/variables.tf
Normal file
35
quickstart/101-aks-cluster-windows/variables.tf
Normal file
@ -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
quickstart/101-app-service-backup/README.md
Normal file
22
quickstart/101-app-service-backup/README.md
Normal file
@ -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
quickstart/101-app-service-backup/main.tf
Normal file
121
quickstart/101-app-service-backup/main.tf
Normal file
@ -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
quickstart/101-app-service-backup/outputs.tf
Normal file
23
quickstart/101-app-service-backup/outputs.tf
Normal file
@ -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
quickstart/101-app-service-backup/providers.tf
Normal file
18
quickstart/101-app-service-backup/providers.tf
Normal file
@ -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
quickstart/101-app-service-backup/variables.tf
Normal file
18
quickstart/101-app-service-backup/variables.tf
Normal file
@ -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."
|
||||
}
|
80
quickstart/101-authn-managed-identity/main.tf
Normal file
80
quickstart/101-authn-managed-identity/main.tf
Normal file
@ -0,0 +1,80 @@
|
||||
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
|
||||
}
|
||||
|
||||
data "azurerm_subscription" "current" {}
|
||||
|
||||
resource "azurerm_virtual_network" "example" {
|
||||
name = "myVnet"
|
||||
address_space = ["10.0.0.0/16"]
|
||||
location = azurerm_resource_group.rg.location
|
||||
resource_group_name = azurerm_resource_group.rg.name
|
||||
}
|
||||
|
||||
resource "azurerm_subnet" "example" {
|
||||
name = "mySubnet"
|
||||
resource_group_name = azurerm_resource_group.rg.name
|
||||
virtual_network_name = azurerm_virtual_network.example.name
|
||||
address_prefixes = ["10.0.2.0/24"]
|
||||
}
|
||||
|
||||
resource "azurerm_network_interface" "example" {
|
||||
name = "myNic"
|
||||
location = azurerm_resource_group.rg.location
|
||||
resource_group_name = azurerm_resource_group.rg.name
|
||||
|
||||
ip_configuration {
|
||||
name = "internal"
|
||||
subnet_id = azurerm_subnet.example.id
|
||||
private_ip_address_allocation = "Dynamic"
|
||||
}
|
||||
}
|
||||
|
||||
resource "azurerm_linux_virtual_machine" "example" {
|
||||
name = "myVm"
|
||||
resource_group_name = azurerm_resource_group.rg.name
|
||||
location = azurerm_resource_group.rg.location
|
||||
size = "Standard_F2"
|
||||
network_interface_ids = [
|
||||
azurerm_network_interface.example.id,
|
||||
]
|
||||
|
||||
computer_name = "hostname"
|
||||
admin_username = var.username
|
||||
|
||||
admin_ssh_key {
|
||||
username = var.username
|
||||
public_key = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
|
||||
identity {
|
||||
type = "SystemAssigned"
|
||||
}
|
||||
|
||||
os_disk {
|
||||
caching = "ReadWrite"
|
||||
storage_account_type = "Standard_LRS"
|
||||
}
|
||||
|
||||
source_image_reference {
|
||||
publisher = "Canonical"
|
||||
offer = "0001-com-ubuntu-server-jammy"
|
||||
sku = "22_04-lts"
|
||||
version = "latest"
|
||||
}
|
||||
}
|
||||
|
||||
data "azurerm_role_definition" "contributor" {
|
||||
name = "Contributor"
|
||||
}
|
||||
|
||||
resource "azurerm_role_assignment" "example" {
|
||||
scope = data.azurerm_subscription.current.id
|
||||
role_definition_name = "Contributor"
|
||||
principal_id = azurerm_linux_virtual_machine.example.identity[0].principal_id
|
||||
}
|
7
quickstart/101-authn-managed-identity/outputs.tf
Normal file
7
quickstart/101-authn-managed-identity/outputs.tf
Normal file
@ -0,0 +1,7 @@
|
||||
output "resource_group_name" {
|
||||
value = azurerm_resource_group.rg.name
|
||||
}
|
||||
|
||||
output "azurerm_linux_virtual_machine_name" {
|
||||
value = azurerm_linux_virtual_machine.example.name
|
||||
}
|
22
quickstart/101-authn-managed-identity/providers.tf
Normal file
22
quickstart/101-authn-managed-identity/providers.tf
Normal file
@ -0,0 +1,22 @@
|
||||
terraform {
|
||||
required_version = ">=0.12"
|
||||
|
||||
required_providers {
|
||||
azapi = {
|
||||
source = "azure/azapi"
|
||||
version = "~>1.5"
|
||||
}
|
||||
azurerm = {
|
||||
source = "hashicorp/azurerm"
|
||||
version = "~>2.0"
|
||||
}
|
||||
random = {
|
||||
source = "hashicorp/random"
|
||||
version = "~>3.0"
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
provider "azurerm" {
|
||||
features {}
|
||||
}
|
25
quickstart/101-authn-managed-identity/readme.md
Normal file
25
quickstart/101-authn-managed-identity/readme.md
Normal file
@ -0,0 +1,25 @@
|
||||
# Authentication using managed identities for Azure services
|
||||
|
||||
This template deploys a Linux virtual machine (VM) to show an example of how to use managed identities for Azure services.
|
||||
|
||||
## 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)
|
||||
- [azurerm_virtual_network](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/virtual_network)
|
||||
- [azurerm_subnet](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/subnet)
|
||||
- [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface)
|
||||
- [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine)
|
||||
- [azurerm_role_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment)
|
||||
|
||||
## 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 |
|
||||
| `username` | The username for the local account that will be created on the new VM. | azureadmin |
|
||||
|
||||
## Example
|
||||
|
||||
To see how to run this example, see [Authenticate Terraform using Managed Identity for Azure services](https://docs.microsoft.com/azure/developer/terraform/authenticate-to-azure-using-msi).
|
24
quickstart/101-authn-managed-identity/ssh.tf
Normal file
24
quickstart/101-authn-managed-identity/ssh.tf
Normal file
@ -0,0 +1,24 @@
|
||||
resource "random_pet" "ssh_key_name" {
|
||||
prefix = "ssh"
|
||||
separator = ""
|
||||
}
|
||||
|
||||
resource "azapi_resource_action" "ssh_public_key_gen" {
|
||||
type = "Microsoft.Compute/sshPublicKeys@2022-11-01"
|
||||
resource_id = azapi_resource.ssh_public_key.id
|
||||
action = "generateKeyPair"
|
||||
method = "POST"
|
||||
|
||||
response_export_values = ["publicKey", "privateKey"]
|
||||
}
|
||||
|
||||
resource "azapi_resource" "ssh_public_key" {
|
||||
type = "Microsoft.Compute/sshPublicKeys@2022-11-01"
|
||||
name = random_pet.ssh_key_name.id
|
||||
location = azurerm_resource_group.rg.location
|
||||
parent_id = azurerm_resource_group.rg.id
|
||||
}
|
||||
|
||||
output "key_data" {
|
||||
value = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
17
quickstart/101-authn-managed-identity/variables.tf
Normal file
17
quickstart/101-authn-managed-identity/variables.tf
Normal file
@ -0,0 +1,17 @@
|
||||
variable "resource_group_location" {
|
||||
type = string
|
||||
description = "Location of the resource group."
|
||||
default = "eastus"
|
||||
}
|
||||
|
||||
variable "resource_group_name_prefix" {
|
||||
type = string
|
||||
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription."
|
||||
default = "rg"
|
||||
}
|
||||
|
||||
variable "username" {
|
||||
type = string
|
||||
description = "The username for the local account that will be created on the new VM."
|
||||
default = "azureadmin"
|
||||
}
|
@ -1,3 +1,7 @@
|
||||
resource "random_pet" "prefix" {
|
||||
prefix = var.prefix
|
||||
length = 1
|
||||
}
|
||||
resource "azurerm_resource_group" "rg" {
|
||||
name = "${random_pet.prefix.id}-rg"
|
||||
location = var.resource_group_location
|
||||
@ -93,8 +97,3 @@ resource "azurerm_firewall_network_rule_collection" "net-rc" {
|
||||
]
|
||||
}
|
||||
}
|
||||
|
||||
resource "random_pet" "prefix" {
|
||||
prefix = var.prefix
|
||||
length = 1
|
||||
}
|
@ -1,3 +1,27 @@
|
||||
output "resource_group_name" {
|
||||
value = azurerm_resource_group.rg.name
|
||||
}
|
||||
|
||||
output "virtual_network_name" {
|
||||
value = azurerm_virtual_network.vnet.name
|
||||
}
|
||||
|
||||
output "subnet_name" {
|
||||
value = azurerm_subnet.subnet.name
|
||||
}
|
||||
|
||||
output "public_ip" {
|
||||
value = azurerm_public_ip.pip.ip_address
|
||||
}
|
||||
|
||||
output "firewall_name" {
|
||||
value = azurerm_firewall.main.name
|
||||
}
|
||||
|
||||
output "firewall_application_rule_collection_name" {
|
||||
value = azurerm_firewall_application_rule_collection.app-rc.name
|
||||
}
|
||||
|
||||
output "firewall_network_rule_collection" {
|
||||
value = azurerm_firewall_network_rule_collection.net-rc.name
|
||||
}
|
||||
|
@ -141,7 +141,7 @@ resource "azurerm_linux_virtual_machine" "my_terraform_vm" {
|
||||
|
||||
admin_ssh_key {
|
||||
username = var.username
|
||||
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
public_key = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
|
||||
boot_diagnostics {
|
||||
|
@ -20,5 +20,5 @@ resource "azapi_resource" "ssh_public_key" {
|
||||
}
|
||||
|
||||
output "key_data" {
|
||||
value = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
value = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
@ -102,7 +102,7 @@ resource "azurerm_linux_virtual_machine" "test" {
|
||||
|
||||
admin_ssh_key {
|
||||
username = var.username
|
||||
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
public_key = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
|
||||
os_disk {
|
||||
|
@ -20,5 +20,5 @@ resource "azapi_resource" "ssh_public_key" {
|
||||
}
|
||||
|
||||
output "key_data" {
|
||||
value = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
value = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
@ -115,7 +115,7 @@ resource "azurerm_linux_virtual_machine" "my_terraform_vm" {
|
||||
|
||||
admin_ssh_key {
|
||||
username = var.username
|
||||
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
public_key = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
|
||||
boot_diagnostics {
|
||||
|
@ -20,5 +20,5 @@ resource "azapi_resource" "ssh_public_key" {
|
||||
}
|
||||
|
||||
output "key_data" {
|
||||
value = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
value = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
@ -210,7 +210,7 @@ resource "azurerm_linux_virtual_machine" "vm_server" {
|
||||
admin_username = var.admin_username
|
||||
admin_ssh_key {
|
||||
username = var.admin_username
|
||||
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
public_key = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
network_interface_ids = [azurerm_network_interface.vm_server_nic.id]
|
||||
os_disk {
|
||||
@ -241,7 +241,7 @@ resource "azurerm_linux_virtual_machine" "vm_jump" {
|
||||
}
|
||||
admin_ssh_key {
|
||||
username = var.admin_username
|
||||
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
public_key = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
source_image_reference {
|
||||
publisher = "Canonical"
|
||||
|
@ -20,6 +20,6 @@ resource "azapi_resource" "ssh_public_key" {
|
||||
}
|
||||
|
||||
output "key_data" {
|
||||
value = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
value = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ resource "azurerm_kubernetes_cluster" "k8s" {
|
||||
admin_username = var.username
|
||||
|
||||
ssh_key {
|
||||
key_data = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
key_data = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
}
|
||||
network_profile {
|
||||
|
@ -20,5 +20,5 @@ resource "azapi_resource" "ssh_public_key" {
|
||||
}
|
||||
|
||||
output "key_data" {
|
||||
value = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
value = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
@ -146,7 +146,7 @@ resource "azurerm_linux_virtual_machine" "my_terraform_vm" {
|
||||
|
||||
admin_ssh_key {
|
||||
username = var.username
|
||||
public_key = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
public_key = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
|
||||
boot_diagnostics {
|
||||
|
@ -20,5 +20,5 @@ resource "azapi_resource" "ssh_public_key" {
|
||||
}
|
||||
|
||||
output "key_data" {
|
||||
value = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
value = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
@ -181,7 +181,7 @@ resource "azurerm_virtual_machine_scale_set" "vmss" {
|
||||
|
||||
ssh_keys {
|
||||
path = "/home/azureuser/.ssh/authorized_keys"
|
||||
key_data = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
key_data = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
}
|
||||
|
||||
@ -256,7 +256,7 @@ resource "azurerm_virtual_machine" "jumpbox" {
|
||||
|
||||
ssh_keys {
|
||||
path = "/home/azureuser/.ssh/authorized_keys"
|
||||
key_data = jsondecode(azapi_resource_action.ssh_public_key_gen.output).publicKey
|
||||
key_data = azapi_resource_action.ssh_public_key_gen.output.publicKey
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -9,10 +9,13 @@ import (
|
||||
"testing"
|
||||
|
||||
helper "github.com/Azure/terraform-module-test-helper"
|
||||
"github.com/agiledragon/gomonkey/v2"
|
||||
"github.com/gruntwork-io/terratest/modules/files"
|
||||
"github.com/gruntwork-io/terratest/modules/packer"
|
||||
"github.com/gruntwork-io/terratest/modules/shell"
|
||||
"github.com/gruntwork-io/terratest/modules/terraform"
|
||||
test_structure "github.com/gruntwork-io/terratest/modules/test-structure"
|
||||
terratest "github.com/gruntwork-io/terratest/modules/testing"
|
||||
"github.com/stretchr/testify/require"
|
||||
)
|
||||
|
||||
@ -128,6 +131,21 @@ func test201VmssPackerJumpbox(t *testing.T) {
|
||||
if tenantId := os.Getenv("ARM_TENANT_ID"); !useMsi && tenantId != "" {
|
||||
packerVars["tenant_id"] = tenantId
|
||||
}
|
||||
patches := gomonkey.ApplyFunc(shell.RunCommandAndGetOutputE, func(t terratest.TestingT, command shell.Command) (string, error) {
|
||||
output, err := shell.RunCommandAndGetStdOutE(t, command)
|
||||
if err != nil {
|
||||
return output, err
|
||||
}
|
||||
|
||||
if len(command.Args) == 1 && command.Args[0] == "-version" {
|
||||
output = strings.TrimPrefix(output, "Packer ")
|
||||
output = strings.TrimPrefix(output, "v")
|
||||
output = strings.Split(output, "\n")[0]
|
||||
}
|
||||
return output, nil
|
||||
})
|
||||
defer patches.Reset()
|
||||
|
||||
_, err := packer.BuildArtifactE(t, &packer.Options{
|
||||
Template: pkrCfg,
|
||||
Vars: packerVars,
|
||||
|
@ -4,6 +4,7 @@ go 1.19
|
||||
|
||||
require (
|
||||
github.com/Azure/terraform-module-test-helper v0.16.0
|
||||
github.com/agiledragon/gomonkey/v2 v2.11.0
|
||||
github.com/gruntwork-io/terratest v0.43.9
|
||||
github.com/stretchr/testify v1.8.4
|
||||
)
|
||||
|
Loading…
x
Reference in New Issue
Block a user