Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

101-azure-automation #397

Merged
merged 3 commits into from
Nov 21, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 19 additions & 0 deletions quickstart/101-azure-automation/README.md
Original file line number Diff line number Diff line change
@@ -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
40 changes: 40 additions & 0 deletions quickstart/101-azure-automation/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
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"
identity {
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
}
7 changes: 7 additions & 0 deletions quickstart/101-azure-automation/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
output "resource_group_name" {
value = azurerm_resource_group.rg.name
}

output "automation_account_name" {
value = azurerm_automation_account.example.name
}
18 changes: 18 additions & 0 deletions quickstart/101-azure-automation/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
terraform {
required_version = ">=1.0"

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

provider "azurerm" {
features {}
}
17 changes: 17 additions & 0 deletions quickstart/101-azure-automation/variables.tf
Original file line number Diff line number Diff line change
@@ -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 = ""
}
Loading