Skip to content

Commit 9784b3a

Browse files
authored
Merge pull request microsoft#90 from Azure/azapi-examples
Examples for documentation
2 parents c644dcd + 3fcccfc commit 9784b3a

6 files changed

Lines changed: 151 additions & 0 deletions

File tree

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
# AzAPI update resource is used to enable Network Rule sets on Event Hub namespace
2+
resource "azapi_update_resource" "qs101" {
3+
type = "Microsoft.EventHub/namespaces/networkRuleSets@2021-11-01"
4+
name = "default"
5+
parent_id = azurerm_eventhub_namespace.qs101.id
6+
7+
body = jsonencode({
8+
properties = {
9+
defaultAction = "Deny"
10+
publicNetworkAccess = "Enabled"
11+
virtualNetworkRules = [
12+
{
13+
ignoreMissingVnetServiceEndpoint = false
14+
subnet = {
15+
# API bug, returned id replaced `resourceGroups` with `resourcegroups`
16+
id = replace(azurerm_subnet.qs101.id, "resourceGroups", "resourcegroups")
17+
}
18+
}
19+
]
20+
ipRules = [
21+
{
22+
action = "Allow"
23+
ipMask = "1.1.1.1"
24+
}
25+
]
26+
}
27+
})
28+
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
resource "azurerm_resource_group" "qs101" {
2+
name = "rg-qs101-eh-rules"
3+
location = "westus2"
4+
}
5+
6+
resource "azurerm_virtual_network" "qs101" {
7+
name = "myvnet"
8+
location = azurerm_resource_group.qs101.location
9+
resource_group_name = azurerm_resource_group.qs101.name
10+
address_space = ["172.17.0.0/16"]
11+
dns_servers = ["10.0.0.4", "10.0.0.5"]
12+
}
13+
14+
resource "azurerm_subnet" "qs101" {
15+
name = "default"
16+
resource_group_name = azurerm_resource_group.qs101.name
17+
virtual_network_name = azurerm_virtual_network.qs101.name
18+
address_prefixes = ["172.17.0.0/24"]
19+
20+
service_endpoints = ["Microsoft.EventHub"]
21+
}
22+
23+
resource "random_pet" "qs101_namespace" {
24+
length = 3
25+
separator = ""
26+
}
27+
28+
resource "azurerm_eventhub_namespace" "qs101" {
29+
name = random_pet.qs101_namespace.id
30+
location = azurerm_resource_group.qs101.location
31+
resource_group_name = azurerm_resource_group.qs101.name
32+
sku = "Standard"
33+
capacity = 2
34+
}
Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
terraform {
2+
required_providers {
3+
azapi = {
4+
source = "azure/azapi"
5+
version = "=0.1.0"
6+
}
7+
8+
azurerm = {
9+
source = "hashicorp/azurerm"
10+
version = "=3.0.2"
11+
}
12+
13+
random = {
14+
source = "hashicorp/random"
15+
version = "=3.1.2"
16+
}
17+
}
18+
}
19+
20+
provider "azapi" {
21+
}
22+
23+
provider "azurerm" {
24+
features {}
25+
}
26+
27+
provider "random" {
28+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
# Provision a Lab Service Account and a Lab that are in public preview
2+
resource "azapi_resource" "qs101-account" {
3+
type = "Microsoft.LabServices/labaccounts@2018-10-15"
4+
name = "qs101LabAccount"
5+
parent_id = azurerm_resource_group.qs101.id
6+
7+
body = jsonencode({
8+
properties = {
9+
enabledRegionSelection = false
10+
}
11+
})
12+
}
13+
14+
resource "azapi_resource" "qs101-lab" {
15+
type = "Microsoft.LabServices/labaccounts/labs@2018-10-15"
16+
name = "qs101Lab"
17+
parent_id = azapi_resource.qs101-account.id
18+
19+
body = jsonencode({
20+
properties = {
21+
maxUsersInLab = 10
22+
userAccessMode = "Restricted"
23+
}
24+
})
25+
}
Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
resource "azurerm_resource_group" "qs101" {
2+
name = "rg-qs101"
3+
location = "westus2"
4+
5+
depends_on = [
6+
azurerm_resource_provider_registration.qs101
7+
]
8+
}
9+
10+
#
11+
resource "azurerm_resource_provider_registration" "qs101" {
12+
name = "Microsoft.LabServices"
13+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
terraform {
2+
required_providers {
3+
azapi = {
4+
source = "azure/azapi"
5+
version = "=0.1.0"
6+
}
7+
azurerm = {
8+
source = "hashicorp/azurerm"
9+
version = "=3.0.2"
10+
}
11+
}
12+
}
13+
14+
provider "azapi" {
15+
default_location = "eastus"
16+
default_tags = {
17+
team = "Azure deployments"
18+
}
19+
}
20+
21+
provider "azurerm" {
22+
features {}
23+
}

0 commit comments

Comments
 (0)