From fdd218ca4cde62fd2a05e9bb9e469c1b24e7aece Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 21 Nov 2024 03:06:19 -0800 Subject: [PATCH 1/3] Initial commit --- quickstart/101-azure-automation/README.md | 19 ++++++++++++++++ quickstart/101-azure-automation/main.tf | 23 ++++++++++++++++++++ quickstart/101-azure-automation/outputs.tf | 7 ++++++ quickstart/101-azure-automation/providers.tf | 18 +++++++++++++++ quickstart/101-azure-automation/variables.tf | 17 +++++++++++++++ 5 files changed, 84 insertions(+) create mode 100644 quickstart/101-azure-automation/README.md create mode 100644 quickstart/101-azure-automation/main.tf create mode 100644 quickstart/101-azure-automation/outputs.tf create mode 100644 quickstart/101-azure-automation/providers.tf create mode 100644 quickstart/101-azure-automation/variables.tf diff --git a/quickstart/101-azure-automation/README.md b/quickstart/101-azure-automation/README.md new file mode 100644 index 000000000..931d4348e --- /dev/null +++ b/quickstart/101-azure-automation/README.md @@ -0,0 +1,19 @@ +# Azure Automation Account +This template deploys an Azure Automation Account. + +## 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_automation_account](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/automation_account) + +## 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 | +| `automation_account_name` | Name of the Automation Account resource. The value will be randomly generated if blank. | "" | + +## Example \ No newline at end of file diff --git a/quickstart/101-azure-automation/main.tf b/quickstart/101-azure-automation/main.tf new file mode 100644 index 000000000..978a3f2e0 --- /dev/null +++ b/quickstart/101-azure-automation/main.tf @@ -0,0 +1,23 @@ +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" "azurerm_automation_account_name" { + length = 13 + lower = true + numeric = false + special = false + upper = false +} + +resource "azurerm_automation_account" "example" { + name = coalesce(var.automation_account_name, "autoacc-${random_string.azurerm_automation_account_name.result}") + resource_group_name = azurerm_resource_group.rg.name + location = azurerm_resource_group.rg.location + sku_name = "Basic" +} \ No newline at end of file diff --git a/quickstart/101-azure-automation/outputs.tf b/quickstart/101-azure-automation/outputs.tf new file mode 100644 index 000000000..9434ce8cf --- /dev/null +++ b/quickstart/101-azure-automation/outputs.tf @@ -0,0 +1,7 @@ +output "resource_group_name" { + value = azurerm_resource_group.rg.name +} + +output "automation_account_name" { + value = azurerm_automation_account.example.name +} \ No newline at end of file diff --git a/quickstart/101-azure-automation/providers.tf b/quickstart/101-azure-automation/providers.tf new file mode 100644 index 000000000..058b68717 --- /dev/null +++ b/quickstart/101-azure-automation/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-azure-automation/variables.tf b/quickstart/101-azure-automation/variables.tf new file mode 100644 index 000000000..12e3ced61 --- /dev/null +++ b/quickstart/101-azure-automation/variables.tf @@ -0,0 +1,17 @@ +variable "resource_group_name_prefix" { + type = string + default = "rg" + description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." +} + +variable "resource_group_location" { + type = string + default = "eastus" + description = "Location of the resource group." +} + +variable "automation_account_name" { + type = string + description = "The name of the Automation Account resource. The value will be randomly generated if blank." + default = "" +} \ No newline at end of file From bf53cf1be03388fe164283c5cff05e8b209bfc79 Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 21 Nov 2024 11:24:34 -0800 Subject: [PATCH 2/3] Copied portal quickstart in having account use MSI and use public network access --- quickstart/101-azure-automation/main.tf | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/quickstart/101-azure-automation/main.tf b/quickstart/101-azure-automation/main.tf index 978a3f2e0..f090db161 100644 --- a/quickstart/101-azure-automation/main.tf +++ b/quickstart/101-azure-automation/main.tf @@ -20,4 +20,10 @@ resource "azurerm_automation_account" "example" { resource_group_name = azurerm_resource_group.rg.name location = azurerm_resource_group.rg.location sku_name = "Basic" + identity { + type = "UserAssigned" + identity_ids = [azurerm_user_assigned_identity.example.id] + } + + public_network_access_enabled = true } \ No newline at end of file From 3b452393aded41e557cc2cc9d7d67fbcf5ef01eb Mon Sep 17 00:00:00 2001 From: Tom Archer Date: Thu, 21 Nov 2024 11:53:18 -0800 Subject: [PATCH 3/3] fixed msi --- quickstart/101-azure-automation/main.tf | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/quickstart/101-azure-automation/main.tf b/quickstart/101-azure-automation/main.tf index f090db161..97e2d3890 100644 --- a/quickstart/101-azure-automation/main.tf +++ b/quickstart/101-azure-automation/main.tf @@ -21,9 +21,20 @@ resource "azurerm_automation_account" "example" { location = azurerm_resource_group.rg.location sku_name = "Basic" identity { - type = "UserAssigned" - identity_ids = [azurerm_user_assigned_identity.example.id] + type = "SystemAssigned" } public_network_access_enabled = true +} + +data "azurerm_subscription" "current" {} + +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_automation_account.example.identity[0].principal_id } \ No newline at end of file