Examples for documentation for AzAPI provider including resource and update_resource

This commit is contained in:
Mark Gray 2022-04-11 15:09:07 -07:00
parent 64aa77f9f8
commit 3fcccfc376
6 changed files with 151 additions and 0 deletions

View File

@ -0,0 +1,28 @@
# AzAPI update resource is used to enable Network Rule sets on Event Hub namespace
resource "azapi_update_resource" "qs101" {
type = "Microsoft.EventHub/namespaces/networkRuleSets@2021-11-01"
name = "default"
parent_id = azurerm_eventhub_namespace.qs101.id
body = jsonencode({
properties = {
defaultAction = "Deny"
publicNetworkAccess = "Enabled"
virtualNetworkRules = [
{
ignoreMissingVnetServiceEndpoint = false
subnet = {
# API bug, returned id replaced `resourceGroups` with `resourcegroups`
id = replace(azurerm_subnet.qs101.id, "resourceGroups", "resourcegroups")
}
}
]
ipRules = [
{
action = "Allow"
ipMask = "1.1.1.1"
}
]
}
})
}

View File

@ -0,0 +1,34 @@
resource "azurerm_resource_group" "qs101" {
name = "rg-qs101-eh-rules"
location = "westus2"
}
resource "azurerm_virtual_network" "qs101" {
name = "myvnet"
location = azurerm_resource_group.qs101.location
resource_group_name = azurerm_resource_group.qs101.name
address_space = ["172.17.0.0/16"]
dns_servers = ["10.0.0.4", "10.0.0.5"]
}
resource "azurerm_subnet" "qs101" {
name = "default"
resource_group_name = azurerm_resource_group.qs101.name
virtual_network_name = azurerm_virtual_network.qs101.name
address_prefixes = ["172.17.0.0/24"]
service_endpoints = ["Microsoft.EventHub"]
}
resource "random_pet" "qs101_namespace" {
length = 3
separator = ""
}
resource "azurerm_eventhub_namespace" "qs101" {
name = random_pet.qs101_namespace.id
location = azurerm_resource_group.qs101.location
resource_group_name = azurerm_resource_group.qs101.name
sku = "Standard"
capacity = 2
}

View File

@ -0,0 +1,28 @@
terraform {
required_providers {
azapi = {
source = "azure/azapi"
version = "=0.1.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.2"
}
random = {
source = "hashicorp/random"
version = "=3.1.2"
}
}
}
provider "azapi" {
}
provider "azurerm" {
features {}
}
provider "random" {
}

View File

@ -0,0 +1,25 @@
# Provision a Lab Service Account and a Lab that are in public preview
resource "azapi_resource" "qs101-account" {
type = "Microsoft.LabServices/labaccounts@2018-10-15"
name = "qs101LabAccount"
parent_id = azurerm_resource_group.qs101.id
body = jsonencode({
properties = {
enabledRegionSelection = false
}
})
}
resource "azapi_resource" "qs101-lab" {
type = "Microsoft.LabServices/labaccounts/labs@2018-10-15"
name = "qs101Lab"
parent_id = azapi_resource.qs101-account.id
body = jsonencode({
properties = {
maxUsersInLab = 10
userAccessMode = "Restricted"
}
})
}

View File

@ -0,0 +1,13 @@
resource "azurerm_resource_group" "qs101" {
name = "rg-qs101"
location = "westus2"
depends_on = [
azurerm_resource_provider_registration.qs101
]
}
#
resource "azurerm_resource_provider_registration" "qs101" {
name = "Microsoft.LabServices"
}

View File

@ -0,0 +1,23 @@
terraform {
required_providers {
azapi = {
source = "azure/azapi"
version = "=0.1.0"
}
azurerm = {
source = "hashicorp/azurerm"
version = "=3.0.2"
}
}
}
provider "azapi" {
default_location = "eastus"
default_tags = {
team = "Azure deployments"
}
}
provider "azurerm" {
features {}
}