From 368ab4ff9bac7a57b946102df7dc4330f49ce521 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Fri, 26 Jan 2024 07:31:18 -0800 Subject: [PATCH 01/27] Added outputs --- quickstart/101-firewall-standard/main.tf | 9 ++++--- quickstart/101-firewall-standard/outputs.tf | 26 ++++++++++++++++++++- 2 files changed, 29 insertions(+), 6 deletions(-) diff --git a/quickstart/101-firewall-standard/main.tf b/quickstart/101-firewall-standard/main.tf index 2ab26001..542ec575 100644 --- a/quickstart/101-firewall-standard/main.tf +++ b/quickstart/101-firewall-standard/main.tf @@ -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 -} \ No newline at end of file diff --git a/quickstart/101-firewall-standard/outputs.tf b/quickstart/101-firewall-standard/outputs.tf index c765da63..76e46cde 100644 --- a/quickstart/101-firewall-standard/outputs.tf +++ b/quickstart/101-firewall-standard/outputs.tf @@ -1,3 +1,27 @@ output "resource_group_name" { value = azurerm_resource_group.rg.name -} \ No newline at end of file +} + +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 +} From 5257f9191166590f834aaeeb6c5be23cd1b4e03b Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Fri, 26 Jan 2024 07:37:18 -0800 Subject: [PATCH 02/27] terraform fmt --- quickstart/101-firewall-standard/outputs.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/101-firewall-standard/outputs.tf b/quickstart/101-firewall-standard/outputs.tf index 76e46cde..ca1afd65 100644 --- a/quickstart/101-firewall-standard/outputs.tf +++ b/quickstart/101-firewall-standard/outputs.tf @@ -6,11 +6,11 @@ output "virtual_network_name" { value = azurerm_virtual_network.vnet.name } -output "subnet_name"{ +output "subnet_name" { value = azurerm_subnet.subnet.name } -output "public_ip"{ +output "public_ip" { value = azurerm_public_ip.pip.ip_address } From d895942b2511bd83e4e2b8cb3e878c740391ceff Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 7 Feb 2024 04:44:15 -0800 Subject: [PATCH 03/27] User Story 208753 --- quickstart/101-app-service-backup/README.md | 22 ++++ quickstart/101-app-service-backup/main.tf | 119 ++++++++++++++++++ quickstart/101-app-service-backup/outputs.tf | 27 ++++ .../101-app-service-backup/providers.tf | 18 +++ .../101-app-service-backup/variables.tf | 11 ++ 5 files changed, 197 insertions(+) create mode 100644 quickstart/101-app-service-backup/README.md create mode 100644 quickstart/101-app-service-backup/main.tf create mode 100644 quickstart/101-app-service-backup/outputs.tf create mode 100644 quickstart/101-app-service-backup/providers.tf create mode 100644 quickstart/101-app-service-backup/variables.tf diff --git a/quickstart/101-app-service-backup/README.md b/quickstart/101-app-service-backup/README.md new file mode 100644 index 00000000..7be08270 --- /dev/null +++ b/quickstart/101-app-service-backup/README.md @@ -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 \ No newline at end of file diff --git a/quickstart/101-app-service-backup/main.tf b/quickstart/101-app-service-backup/main.tf new file mode 100644 index 00000000..6bb1575e --- /dev/null +++ b/quickstart/101-app-service-backup/main.tf @@ -0,0 +1,119 @@ +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 + } + + start = "2024-01-01" + expiry = "2024-12-31" + + 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" + } + } +} \ No newline at end of file diff --git a/quickstart/101-app-service-backup/outputs.tf b/quickstart/101-app-service-backup/outputs.tf new file mode 100644 index 00000000..44ba3e90 --- /dev/null +++ b/quickstart/101-app-service-backup/outputs.tf @@ -0,0 +1,27 @@ +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 +} + +output "windows_web_app_default_site_hostname" { + value = azurerm_windows_web_app.example.default_site_hostname +} \ No newline at end of file diff --git a/quickstart/101-app-service-backup/providers.tf b/quickstart/101-app-service-backup/providers.tf new file mode 100644 index 00000000..058b6871 --- /dev/null +++ b/quickstart/101-app-service-backup/providers.tf @@ -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 {} +} \ No newline at end of file diff --git a/quickstart/101-app-service-backup/variables.tf b/quickstart/101-app-service-backup/variables.tf new file mode 100644 index 00000000..e71c1446 --- /dev/null +++ b/quickstart/101-app-service-backup/variables.tf @@ -0,0 +1,11 @@ +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." +} \ No newline at end of file From 4c73d9da3b988966bbddaab3d6cd7647ee056647 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 7 Feb 2024 05:00:39 -0800 Subject: [PATCH 04/27] Removed incorrect output --- quickstart/101-app-service-backup/outputs.tf | 4 ---- 1 file changed, 4 deletions(-) diff --git a/quickstart/101-app-service-backup/outputs.tf b/quickstart/101-app-service-backup/outputs.tf index 44ba3e90..e4cbe491 100644 --- a/quickstart/101-app-service-backup/outputs.tf +++ b/quickstart/101-app-service-backup/outputs.tf @@ -21,7 +21,3 @@ output "windows_web_app_name" { output "windows_web_app_default_hostname" { value = azurerm_windows_web_app.example.default_hostname } - -output "windows_web_app_default_site_hostname" { - value = azurerm_windows_web_app.example.default_site_hostname -} \ No newline at end of file From ffa4aa614b560056a74a5db4a9007399f27792bc Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 10 Jun 2024 10:41:46 -0700 Subject: [PATCH 05/27] Changed per review --- quickstart/101-app-service-backup/main.tf | 6 ++++-- quickstart/101-app-service-backup/variables.tf | 7 +++++++ 2 files changed, 11 insertions(+), 2 deletions(-) diff --git a/quickstart/101-app-service-backup/main.tf b/quickstart/101-app-service-backup/main.tf index 6bb1575e..874e50af 100644 --- a/quickstart/101-app-service-backup/main.tf +++ b/quickstart/101-app-service-backup/main.tf @@ -70,8 +70,10 @@ data "azurerm_storage_account_sas" "example" { file = false } - start = "2024-01-01" - expiry = "2024-12-31" + # 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 diff --git a/quickstart/101-app-service-backup/variables.tf b/quickstart/101-app-service-backup/variables.tf index e71c1446..5320e399 100644 --- a/quickstart/101-app-service-backup/variables.tf +++ b/quickstart/101-app-service-backup/variables.tf @@ -8,4 +8,11 @@ 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." } \ No newline at end of file From 50e642f10db423f1b3dd05d21b9b75260c511fc7 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 13 Jun 2024 09:32:07 -0700 Subject: [PATCH 06/27] initial put --- quickstart/101-authn-managed-identity/main.tf | 81 +++++++++++++++++++ .../101-authn-managed-identity/outputs.tf | 7 ++ .../101-authn-managed-identity/providers.tf | 22 +++++ .../101-authn-managed-identity/readme.md | 33 ++++++++ quickstart/101-authn-managed-identity/ssh.tf | 24 ++++++ .../101-authn-managed-identity/variables.tf | 17 ++++ 6 files changed, 184 insertions(+) create mode 100644 quickstart/101-authn-managed-identity/main.tf create mode 100644 quickstart/101-authn-managed-identity/outputs.tf create mode 100644 quickstart/101-authn-managed-identity/providers.tf create mode 100644 quickstart/101-authn-managed-identity/readme.md create mode 100644 quickstart/101-authn-managed-identity/ssh.tf create mode 100644 quickstart/101-authn-managed-identity/variables.tf diff --git a/quickstart/101-authn-managed-identity/main.tf b/quickstart/101-authn-managed-identity/main.tf new file mode 100644 index 00000000..81292277 --- /dev/null +++ b/quickstart/101-authn-managed-identity/main.tf @@ -0,0 +1,81 @@ +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix +} + +resource "azurerm_resource_group" "rg" { + name = random_pet.rg_name.id + location = var.resource_group_location +} + +data "azurerm_subscription" "current" {} + +resource "azurerm_virtual_network" "example" { + name = "nanxuvnet06071" + 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 = "nanxusubnet06071" + 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 = "nanxunic06071" + 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 = "nanxuvm06071" + 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 +} + diff --git a/quickstart/101-authn-managed-identity/outputs.tf b/quickstart/101-authn-managed-identity/outputs.tf new file mode 100644 index 00000000..a008ee50 --- /dev/null +++ b/quickstart/101-authn-managed-identity/outputs.tf @@ -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 +} diff --git a/quickstart/101-authn-managed-identity/providers.tf b/quickstart/101-authn-managed-identity/providers.tf new file mode 100644 index 00000000..93ab8819 --- /dev/null +++ b/quickstart/101-authn-managed-identity/providers.tf @@ -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 {} +} \ No newline at end of file diff --git a/quickstart/101-authn-managed-identity/readme.md b/quickstart/101-authn-managed-identity/readme.md new file mode 100644 index 00000000..a41f012b --- /dev/null +++ b/quickstart/101-authn-managed-identity/readme.md @@ -0,0 +1,33 @@ +# Azure Linux VM + +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_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) +- [azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group) +- [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) +- [azurerm_network_interface_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association) +- [random_id](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) +- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) +- [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) +- [azapi_resource](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource) +- [azapi_resource_action](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource_action) + +## 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 + diff --git a/quickstart/101-authn-managed-identity/ssh.tf b/quickstart/101-authn-managed-identity/ssh.tf new file mode 100644 index 00000000..7dbe345a --- /dev/null +++ b/quickstart/101-authn-managed-identity/ssh.tf @@ -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 +} \ No newline at end of file diff --git a/quickstart/101-authn-managed-identity/variables.tf b/quickstart/101-authn-managed-identity/variables.tf new file mode 100644 index 00000000..27bfc0a7 --- /dev/null +++ b/quickstart/101-authn-managed-identity/variables.tf @@ -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" +} From 295e98af0554b58f6ccecf631a020fe9a699d7a3 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 19 Jun 2024 12:28:51 -0700 Subject: [PATCH 07/27] Fixed code --- quickstart/101-authn-managed-identity/readme.md | 16 ++++------------ 1 file changed, 4 insertions(+), 12 deletions(-) diff --git a/quickstart/101-authn-managed-identity/readme.md b/quickstart/101-authn-managed-identity/readme.md index a41f012b..55883b37 100644 --- a/quickstart/101-authn-managed-identity/readme.md +++ b/quickstart/101-authn-managed-identity/readme.md @@ -1,4 +1,4 @@ -# Azure Linux VM +# 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. @@ -6,20 +6,11 @@ This template deploys a Linux virtual machine (VM) to show an example of how to - [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_public_ip](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/public_ip) -- [azurerm_network_security_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_security_group) -- [azurerm_network_interface](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface) -- [azurerm_network_interface_security_group_association](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/network_interface_security_group_association) -- [random_id](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/id) -- [azurerm_storage_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/storage_account) +- [azurerm_network_interface](azurerm_network_interface) - [azurerm_linux_virtual_machine](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/linux_virtual_machine) -- [azapi_resource](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource) -- [azapi_resource_action](https://registry.terraform.io/providers/Azure/azapi/latest/docs/resources/azapi_resource_action) +- [azurerm_role_assignment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/role_assignment) ## Variables @@ -31,3 +22,4 @@ This template deploys a Linux virtual machine (VM) to show an example of how to ## 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). From be4de1c357593403725776630a0efdcfd596ba19 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Wed, 19 Jun 2024 13:24:42 -0700 Subject: [PATCH 08/27] Corrections --- quickstart/101-authn-managed-identity/main.tf | 11 +++++------ quickstart/101-authn-managed-identity/readme.md | 2 +- 2 files changed, 6 insertions(+), 7 deletions(-) diff --git a/quickstart/101-authn-managed-identity/main.tf b/quickstart/101-authn-managed-identity/main.tf index 81292277..aef2cdee 100644 --- a/quickstart/101-authn-managed-identity/main.tf +++ b/quickstart/101-authn-managed-identity/main.tf @@ -3,28 +3,28 @@ resource "random_pet" "rg_name" { } resource "azurerm_resource_group" "rg" { - name = random_pet.rg_name.id location = var.resource_group_location + name = random_pet.rg_name.id } data "azurerm_subscription" "current" {} resource "azurerm_virtual_network" "example" { - name = "nanxuvnet06071" + 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 = "nanxusubnet06071" + 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 = "nanxunic06071" + name = "myNic" location = azurerm_resource_group.rg.location resource_group_name = azurerm_resource_group.rg.name @@ -36,7 +36,7 @@ resource "azurerm_network_interface" "example" { } resource "azurerm_linux_virtual_machine" "example" { - name = "nanxuvm06071" + name = "myVm" resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location size = "Standard_F2" @@ -78,4 +78,3 @@ resource "azurerm_role_assignment" "example" { role_definition_name = "Contributor" principal_id = azurerm_linux_virtual_machine.example.identity[0].principal_id } - diff --git a/quickstart/101-authn-managed-identity/readme.md b/quickstart/101-authn-managed-identity/readme.md index 55883b37..e5c22bbe 100644 --- a/quickstart/101-authn-managed-identity/readme.md +++ b/quickstart/101-authn-managed-identity/readme.md @@ -8,7 +8,7 @@ This template deploys a Linux virtual machine (VM) to show an example of how to - [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](azurerm_network_interface) +- [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) From 097321f7d5da25cc8f25b013ea411c19a83ea27f Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 15 May 2024 20:45:38 +0000 Subject: [PATCH 09/27] added files --- quickstart/101-ai-studio/README.md | 44 ++++++++++++++++ quickstart/101-ai-studio/connections.tf | 26 ++++++++++ quickstart/101-ai-studio/dependent.tf | 67 +++++++++++++++++++++++++ quickstart/101-ai-studio/hub-cmk.tf | 48 ++++++++++++++++++ quickstart/101-ai-studio/hub.tf | 26 ++++++++++ quickstart/101-ai-studio/main.tf | 17 +++++++ quickstart/101-ai-studio/output.tf | 16 ++++++ quickstart/101-ai-studio/project.tf | 20 ++++++++ quickstart/101-ai-studio/variables.tf | 18 +++++++ 9 files changed, 282 insertions(+) create mode 100644 quickstart/101-ai-studio/README.md create mode 100644 quickstart/101-ai-studio/connections.tf create mode 100644 quickstart/101-ai-studio/dependent.tf create mode 100644 quickstart/101-ai-studio/hub-cmk.tf create mode 100644 quickstart/101-ai-studio/hub.tf create mode 100644 quickstart/101-ai-studio/main.tf create mode 100644 quickstart/101-ai-studio/output.tf create mode 100644 quickstart/101-ai-studio/project.tf create mode 100644 quickstart/101-ai-studio/variables.tf diff --git a/quickstart/101-ai-studio/README.md b/quickstart/101-ai-studio/README.md new file mode 100644 index 00000000..579d518f --- /dev/null +++ b/quickstart/101-ai-studio/README.md @@ -0,0 +1,44 @@ +# Azure AI Studio + +This deployment configuration specifies an [Azure AI hub](https://learn.microsoft.com/en-us/azure/ai-studio/concepts/ai-resources), +and its associated resources including Azure Key Vault, Azure Storage. You can optionally provision and attach Azure Application Insights and Azure Container Registry. + +This configuration describes the minimal set of resources you require to get started with Azure AI Studio. + +## Resources + +| Terraform Resource Type | Description | +| - | - | +| `azurerm_resource_group` | The resource group all resources get deployed into. | +| `azurerm_key_vault` | An Azure Key Vault instance associated to the Azure Machine Learning workspace. | +| `azurerm_storage_account` | An Azure Storage instance associated to the Azure Machine Learning workspace. | +| `azurerm_application_insights` | An Azure Application Insights instance associated to the Azure Machine Learning workspace. | +| `azurerm_container_registry` | An Azure Container Registry instance associated to the Azure Machine Learning workspace. | + +## Variables + +| Name | Description | Default | +| ---- | ----------- | ------- | +| names | Prefix name for dependent resources. | myfirst | +| location | The Azure region used for deployments | East US | +| sku | The SKU for AI Services resources | S0 + +## Usage + +After git cloning the repo, run the following commands after having docker running on your machine. + +```bash +terraform init + +az login + +terraform plan -var names="tftemplate" -out demo.tfplan + +terraform apply "demo.tfplan" +``` + +## Common mistakes + +1. Make sure docker is running +1. Make sure to have logged into your Azure Subscription by running ```az login```. +1. Ensure that you have the correct RBAC permissions for in your subscription, hub, and project. \ No newline at end of file diff --git a/quickstart/101-ai-studio/connections.tf b/quickstart/101-ai-studio/connections.tf new file mode 100644 index 00000000..60640c44 --- /dev/null +++ b/quickstart/101-ai-studio/connections.tf @@ -0,0 +1,26 @@ +//Create an AI Services connection. +resource "azapi_resource" "AIServicesConnection" { + type = "Microsoft.MachineLearningServices/workspaces/connections@2024-04-01-preview" + name = "Default_AIServices" + parent_id = azapi_resource.hub.id + + body = jsonencode({ + properties = { + category = "AIServices", + target = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint, + authType = "AAD", // or "APIKey" + isSharedToAll = true, + metadata = { + ApiType = "Azure", + ResourceId = azapi_resource.AIServicesResource.id + } + + credentials = { + Key = "" // <- must input APIKey here + } + + } + }) + schema_validation_enabled = false + response_export_values = ["*"] +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/dependent.tf b/quickstart/101-ai-studio/dependent.tf new file mode 100644 index 00000000..038af316 --- /dev/null +++ b/quickstart/101-ai-studio/dependent.tf @@ -0,0 +1,67 @@ + +resource "azurerm_resource_group" "default" { + name = "azapi-template-rg-${var.names}" + location = var.location +} + +resource "azurerm_storage_account" "default" { + name = "${var.names}storage" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + account_tier = "Standard" + account_replication_type = "GRS" + allow_nested_items_to_be_public = false +} + +resource "azurerm_key_vault" "default" { + name = "${var.names}keyvault" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "standard" + purge_protection_enabled = false +} + +// AzAPI AIServices +resource "azapi_resource" "AIServicesResource"{ + type = "Microsoft.CognitiveServices/accounts@2024-01-01-preview" + name = "${var.names}AIServicesResource" + location = azurerm_resource_group.default.location + parent_id = azurerm_resource_group.default.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + properties = { + apiProperties = { + statisticsEnabled = false + } + } + kind = "AIServices" + sku = { + name = var.sku + } + }) + + schema_validation_enabled = false + response_export_values = ["*"] +} + +/* The following resources are OPTIONAL. +resource "azurerm_application_insights" "default" { + name = "${var.names}appinsights" + location = azurerm_resource_group.default.location + resource_group_name = azurerm_resource_group.default.name + application_type = "web" +} + +resource "azurerm_container_registry" "default" { + name = "${var.names}contreg" + resource_group_name = azurerm_resource_group.default.name + location = azurerm_resource_group.default.location + sku = "premium" + admin_enabled = true +} +*/ \ No newline at end of file diff --git a/quickstart/101-ai-studio/hub-cmk.tf b/quickstart/101-ai-studio/hub-cmk.tf new file mode 100644 index 00000000..c29c1f3e --- /dev/null +++ b/quickstart/101-ai-studio/hub-cmk.tf @@ -0,0 +1,48 @@ +/* // To enable cmk, pass in arguments to set up keyIdentifier via cmk_keyvault_key_uri. Also comment out hub.tf. + +variable "cmk_keyvault_key_uri" { + description = "Key vault uri to access the encryption key." +} + +variable "encryption_status" { + description = "Indicates whether or not the encryption is enabled for the workspace." + default = "Enabled" +} + +resource "azapi_resource" "hub" { + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01" + name = "my-ai-hub" + location = azurerm_resource_group.default.location + parent_id = azurerm_resource_group.default.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + properties = { + description = "This is my Azure AI hub" + friendlyName = "My Hub" + storageAccount = azurerm_storage_account.default.id + keyVault = azurerm_key_vault.default.id + + /* Optional: To enable these field, the corresponding dependent resources need to be uncommented. + applicationInsight = azurerm_application_insights.default.id + containerRegistry = azurerm_container_registry.default.id + /* + + encryption = { + status = var.encryption_status + keyVaultProperties = { + keyVaultArmId = azurerm_key_vault.default.id + keyIdentifier = var.cmk_keyvault_key_uri + } + } + + } + kind = "hub" + }) + schema_validation_enabled = false +} + +*/ \ No newline at end of file diff --git a/quickstart/101-ai-studio/hub.tf b/quickstart/101-ai-studio/hub.tf new file mode 100644 index 00000000..7629f30b --- /dev/null +++ b/quickstart/101-ai-studio/hub.tf @@ -0,0 +1,26 @@ +resource "azapi_resource" "hub" { + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01" + name = "my-ai-hub" + location = azurerm_resource_group.default.location + parent_id = azurerm_resource_group.default.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + properties = { + description = "This is my Azure AI hub" + friendlyName = "My Hub" + storageAccount = azurerm_storage_account.default.id + keyVault = azurerm_key_vault.default.id + + /* Optional: To enable these field, the corresponding dependent resources need to be uncommented. + applicationInsight = azurerm_application_insights.default.id + containerRegistry = azurerm_container_registry.default.id + */ + } + kind = "hub" + }) + schema_validation_enabled = false +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/main.tf b/quickstart/101-ai-studio/main.tf new file mode 100644 index 00000000..ed091aa3 --- /dev/null +++ b/quickstart/101-ai-studio/main.tf @@ -0,0 +1,17 @@ +terraform { + required_providers { + azapi = { + source = "azure/azapi" + } + } +} + +provider "azurerm" { + features {} +} + +provider "azapi" { +} + +data "azurerm_client_config" "current" { +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/output.tf b/quickstart/101-ai-studio/output.tf new file mode 100644 index 00000000..c24deefa --- /dev/null +++ b/quickstart/101-ai-studio/output.tf @@ -0,0 +1,16 @@ +output "ResourceGroup" { + value = azurerm_resource_group.default.id +} + +output "HubId" { + value = azapi_resource.hub.id +} + +output "ProjectId" { + value = azapi_resource.project.id +} + +output "endpoint" { + value = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint +} + diff --git a/quickstart/101-ai-studio/project.tf b/quickstart/101-ai-studio/project.tf new file mode 100644 index 00000000..2bcec10b --- /dev/null +++ b/quickstart/101-ai-studio/project.tf @@ -0,0 +1,20 @@ +resource "azapi_resource" "project" { + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01" + name = "my-ai-project" + location = azurerm_resource_group.default.location + parent_id = azurerm_resource_group.default.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + properties = { + description = "This is my Azure AI PROJECT" + friendlyName = "My Project" + hubResourceId = azapi_resource.hub.id + } + kind = "project" + }) + schema_validation_enabled = false +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/variables.tf b/quickstart/101-ai-studio/variables.tf new file mode 100644 index 00000000..ae636375 --- /dev/null +++ b/quickstart/101-ai-studio/variables.tf @@ -0,0 +1,18 @@ +// Names and Try are used for naming conventions in hub.tf and depende +variable "names" { + type = string + description="This variable is used to name the hub, project, and dependent resources." + default = "tftemplate" +} + +variable "location" { + type = string + description = "This is the location for all resources" + default = "East US 2" +} + +variable "sku" { + type = string + description = "The sku name of the Azure Analysis Services server to create. Choose from: B1, B2, D1, S0, S1, S2, S3, S4, S8, S9. Some skus are region specific. See https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-overview#availability-by-region" + default = "S0" +} \ No newline at end of file From 6d7c5998500981f6d78496bce46aef9167a2152c Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Wed, 15 May 2024 21:17:25 +0000 Subject: [PATCH 10/27] merged cmk into hub.tf --- quickstart/101-ai-studio/dependent.tf | 2 +- quickstart/101-ai-studio/hub-cmk.tf | 48 --------------------------- quickstart/101-ai-studio/hub.tf | 10 ++++++ quickstart/101-ai-studio/variables.tf | 12 ++++++- 4 files changed, 22 insertions(+), 50 deletions(-) delete mode 100644 quickstart/101-ai-studio/hub-cmk.tf diff --git a/quickstart/101-ai-studio/dependent.tf b/quickstart/101-ai-studio/dependent.tf index 038af316..50958e43 100644 --- a/quickstart/101-ai-studio/dependent.tf +++ b/quickstart/101-ai-studio/dependent.tf @@ -24,7 +24,7 @@ resource "azurerm_key_vault" "default" { // AzAPI AIServices resource "azapi_resource" "AIServicesResource"{ - type = "Microsoft.CognitiveServices/accounts@2024-01-01-preview" + type = "Microsoft.CognitiveServices/accounts@2024-04-01-preview" name = "${var.names}AIServicesResource" location = azurerm_resource_group.default.location parent_id = azurerm_resource_group.default.id diff --git a/quickstart/101-ai-studio/hub-cmk.tf b/quickstart/101-ai-studio/hub-cmk.tf deleted file mode 100644 index c29c1f3e..00000000 --- a/quickstart/101-ai-studio/hub-cmk.tf +++ /dev/null @@ -1,48 +0,0 @@ -/* // To enable cmk, pass in arguments to set up keyIdentifier via cmk_keyvault_key_uri. Also comment out hub.tf. - -variable "cmk_keyvault_key_uri" { - description = "Key vault uri to access the encryption key." -} - -variable "encryption_status" { - description = "Indicates whether or not the encryption is enabled for the workspace." - default = "Enabled" -} - -resource "azapi_resource" "hub" { - type = "Microsoft.MachineLearningServices/workspaces@2024-04-01" - name = "my-ai-hub" - location = azurerm_resource_group.default.location - parent_id = azurerm_resource_group.default.id - - identity { - type = "SystemAssigned" - } - - body = jsonencode({ - properties = { - description = "This is my Azure AI hub" - friendlyName = "My Hub" - storageAccount = azurerm_storage_account.default.id - keyVault = azurerm_key_vault.default.id - - /* Optional: To enable these field, the corresponding dependent resources need to be uncommented. - applicationInsight = azurerm_application_insights.default.id - containerRegistry = azurerm_container_registry.default.id - /* - - encryption = { - status = var.encryption_status - keyVaultProperties = { - keyVaultArmId = azurerm_key_vault.default.id - keyIdentifier = var.cmk_keyvault_key_uri - } - } - - } - kind = "hub" - }) - schema_validation_enabled = false -} - -*/ \ No newline at end of file diff --git a/quickstart/101-ai-studio/hub.tf b/quickstart/101-ai-studio/hub.tf index 7629f30b..e0389340 100644 --- a/quickstart/101-ai-studio/hub.tf +++ b/quickstart/101-ai-studio/hub.tf @@ -19,6 +19,16 @@ resource "azapi_resource" "hub" { applicationInsight = azurerm_application_insights.default.id containerRegistry = azurerm_container_registry.default.id */ + + //Optional: To enable Customer Managed Keys, the corresponding + encryption = { + status = var.encryption_status + keyVaultProperties = { + keyVaultArmId = azurerm_key_vault.default.id + keyIdentifier = var.cmk_keyvault_key_uri + } + } + } kind = "hub" }) diff --git a/quickstart/101-ai-studio/variables.tf b/quickstart/101-ai-studio/variables.tf index ae636375..b83c3120 100644 --- a/quickstart/101-ai-studio/variables.tf +++ b/quickstart/101-ai-studio/variables.tf @@ -15,4 +15,14 @@ variable "sku" { type = string description = "The sku name of the Azure Analysis Services server to create. Choose from: B1, B2, D1, S0, S1, S2, S3, S4, S8, S9. Some skus are region specific. See https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-overview#availability-by-region" default = "S0" -} \ No newline at end of file +} + +//Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in hub.tf +variable "cmk_keyvault_key_uri" { + description = "Key vault uri to access the encryption key." +} + +variable "encryption_status" { + description = "Indicates whether or not the encryption is enabled for the workspace." + default = "Enabled" +} From 9df50ca6b2b2a41f0159062fabe3d2171878bf58 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 17 May 2024 20:13:17 +0000 Subject: [PATCH 11/27] fixed according to comments --- quickstart/101-ai-studio/dependent.tf | 5 +-- quickstart/101-ai-studio/hub.tf | 6 +-- quickstart/101-ai-studio/main.tf | 6 +++ quickstart/101-ai-studio/project.tf | 3 +- quickstart/101-ai-studio/variables.tf | 57 ++++++++++++++------------- 5 files changed, 41 insertions(+), 36 deletions(-) diff --git a/quickstart/101-ai-studio/dependent.tf b/quickstart/101-ai-studio/dependent.tf index 50958e43..14481aca 100644 --- a/quickstart/101-ai-studio/dependent.tf +++ b/quickstart/101-ai-studio/dependent.tf @@ -1,6 +1,6 @@ resource "azurerm_resource_group" "default" { - name = "azapi-template-rg-${var.names}" + name = "rg-${var.names}" location = var.location } @@ -24,7 +24,7 @@ resource "azurerm_key_vault" "default" { // AzAPI AIServices resource "azapi_resource" "AIServicesResource"{ - type = "Microsoft.CognitiveServices/accounts@2024-04-01-preview" + type = "Microsoft.CognitiveServices/accounts@2023-10-01-preview" name = "${var.names}AIServicesResource" location = azurerm_resource_group.default.location parent_id = azurerm_resource_group.default.id @@ -45,7 +45,6 @@ resource "azapi_resource" "AIServicesResource"{ } }) - schema_validation_enabled = false response_export_values = ["*"] } diff --git a/quickstart/101-ai-studio/hub.tf b/quickstart/101-ai-studio/hub.tf index e0389340..565ca7c1 100644 --- a/quickstart/101-ai-studio/hub.tf +++ b/quickstart/101-ai-studio/hub.tf @@ -1,5 +1,5 @@ resource "azapi_resource" "hub" { - type = "Microsoft.MachineLearningServices/workspaces@2024-04-01" + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" name = "my-ai-hub" location = azurerm_resource_group.default.location parent_id = azurerm_resource_group.default.id @@ -20,7 +20,7 @@ resource "azapi_resource" "hub" { containerRegistry = azurerm_container_registry.default.id */ - //Optional: To enable Customer Managed Keys, the corresponding + /*Optional: To enable Customer Managed Keys, the corresponding encryption = { status = var.encryption_status keyVaultProperties = { @@ -28,9 +28,9 @@ resource "azapi_resource" "hub" { keyIdentifier = var.cmk_keyvault_key_uri } } + */ } kind = "hub" }) - schema_validation_enabled = false } \ No newline at end of file diff --git a/quickstart/101-ai-studio/main.tf b/quickstart/101-ai-studio/main.tf index ed091aa3..0ac01faa 100644 --- a/quickstart/101-ai-studio/main.tf +++ b/quickstart/101-ai-studio/main.tf @@ -1,5 +1,11 @@ terraform { + required_version = ">= 1.0" + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = ">= 3.0, < 4.0" + } azapi = { source = "azure/azapi" } diff --git a/quickstart/101-ai-studio/project.tf b/quickstart/101-ai-studio/project.tf index 2bcec10b..96aee1cc 100644 --- a/quickstart/101-ai-studio/project.tf +++ b/quickstart/101-ai-studio/project.tf @@ -1,5 +1,5 @@ resource "azapi_resource" "project" { - type = "Microsoft.MachineLearningServices/workspaces@2024-04-01" + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" name = "my-ai-project" location = azurerm_resource_group.default.location parent_id = azurerm_resource_group.default.id @@ -16,5 +16,4 @@ resource "azapi_resource" "project" { } kind = "project" }) - schema_validation_enabled = false } \ No newline at end of file diff --git a/quickstart/101-ai-studio/variables.tf b/quickstart/101-ai-studio/variables.tf index b83c3120..f739c12d 100644 --- a/quickstart/101-ai-studio/variables.tf +++ b/quickstart/101-ai-studio/variables.tf @@ -1,28 +1,29 @@ -// Names and Try are used for naming conventions in hub.tf and depende -variable "names" { - type = string - description="This variable is used to name the hub, project, and dependent resources." - default = "tftemplate" -} - -variable "location" { - type = string - description = "This is the location for all resources" - default = "East US 2" -} - -variable "sku" { - type = string - description = "The sku name of the Azure Analysis Services server to create. Choose from: B1, B2, D1, S0, S1, S2, S3, S4, S8, S9. Some skus are region specific. See https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-overview#availability-by-region" - default = "S0" -} - -//Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in hub.tf -variable "cmk_keyvault_key_uri" { - description = "Key vault uri to access the encryption key." -} - -variable "encryption_status" { - description = "Indicates whether or not the encryption is enabled for the workspace." - default = "Enabled" -} +// Names and Try are used for naming conventions in hub.tf and depende +variable "names" { + type = string + description="This variable is used to name the hub, project, and dependent resources." + default = "tftemplate" +} + +variable "location" { + type = string + description = "This is the location for all resources" + default = "East US 2" +} + +variable "sku" { + type = string + description = "The sku name of the Azure Analysis Services server to create. Choose from: B1, B2, D1, S0, S1, S2, S3, S4, S8, S9. Some skus are region specific. See https://docs.microsoft.com/en-us/azure/analysis-services/analysis-services-overview#availability-by-region" + default = "S0" +} + +/*Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in hub.tf +variable "cmk_keyvault_key_uri" { + description = "Key vault uri to access the encryption key." +} + +variable "encryption_status" { + description = "Indicates whether or not the encryption is enabled for the workspace." + default = "Enabled" +} +*/ \ No newline at end of file From c15b0e61a3a1ba6e54705f4f98d099852b532f54 Mon Sep 17 00:00:00 2001 From: "github-actions[bot]" Date: Fri, 17 May 2024 20:15:08 +0000 Subject: [PATCH 12/27] removed connections schema validation skip --- quickstart/101-ai-studio/connections.tf | 1 - 1 file changed, 1 deletion(-) diff --git a/quickstart/101-ai-studio/connections.tf b/quickstart/101-ai-studio/connections.tf index 60640c44..62bb753e 100644 --- a/quickstart/101-ai-studio/connections.tf +++ b/quickstart/101-ai-studio/connections.tf @@ -21,6 +21,5 @@ resource "azapi_resource" "AIServicesConnection" { } }) - schema_validation_enabled = false response_export_values = ["*"] } \ No newline at end of file From cd38055ba378c022a4e67223a4dacef1683d1671 Mon Sep 17 00:00:00 2001 From: Andy Aviles Date: Wed, 5 Jun 2024 13:12:21 -0400 Subject: [PATCH 13/27] added in azurerm key_vault provider section in main.tf --- quickstart/101-ai-studio/main.tf | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/quickstart/101-ai-studio/main.tf b/quickstart/101-ai-studio/main.tf index 0ac01faa..c6ad21da 100644 --- a/quickstart/101-ai-studio/main.tf +++ b/quickstart/101-ai-studio/main.tf @@ -13,7 +13,16 @@ terraform { } provider "azurerm" { - features {} + features { + key_vault { + recover_soft_deleted_key_vaults = false + purge_soft_delete_on_destroy = false + purge_soft_deleted_keys_on_destroy = false + } + resource_group { + prevent_deletion_if_contains_resources = false + } + } } provider "azapi" { From d5c754a94b997081268d46d8f5a008c16acc16c3 Mon Sep 17 00:00:00 2001 From: Andy Aviles Date: Mon, 17 Jun 2024 09:50:53 -0400 Subject: [PATCH 14/27] included random string suffix --- quickstart/101-ai-studio/dependent.tf | 4 ++-- quickstart/101-ai-studio/variables.tf | 6 ++++++ 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/quickstart/101-ai-studio/dependent.tf b/quickstart/101-ai-studio/dependent.tf index 14481aca..9e95287e 100644 --- a/quickstart/101-ai-studio/dependent.tf +++ b/quickstart/101-ai-studio/dependent.tf @@ -5,7 +5,7 @@ resource "azurerm_resource_group" "default" { } resource "azurerm_storage_account" "default" { - name = "${var.names}storage" + name = "${var.names}storage${random_string.suffix.result}" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name account_tier = "Standard" @@ -14,7 +14,7 @@ resource "azurerm_storage_account" "default" { } resource "azurerm_key_vault" "default" { - name = "${var.names}keyvault" + name = "${var.names}keyvault${random_string.suffix.result}" location = azurerm_resource_group.default.location resource_group_name = azurerm_resource_group.default.name tenant_id = data.azurerm_client_config.current.tenant_id diff --git a/quickstart/101-ai-studio/variables.tf b/quickstart/101-ai-studio/variables.tf index f739c12d..2a401684 100644 --- a/quickstart/101-ai-studio/variables.tf +++ b/quickstart/101-ai-studio/variables.tf @@ -17,6 +17,12 @@ variable "sku" { default = "S0" } +resource "random_string" "suffix" { + length = 4 + special = false + upper = false +} + /*Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in hub.tf variable "cmk_keyvault_key_uri" { description = "Key vault uri to access the encryption key." From de722790959a67782ff9bab9d94188bd7df20de5 Mon Sep 17 00:00:00 2001 From: Andy Aviles Date: Wed, 19 Jun 2024 11:51:11 -0400 Subject: [PATCH 15/27] removed credentials as it was not expected --- quickstart/101-ai-studio/connections.tf | 7 +------ 1 file changed, 1 insertion(+), 6 deletions(-) diff --git a/quickstart/101-ai-studio/connections.tf b/quickstart/101-ai-studio/connections.tf index 62bb753e..2ab70ee8 100644 --- a/quickstart/101-ai-studio/connections.tf +++ b/quickstart/101-ai-studio/connections.tf @@ -8,17 +8,12 @@ resource "azapi_resource" "AIServicesConnection" { properties = { category = "AIServices", target = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint, - authType = "AAD", // or "APIKey" + authType = "AAD", isSharedToAll = true, metadata = { ApiType = "Azure", ResourceId = azapi_resource.AIServicesResource.id } - - credentials = { - Key = "" // <- must input APIKey here - } - } }) response_export_values = ["*"] From db1dc1b5bb7cb313b68062d07d5d2a2e23a8d94c Mon Sep 17 00:00:00 2001 From: Andy Aviles Date: Fri, 21 Jun 2024 12:29:29 -0400 Subject: [PATCH 16/27] matching contributor guidelines --- quickstart/101-ai-studio/connections.tf | 20 --- quickstart/101-ai-studio/dependent.tf | 66 --------- quickstart/101-ai-studio/hub.tf | 36 ----- quickstart/101-ai-studio/main.tf | 182 ++++++++++++++++++++---- quickstart/101-ai-studio/output.tf | 5 +- quickstart/101-ai-studio/project.tf | 19 --- quickstart/101-ai-studio/providers.tf | 33 +++++ quickstart/101-ai-studio/variables.tf | 23 +-- 8 files changed, 204 insertions(+), 180 deletions(-) delete mode 100644 quickstart/101-ai-studio/connections.tf delete mode 100644 quickstart/101-ai-studio/dependent.tf delete mode 100644 quickstart/101-ai-studio/hub.tf delete mode 100644 quickstart/101-ai-studio/project.tf create mode 100644 quickstart/101-ai-studio/providers.tf diff --git a/quickstart/101-ai-studio/connections.tf b/quickstart/101-ai-studio/connections.tf deleted file mode 100644 index 2ab70ee8..00000000 --- a/quickstart/101-ai-studio/connections.tf +++ /dev/null @@ -1,20 +0,0 @@ -//Create an AI Services connection. -resource "azapi_resource" "AIServicesConnection" { - type = "Microsoft.MachineLearningServices/workspaces/connections@2024-04-01-preview" - name = "Default_AIServices" - parent_id = azapi_resource.hub.id - - body = jsonencode({ - properties = { - category = "AIServices", - target = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint, - authType = "AAD", - isSharedToAll = true, - metadata = { - ApiType = "Azure", - ResourceId = azapi_resource.AIServicesResource.id - } - } - }) - response_export_values = ["*"] -} \ No newline at end of file diff --git a/quickstart/101-ai-studio/dependent.tf b/quickstart/101-ai-studio/dependent.tf deleted file mode 100644 index 9e95287e..00000000 --- a/quickstart/101-ai-studio/dependent.tf +++ /dev/null @@ -1,66 +0,0 @@ - -resource "azurerm_resource_group" "default" { - name = "rg-${var.names}" - location = var.location -} - -resource "azurerm_storage_account" "default" { - name = "${var.names}storage${random_string.suffix.result}" - location = azurerm_resource_group.default.location - resource_group_name = azurerm_resource_group.default.name - account_tier = "Standard" - account_replication_type = "GRS" - allow_nested_items_to_be_public = false -} - -resource "azurerm_key_vault" "default" { - name = "${var.names}keyvault${random_string.suffix.result}" - location = azurerm_resource_group.default.location - resource_group_name = azurerm_resource_group.default.name - tenant_id = data.azurerm_client_config.current.tenant_id - sku_name = "standard" - purge_protection_enabled = false -} - -// AzAPI AIServices -resource "azapi_resource" "AIServicesResource"{ - type = "Microsoft.CognitiveServices/accounts@2023-10-01-preview" - name = "${var.names}AIServicesResource" - location = azurerm_resource_group.default.location - parent_id = azurerm_resource_group.default.id - - identity { - type = "SystemAssigned" - } - - body = jsonencode({ - properties = { - apiProperties = { - statisticsEnabled = false - } - } - kind = "AIServices" - sku = { - name = var.sku - } - }) - - response_export_values = ["*"] -} - -/* The following resources are OPTIONAL. -resource "azurerm_application_insights" "default" { - name = "${var.names}appinsights" - location = azurerm_resource_group.default.location - resource_group_name = azurerm_resource_group.default.name - application_type = "web" -} - -resource "azurerm_container_registry" "default" { - name = "${var.names}contreg" - resource_group_name = azurerm_resource_group.default.name - location = azurerm_resource_group.default.location - sku = "premium" - admin_enabled = true -} -*/ \ No newline at end of file diff --git a/quickstart/101-ai-studio/hub.tf b/quickstart/101-ai-studio/hub.tf deleted file mode 100644 index 565ca7c1..00000000 --- a/quickstart/101-ai-studio/hub.tf +++ /dev/null @@ -1,36 +0,0 @@ -resource "azapi_resource" "hub" { - type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" - name = "my-ai-hub" - location = azurerm_resource_group.default.location - parent_id = azurerm_resource_group.default.id - - identity { - type = "SystemAssigned" - } - - body = jsonencode({ - properties = { - description = "This is my Azure AI hub" - friendlyName = "My Hub" - storageAccount = azurerm_storage_account.default.id - keyVault = azurerm_key_vault.default.id - - /* Optional: To enable these field, the corresponding dependent resources need to be uncommented. - applicationInsight = azurerm_application_insights.default.id - containerRegistry = azurerm_container_registry.default.id - */ - - /*Optional: To enable Customer Managed Keys, the corresponding - encryption = { - status = var.encryption_status - keyVaultProperties = { - keyVaultArmId = azurerm_key_vault.default.id - keyIdentifier = var.cmk_keyvault_key_uri - } - } - */ - - } - kind = "hub" - }) -} \ No newline at end of file diff --git a/quickstart/101-ai-studio/main.tf b/quickstart/101-ai-studio/main.tf index c6ad21da..ca348732 100644 --- a/quickstart/101-ai-studio/main.tf +++ b/quickstart/101-ai-studio/main.tf @@ -1,32 +1,160 @@ -terraform { - required_version = ">= 1.0" - - required_providers { - azurerm = { - source = "hashicorp/azurerm" - version = ">= 3.0, < 4.0" - } - azapi = { - source = "azure/azapi" - } - } +resource "random_pet" "rg_name" { + prefix = var.resource_group_name_prefix } -provider "azurerm" { - features { - key_vault { - recover_soft_deleted_key_vaults = false - purge_soft_delete_on_destroy = false - purge_soft_deleted_keys_on_destroy = false - } - resource_group { - prevent_deletion_if_contains_resources = false - } - } -} - -provider "azapi" { +// RESOURCE GROUP +resource "azurerm_resource_group" "rg" { + location = var.resource_group_location + name = random_pet.rg_name.id } data "azurerm_client_config" "current" { -} \ No newline at end of file +} + +// STORAGE ACCOUNT +resource "azurerm_storage_account" "default" { + name = "${var.prefix}storage${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + account_tier = "Standard" + account_replication_type = "GRS" + allow_nested_items_to_be_public = false +} + +// KEY VAULT +resource "azurerm_key_vault" "default" { + name = "${var.prefix}keyvault${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + tenant_id = data.azurerm_client_config.current.tenant_id + sku_name = "standard" + purge_protection_enabled = false +} + +// AzAPI AIServices +resource "azapi_resource" "AIServicesResource"{ + type = "Microsoft.CognitiveServices/accounts@2023-10-01-preview" + name = "AIServicesResource${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + parent_id = azurerm_resource_group.rg.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + name = "AIServicesResource${random_string.suffix.result}" + properties = { + //restore = true + customSubDomainName = "${random_string.suffix.result}domain" + apiProperties = { + statisticsEnabled = false + } + } + kind = "AIServices" + sku = { + name = var.sku + } + }) + + response_export_values = ["*"] +} + +// Azure AI Hub +resource "azapi_resource" "hub" { + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" + name = "${random_pet.rg_name.id}-aih" + location = azurerm_resource_group.rg.location + parent_id = azurerm_resource_group.rg.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + properties = { + description = "This is my Azure AI hub" + friendlyName = "My Hub" + storageAccount = azurerm_storage_account.default.id + keyVault = azurerm_key_vault.default.id + + /* Optional: To enable these field, the corresponding dependent resources need to be uncommented. + applicationInsight = azurerm_application_insights.default.id + containerRegistry = azurerm_container_registry.default.id + */ + + /*Optional: To enable Customer Managed Keys, the corresponding + encryption = { + status = var.encryption_status + keyVaultProperties = { + keyVaultArmId = azurerm_key_vault.default.id + keyIdentifier = var.cmk_keyvault_key_uri + } + } + */ + + } + kind = "hub" + }) +} + +// Azure AI Project +resource "azapi_resource" "project" { + type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" + name = "my-ai-project${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + parent_id = azurerm_resource_group.rg.id + + identity { + type = "SystemAssigned" + } + + body = jsonencode({ + properties = { + description = "This is my Azure AI PROJECT" + friendlyName = "My Project" + hubResourceId = azapi_resource.hub.id + } + kind = "project" + }) +} + +// AzAPI AI Services Connection +resource "azapi_resource" "AIServicesConnection" { + type = "Microsoft.MachineLearningServices/workspaces/connections@2024-04-01-preview" + name = "Default_AIServices${random_string.suffix.result}" + parent_id = azapi_resource.hub.id + + body = jsonencode({ + properties = { + category = "AIServices", + target = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint, + authType = "AAD", + isSharedToAll = true, + metadata = { + ApiType = "Azure", + ResourceId = azapi_resource.AIServicesResource.id + } + } + }) + response_export_values = ["*"] +} + +/* The following resources are OPTIONAL. +// APPLICATION INSIGHTS +resource "azurerm_application_insights" "default" { + name = "${var.prefix}appinsights${random_string.suffix.result}" + location = azurerm_resource_group.rg.location + resource_group_name = azurerm_resource_group.rg.name + application_type = "web" +} + +// CONTAINER REGISTRY +resource "azurerm_container_registry" "default" { + name = "${var.prefix}contreg${random_string.suffix.result}" + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + sku = "premium" + admin_enabled = true +} +*/ \ No newline at end of file diff --git a/quickstart/101-ai-studio/output.tf b/quickstart/101-ai-studio/output.tf index c24deefa..ae3666a1 100644 --- a/quickstart/101-ai-studio/output.tf +++ b/quickstart/101-ai-studio/output.tf @@ -1,5 +1,5 @@ output "ResourceGroup" { - value = azurerm_resource_group.default.id + value = azurerm_resource_group.rg.id } output "HubId" { @@ -12,5 +12,4 @@ output "ProjectId" { output "endpoint" { value = jsondecode(azapi_resource.AIServicesResource.output).properties.endpoint -} - +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/project.tf b/quickstart/101-ai-studio/project.tf deleted file mode 100644 index 96aee1cc..00000000 --- a/quickstart/101-ai-studio/project.tf +++ /dev/null @@ -1,19 +0,0 @@ -resource "azapi_resource" "project" { - type = "Microsoft.MachineLearningServices/workspaces@2024-04-01-preview" - name = "my-ai-project" - location = azurerm_resource_group.default.location - parent_id = azurerm_resource_group.default.id - - identity { - type = "SystemAssigned" - } - - body = jsonencode({ - properties = { - description = "This is my Azure AI PROJECT" - friendlyName = "My Project" - hubResourceId = azapi_resource.hub.id - } - kind = "project" - }) -} \ No newline at end of file diff --git a/quickstart/101-ai-studio/providers.tf b/quickstart/101-ai-studio/providers.tf new file mode 100644 index 00000000..f802a369 --- /dev/null +++ b/quickstart/101-ai-studio/providers.tf @@ -0,0 +1,33 @@ +terraform { + required_version = ">= 1.0" + + required_providers { + azurerm = { + source = "hashicorp/azurerm" + version = "~>3.0" + } + azapi = { + source = "azure/azapi" + } + random = { + source = "hashicorp/random" + version = "~>3.0" + } + } +} + +provider "azurerm" { + features { + key_vault { + recover_soft_deleted_key_vaults = false + purge_soft_delete_on_destroy = false + purge_soft_deleted_keys_on_destroy = false + } + resource_group { + prevent_deletion_if_contains_resources = false + } + } +} + +provider "azapi" { +} \ No newline at end of file diff --git a/quickstart/101-ai-studio/variables.tf b/quickstart/101-ai-studio/variables.tf index 2a401684..8d6d2484 100644 --- a/quickstart/101-ai-studio/variables.tf +++ b/quickstart/101-ai-studio/variables.tf @@ -1,14 +1,19 @@ -// Names and Try are used for naming conventions in hub.tf and depende -variable "names" { - type = string - description="This variable is used to name the hub, project, and dependent resources." - default = "tftemplate" +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location of the resource group." } -variable "location" { +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 "prefix" { type = string - description = "This is the location for all resources" - default = "East US 2" + description="This variable is used to name the hub, project, and dependent resources." + default = "ai" } variable "sku" { @@ -23,7 +28,7 @@ resource "random_string" "suffix" { upper = false } -/*Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in hub.tf +/*Optional: For Customer Managed Keys, uncomment this part AND the corresponding section in main.tf variable "cmk_keyvault_key_uri" { description = "Key vault uri to access the encryption key." } From c015ce05d36520a7cfa43bcc3e46c979e28507e5 Mon Sep 17 00:00:00 2001 From: Andy Aviles Date: Fri, 21 Jun 2024 13:35:30 -0400 Subject: [PATCH 17/27] renamed outputs.tf --- quickstart/101-ai-studio/{output.tf => outputs.tf} | 0 1 file changed, 0 insertions(+), 0 deletions(-) rename quickstart/101-ai-studio/{output.tf => outputs.tf} (100%) diff --git a/quickstart/101-ai-studio/output.tf b/quickstart/101-ai-studio/outputs.tf similarity index 100% rename from quickstart/101-ai-studio/output.tf rename to quickstart/101-ai-studio/outputs.tf From 6e7acfb6955371b90b3045dbaa8fc64369b01f50 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 13:19:54 -0700 Subject: [PATCH 18/27] Create a Windows-based Azure Kubernetes Service (AKS) cluster --- quickstart/101-aks-cluster-windows/README.md | 18 +++++ quickstart/101-aks-cluster-windows/main.tf | 69 +++++++++++++++++++ quickstart/101-aks-cluster-windows/outputs.tf | 3 + .../101-aks-cluster-windows/providers.tf | 19 +++++ .../101-aks-cluster-windows/variables.tf | 23 +++++++ 5 files changed, 132 insertions(+) create mode 100644 quickstart/101-aks-cluster-windows/README.md create mode 100644 quickstart/101-aks-cluster-windows/main.tf create mode 100644 quickstart/101-aks-cluster-windows/outputs.tf create mode 100644 quickstart/101-aks-cluster-windows/providers.tf create mode 100644 quickstart/101-aks-cluster-windows/variables.tf diff --git a/quickstart/101-aks-cluster-windows/README.md b/quickstart/101-aks-cluster-windows/README.md new file mode 100644 index 00000000..e257e737 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/README.md @@ -0,0 +1,18 @@ +# 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) + +## 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 | + +## Example + diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf new file mode 100644 index 00000000..62b21230 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -0,0 +1,69 @@ +# 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_pet" "azurerm_kubernetes_cluster_node_pool" { + prefix = "pool" +} + +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 = "azureadmin" + admin_password = "Password0123!" + } + + network_profile { + network_plugin = "kubenet" + load_balancer_sku = "standard" + } +} + +resource "azurerm_kubernetes_cluster_node_pool" "win" { + name = random_pet.azurerm_kubernetes_cluster_node_pool.id + kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id + vm_size = "Standard_D4s_v3" + node_count = var.node_count_windows + os_type = "Windows" +} \ No newline at end of file diff --git a/quickstart/101-aks-cluster-windows/outputs.tf b/quickstart/101-aks-cluster-windows/outputs.tf new file mode 100644 index 00000000..62816bd7 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/outputs.tf @@ -0,0 +1,3 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} diff --git a/quickstart/101-aks-cluster-windows/providers.tf b/quickstart/101-aks-cluster-windows/providers.tf new file mode 100644 index 00000000..a0155e16 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/providers.tf @@ -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 { + } +} diff --git a/quickstart/101-aks-cluster-windows/variables.tf b/quickstart/101-aks-cluster-windows/variables.tf new file mode 100644 index 00000000..51cecde0 --- /dev/null +++ b/quickstart/101-aks-cluster-windows/variables.tf @@ -0,0 +1,23 @@ +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 +} \ No newline at end of file From 5182c37a0f1e99ef4000791d72bccc8ebde45170 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 15:57:55 -0700 Subject: [PATCH 19/27] fixes --- quickstart/101-aks-cluster-windows/main.tf | 12 ------------ 1 file changed, 12 deletions(-) diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf index 62b21230..5ba71a46 100644 --- a/quickstart/101-aks-cluster-windows/main.tf +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -16,10 +16,6 @@ resource "random_pet" "azurerm_kubernetes_cluster_dns_prefix" { prefix = "dns" } -resource "random_pet" "azurerm_kubernetes_cluster_node_pool" { - prefix = "pool" -} - resource "azurerm_virtual_network" "vnet" { name = "myvnet" location = azurerm_resource_group.rg.location @@ -59,11 +55,3 @@ resource "azurerm_kubernetes_cluster" "aks" { load_balancer_sku = "standard" } } - -resource "azurerm_kubernetes_cluster_node_pool" "win" { - name = random_pet.azurerm_kubernetes_cluster_node_pool.id - kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id - vm_size = "Standard_D4s_v3" - node_count = var.node_count_windows - os_type = "Windows" -} \ No newline at end of file From da5efce1779d9920d292a55bc1b88c8dcf4e04f4 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 16:48:54 -0700 Subject: [PATCH 20/27] fixes 2 --- quickstart/101-aks-cluster-windows/article | 0 quickstart/101-aks-cluster-windows/main.tf | 14 +++++++++++++- 2 files changed, 13 insertions(+), 1 deletion(-) create mode 100644 quickstart/101-aks-cluster-windows/article diff --git a/quickstart/101-aks-cluster-windows/article b/quickstart/101-aks-cluster-windows/article new file mode 100644 index 00000000..e69de29b diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf index 5ba71a46..7bb953f3 100644 --- a/quickstart/101-aks-cluster-windows/main.tf +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -16,6 +16,10 @@ resource "random_pet" "azurerm_kubernetes_cluster_dns_prefix" { prefix = "dns" } +resource "random_pet" "azurerm_kubernetes_cluster_node_pool" { + prefix = "nodepool" +} + resource "azurerm_virtual_network" "vnet" { name = "myvnet" location = azurerm_resource_group.rg.location @@ -51,7 +55,15 @@ resource "azurerm_kubernetes_cluster" "aks" { } network_profile { - network_plugin = "kubenet" + network_plugin = "azure" load_balancer_sku = "standard" } } + +resource "azurerm_kubernetes_cluster_node_pool" "win" { + name = random_pet.azurerm_kubernetes_cluster_node_pool.id + kubernetes_cluster_id = azurerm_kubernetes_cluster.aks.id + vm_size = "Standard_D4s_v3" + node_count = var.node_count_windows + os_type = "Windows" +} From 1bd62d28a8a1ed5284c19446f8902e989ffdd8c6 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 17:00:31 -0700 Subject: [PATCH 21/27] declared user & pwd as vars --- quickstart/101-aks-cluster-windows/main.tf | 4 ++-- quickstart/101-aks-cluster-windows/variables.tf | 12 ++++++++++++ 2 files changed, 14 insertions(+), 2 deletions(-) diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf index 7bb953f3..46513070 100644 --- a/quickstart/101-aks-cluster-windows/main.tf +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -50,8 +50,8 @@ resource "azurerm_kubernetes_cluster" "aks" { } windows_profile { - admin_username = "azureadmin" - admin_password = "Password0123!" + admin_username = var.admin_username + admin_password = var.admin_password } network_profile { diff --git a/quickstart/101-aks-cluster-windows/variables.tf b/quickstart/101-aks-cluster-windows/variables.tf index 51cecde0..ce823cfb 100644 --- a/quickstart/101-aks-cluster-windows/variables.tf +++ b/quickstart/101-aks-cluster-windows/variables.tf @@ -20,4 +20,16 @@ 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!" } \ No newline at end of file From 068cf2da3fc76f357808a49e6c67e5fcc897a743 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 17:18:04 -0700 Subject: [PATCH 22/27] changed params of terraform init --- quickstart/101-aks-cluster-windows/main.tf | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf index 46513070..b3910bae 100644 --- a/quickstart/101-aks-cluster-windows/main.tf +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -16,8 +16,12 @@ resource "random_pet" "azurerm_kubernetes_cluster_dns_prefix" { prefix = "dns" } -resource "random_pet" "azurerm_kubernetes_cluster_node_pool" { - prefix = "nodepool" +resource "random_string" "azurerm_kubernetes_cluster_node_pool" { + length = 12 + special = false + numeric = false + lower = true + upper = false } resource "azurerm_virtual_network" "vnet" { From bee854b03b46eb329162fa6660209239493ec25a Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 17:19:12 -0700 Subject: [PATCH 23/27] changed params of node pool name --- quickstart/101-aks-cluster-windows/main.tf | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf index b3910bae..c8e1f447 100644 --- a/quickstart/101-aks-cluster-windows/main.tf +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -20,7 +20,7 @@ resource "random_string" "azurerm_kubernetes_cluster_node_pool" { length = 12 special = false numeric = false - lower = true + lower = true upper = false } @@ -65,7 +65,7 @@ resource "azurerm_kubernetes_cluster" "aks" { } resource "azurerm_kubernetes_cluster_node_pool" "win" { - name = random_pet.azurerm_kubernetes_cluster_node_pool.id + 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 From 7c29b17ca6c0afd82587e8a6c27df5f50691afe8 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 19:01:53 -0700 Subject: [PATCH 24/27] fixed node pool name len --- quickstart/101-aks-cluster-windows/main.tf | 4 ++-- quickstart/101-aks-cluster-windows/variables.tf | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/quickstart/101-aks-cluster-windows/main.tf b/quickstart/101-aks-cluster-windows/main.tf index c8e1f447..3795214c 100644 --- a/quickstart/101-aks-cluster-windows/main.tf +++ b/quickstart/101-aks-cluster-windows/main.tf @@ -17,10 +17,10 @@ resource "random_pet" "azurerm_kubernetes_cluster_dns_prefix" { } resource "random_string" "azurerm_kubernetes_cluster_node_pool" { - length = 12 + length = 6 special = false numeric = false - lower = true + lower = true upper = false } diff --git a/quickstart/101-aks-cluster-windows/variables.tf b/quickstart/101-aks-cluster-windows/variables.tf index ce823cfb..2cf992b9 100644 --- a/quickstart/101-aks-cluster-windows/variables.tf +++ b/quickstart/101-aks-cluster-windows/variables.tf @@ -25,11 +25,11 @@ variable "node_count_windows" { variable "admin_username" { type = string description = "The admin username for the Windows node pool." - default = "azureuser" + default = "azureuser" } variable "admin_password" { type = string description = "The admin password for the Windows node pool." - default = "Passw0rd1234Us!" + default = "Passw0rd1234Us!" } \ No newline at end of file From bf2f1f59398a15399eb4ff9e6a8b58de5d66d12c Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Mon, 1 Jul 2024 19:21:33 -0700 Subject: [PATCH 25/27] completed readme --- quickstart/101-aks-cluster-windows/README.md | 9 ++++++++- quickstart/101-aks-cluster-windows/article | 0 quickstart/101-aks-cluster-windows/outputs.tf | 17 +++++++++++++++++ 3 files changed, 25 insertions(+), 1 deletion(-) delete mode 100644 quickstart/101-aks-cluster-windows/article diff --git a/quickstart/101-aks-cluster-windows/README.md b/quickstart/101-aks-cluster-windows/README.md index e257e737..071782ad 100644 --- a/quickstart/101-aks-cluster-windows/README.md +++ b/quickstart/101-aks-cluster-windows/README.md @@ -6,6 +6,10 @@ This template deploys an AKS cluster with Windows nodes. - [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 @@ -13,6 +17,9 @@ This template deploys an AKS cluster with Windows nodes. |-|-|-| | `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 - diff --git a/quickstart/101-aks-cluster-windows/article b/quickstart/101-aks-cluster-windows/article deleted file mode 100644 index e69de29b..00000000 diff --git a/quickstart/101-aks-cluster-windows/outputs.tf b/quickstart/101-aks-cluster-windows/outputs.tf index 62816bd7..7067a430 100644 --- a/quickstart/101-aks-cluster-windows/outputs.tf +++ b/quickstart/101-aks-cluster-windows/outputs.tf @@ -1,3 +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 +} \ No newline at end of file From 0fd2a5d1297aa61e8c08c4ea849428ab5f6c360d Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Fri, 7 Jun 2024 05:41:16 -0700 Subject: [PATCH 26/27] Fixing command to get public key --- quickstart/101-nat-gateway-create/main.tf | 2 +- quickstart/101-nat-gateway-create/ssh.tf | 2 +- quickstart/101-vm-cluster-linux/main.tf | 2 +- quickstart/101-vm-cluster-linux/ssh.tf | 2 +- quickstart/101-vm-with-infrastructure/main.tf | 2 +- quickstart/101-vm-with-infrastructure/ssh.tf | 2 +- quickstart/201-azfw-with-ipgroups/main.tf | 4 ++-- quickstart/201-azfw-with-ipgroups/ssh.tf | 2 +- quickstart/201-k8s-cluster-with-tf-and-aks/main.tf | 2 +- quickstart/201-k8s-cluster-with-tf-and-aks/ssh.tf | 2 +- quickstart/201-private-link-sql-database/main.tf | 2 +- quickstart/201-private-link-sql-database/ssh.tf | 2 +- quickstart/201-vmss-packer-jumpbox/main.tf | 4 ++-- 13 files changed, 15 insertions(+), 15 deletions(-) diff --git a/quickstart/101-nat-gateway-create/main.tf b/quickstart/101-nat-gateway-create/main.tf index fef31a83..440c9e32 100644 --- a/quickstart/101-nat-gateway-create/main.tf +++ b/quickstart/101-nat-gateway-create/main.tf @@ -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 { diff --git a/quickstart/101-nat-gateway-create/ssh.tf b/quickstart/101-nat-gateway-create/ssh.tf index b7a8a2e5..7dbe345a 100644 --- a/quickstart/101-nat-gateway-create/ssh.tf +++ b/quickstart/101-nat-gateway-create/ssh.tf @@ -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 } \ No newline at end of file diff --git a/quickstart/101-vm-cluster-linux/main.tf b/quickstart/101-vm-cluster-linux/main.tf index 06200241..d1a7cc08 100644 --- a/quickstart/101-vm-cluster-linux/main.tf +++ b/quickstart/101-vm-cluster-linux/main.tf @@ -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 { diff --git a/quickstart/101-vm-cluster-linux/ssh.tf b/quickstart/101-vm-cluster-linux/ssh.tf index b7a8a2e5..7dbe345a 100644 --- a/quickstart/101-vm-cluster-linux/ssh.tf +++ b/quickstart/101-vm-cluster-linux/ssh.tf @@ -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 } \ No newline at end of file diff --git a/quickstart/101-vm-with-infrastructure/main.tf b/quickstart/101-vm-with-infrastructure/main.tf index e8c27392..9482a95f 100644 --- a/quickstart/101-vm-with-infrastructure/main.tf +++ b/quickstart/101-vm-with-infrastructure/main.tf @@ -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 { diff --git a/quickstart/101-vm-with-infrastructure/ssh.tf b/quickstart/101-vm-with-infrastructure/ssh.tf index b7a8a2e5..7dbe345a 100644 --- a/quickstart/101-vm-with-infrastructure/ssh.tf +++ b/quickstart/101-vm-with-infrastructure/ssh.tf @@ -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 } \ No newline at end of file diff --git a/quickstart/201-azfw-with-ipgroups/main.tf b/quickstart/201-azfw-with-ipgroups/main.tf index 68d506a0..79da8555 100644 --- a/quickstart/201-azfw-with-ipgroups/main.tf +++ b/quickstart/201-azfw-with-ipgroups/main.tf @@ -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" diff --git a/quickstart/201-azfw-with-ipgroups/ssh.tf b/quickstart/201-azfw-with-ipgroups/ssh.tf index fcdb482b..3ff75ab4 100644 --- a/quickstart/201-azfw-with-ipgroups/ssh.tf +++ b/quickstart/201-azfw-with-ipgroups/ssh.tf @@ -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 } diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf index 014d7b12..4c06f732 100644 --- a/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/main.tf @@ -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 { diff --git a/quickstart/201-k8s-cluster-with-tf-and-aks/ssh.tf b/quickstart/201-k8s-cluster-with-tf-and-aks/ssh.tf index b7a8a2e5..7dbe345a 100644 --- a/quickstart/201-k8s-cluster-with-tf-and-aks/ssh.tf +++ b/quickstart/201-k8s-cluster-with-tf-and-aks/ssh.tf @@ -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 } \ No newline at end of file diff --git a/quickstart/201-private-link-sql-database/main.tf b/quickstart/201-private-link-sql-database/main.tf index eb36986c..7e4ff3d9 100644 --- a/quickstart/201-private-link-sql-database/main.tf +++ b/quickstart/201-private-link-sql-database/main.tf @@ -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 { diff --git a/quickstart/201-private-link-sql-database/ssh.tf b/quickstart/201-private-link-sql-database/ssh.tf index b7a8a2e5..7dbe345a 100644 --- a/quickstart/201-private-link-sql-database/ssh.tf +++ b/quickstart/201-private-link-sql-database/ssh.tf @@ -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 } \ No newline at end of file diff --git a/quickstart/201-vmss-packer-jumpbox/main.tf b/quickstart/201-vmss-packer-jumpbox/main.tf index e5e4dc4f..8525398a 100644 --- a/quickstart/201-vmss-packer-jumpbox/main.tf +++ b/quickstart/201-vmss-packer-jumpbox/main.tf @@ -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 } } From b56dda974ff97389a331a3bf38803a95da27c341 Mon Sep 17 00:00:00 2001 From: hezijie Date: Tue, 2 Jul 2024 12:46:11 +0800 Subject: [PATCH 27/27] fix packer error by monkey patch the version output --- test/e2e/quickstart_test.go | 18 ++++++++++++++++++ test/go.mod | 1 + 2 files changed, 19 insertions(+) diff --git a/test/e2e/quickstart_test.go b/test/e2e/quickstart_test.go index 54ad1237..a6459f7c 100644 --- a/test/e2e/quickstart_test.go +++ b/test/e2e/quickstart_test.go @@ -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, diff --git a/test/go.mod b/test/go.mod index f0d81550..87fec874 100644 --- a/test/go.mod +++ b/test/go.mod @@ -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 )