Skip to content

Commit 33fb7b9

Browse files
authored
add terraform samples (#115)
This PR syncs terraform azapi examples from https://github.com/Azure/terraform-provider-azapi/tree/main/examples. It's done by a tool: Azure/terraform-provider-azapi#972 cc @stemaMSFT
1 parent f3a6c6a commit 33fb7b9

File tree

779 files changed

+65024
-698
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

779 files changed

+65024
-698
lines changed
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "../../schemas/remarks.schema.json",
3+
"TerraformSamples": [
4+
{
5+
"ResourceType": "Microsoft.AADIAM/diagnosticSettings",
6+
"Path": "samples/diagnosticsettings/main.tf",
7+
"Description": "A basic example of deploying Azure Active Directory Diagnostic Setting for Azure Monitor."
8+
}
9+
]
10+
}
Lines changed: 111 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,111 @@
1+
terraform {
2+
required_providers {
3+
azapi = {
4+
source = "Azure/azapi"
5+
}
6+
}
7+
}
8+
9+
variable "resource_name" {
10+
type = string
11+
default = "acctest0001"
12+
}
13+
14+
variable "location" {
15+
type = string
16+
default = "westus"
17+
}
18+
19+
data "azapi_client_config" "current" {}
20+
21+
resource "azapi_resource" "resourceGroup" {
22+
type = "Microsoft.Resources/resourceGroups@2020-06-01"
23+
name = var.resource_name
24+
location = var.location
25+
}
26+
27+
resource "azapi_resource" "namespace" {
28+
type = "Microsoft.EventHub/namespaces@2024-01-01"
29+
parent_id = azapi_resource.resourceGroup.id
30+
name = "${var.resource_name}-EHN-unique"
31+
location = var.location
32+
body = {
33+
properties = {
34+
disableLocalAuth = false
35+
isAutoInflateEnabled = false
36+
minimumTlsVersion = "1.2"
37+
publicNetworkAccess = "Enabled"
38+
}
39+
sku = {
40+
capacity = 1
41+
name = "Basic"
42+
tier = "Basic"
43+
}
44+
}
45+
}
46+
47+
resource "azapi_resource" "eventhub" {
48+
type = "Microsoft.EventHub/namespaces/eventhubs@2024-01-01"
49+
parent_id = azapi_resource.namespace.id
50+
name = "${var.resource_name}-EH-unique"
51+
body = {
52+
properties = {
53+
messageRetentionInDays = 1
54+
partitionCount = 2
55+
status = "Active"
56+
}
57+
}
58+
}
59+
60+
resource "azapi_resource" "authorizationRule" {
61+
type = "Microsoft.EventHub/namespaces/authorizationRules@2024-01-01"
62+
parent_id = azapi_resource.namespace.id
63+
name = "example"
64+
body = {
65+
properties = {
66+
rights = ["Listen", "Send", "Manage"]
67+
}
68+
}
69+
}
70+
71+
resource "azapi_resource" "diagnosticSetting" {
72+
type = "Microsoft.AADIAM/diagnosticSettings@2017-04-01"
73+
parent_id = "/"
74+
name = "${var.resource_name}-DS-unique"
75+
body = {
76+
properties = {
77+
eventHubAuthorizationRuleId = azapi_resource.authorizationRule.id
78+
eventHubName = azapi_resource.eventhub.name
79+
logs = [
80+
{
81+
category = "RiskyUsers"
82+
enabled = true
83+
},
84+
{
85+
category = "ServicePrincipalSignInLogs"
86+
enabled = true
87+
},
88+
{
89+
category = "SignInLogs"
90+
enabled = true
91+
},
92+
{
93+
category = "B2CRequestLogs"
94+
enabled = true
95+
},
96+
{
97+
category = "UserRiskEvents"
98+
enabled = true
99+
},
100+
{
101+
category = "NonInteractiveUserSignInLogs"
102+
enabled = true
103+
},
104+
{
105+
category = "AuditLogs"
106+
enabled = true
107+
}
108+
]
109+
}
110+
}
111+
}
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
{
2+
"$schema": "../../schemas/remarks.schema.json",
3+
"TerraformSamples": [
4+
{
5+
"ResourceType": "Microsoft.Advisor/recommendations/suppressions",
6+
"Path": "samples/recommendations/suppressions/main.tf",
7+
"Description": "A basic example of deploying Specifies a suppression for an Azure Advisor recommendation."
8+
}
9+
]
10+
}
Lines changed: 35 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
terraform {
2+
required_providers {
3+
azapi = {
4+
source = "Azure/azapi"
5+
}
6+
}
7+
}
8+
9+
variable "resource_name" {
10+
type = string
11+
default = "acctest0001"
12+
}
13+
14+
variable "location" {
15+
type = string
16+
default = "westus"
17+
}
18+
19+
variable "recommendation_id" {
20+
type = string
21+
}
22+
23+
data "azapi_client_config" "current" {}
24+
25+
resource "azapi_resource" "suppression" {
26+
type = "Microsoft.Advisor/recommendations/suppressions@2023-01-01"
27+
parent_id = "${data.azapi_client_config.current.subscription_resource_id}/providers/Microsoft.Advisor/recommendations/${var.recommendation_id}"
28+
name = var.resource_name
29+
body = {
30+
properties = {
31+
suppressionId = ""
32+
ttl = "00:30:00"
33+
}
34+
}
35+
}

settings/remarks/microsoft.alertsmanagement/remarks.json

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,17 @@
22
"$schema": "../../schemas/remarks.schema.json",
33
"ResourceRemarks": [
44
{
5+
"Description": "For guidance on deploying monitoring solutions, see [Create monitoring resources by using Bicep](/azure/azure-resource-manager/bicep/scenarios-monitoring).",
56
"ResourceTypes": [
67
"microsoft.alertsmanagement/smartdetectoralertrules"
7-
],
8-
"Description": "For guidance on deploying monitoring solutions, see [Create monitoring resources by using Bicep](/azure/azure-resource-manager/bicep/scenarios-monitoring)."
8+
]
9+
}
10+
],
11+
"TerraformSamples": [
12+
{
13+
"ResourceType": "microsoft.alertsManagement/smartDetectorAlertRules",
14+
"Path": "samples/smartdetectoralertrules/main.tf",
15+
"Description": "A basic example of deploying Monitor Smart Detector Alert Rule."
916
}
1017
]
11-
}
18+
}
Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,52 @@
1+
terraform {
2+
required_providers {
3+
azapi = {
4+
source = "Azure/azapi"
5+
}
6+
}
7+
}
8+
9+
provider "azapi" {
10+
skip_provider_registration = false
11+
}
12+
13+
variable "resource_name" {
14+
type = string
15+
default = "acctest0001"
16+
}
17+
18+
variable "location" {
19+
type = string
20+
default = "westeurope"
21+
}
22+
23+
resource "azapi_resource" "resourceGroup" {
24+
type = "Microsoft.Resources/resourceGroups@2020-06-01"
25+
name = var.resource_name
26+
location = var.location
27+
}
28+
29+
resource "azapi_resource" "actionRule" {
30+
type = "Microsoft.AlertsManagement/actionRules@2021-08-08"
31+
parent_id = azapi_resource.resourceGroup.id
32+
name = var.resource_name
33+
location = "global"
34+
body = {
35+
properties = {
36+
actions = [
37+
{
38+
actionType = "RemoveAllActionGroups"
39+
},
40+
]
41+
description = ""
42+
enabled = true
43+
scopes = [
44+
azapi_resource.resourceGroup.id,
45+
]
46+
}
47+
48+
}
49+
schema_validation_enabled = false
50+
response_export_values = ["*"]
51+
}
52+
Lines changed: 73 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
terraform {
2+
required_providers {
3+
azapi = {
4+
source = "Azure/azapi"
5+
}
6+
}
7+
}
8+
9+
provider "azapi" {
10+
skip_provider_registration = false
11+
}
12+
13+
variable "resource_name" {
14+
type = string
15+
default = "acctest0001"
16+
}
17+
18+
variable "location" {
19+
type = string
20+
default = "westeurope"
21+
}
22+
23+
resource "azapi_resource" "resourceGroup" {
24+
type = "Microsoft.Resources/resourceGroups@2020-06-01"
25+
name = var.resource_name
26+
location = var.location
27+
}
28+
29+
resource "azapi_resource" "account" {
30+
type = "Microsoft.Monitor/accounts@2023-04-03"
31+
parent_id = azapi_resource.resourceGroup.id
32+
name = var.resource_name
33+
location = var.location
34+
body = {
35+
properties = {
36+
publicNetworkAccess = "Enabled"
37+
}
38+
39+
}
40+
schema_validation_enabled = false
41+
response_export_values = ["*"]
42+
}
43+
44+
resource "azapi_resource" "prometheusRuleGroup" {
45+
type = "Microsoft.AlertsManagement/prometheusRuleGroups@2023-03-01"
46+
parent_id = azapi_resource.resourceGroup.id
47+
name = var.resource_name
48+
location = var.location
49+
body = {
50+
properties = {
51+
clusterName = ""
52+
description = ""
53+
enabled = false
54+
rules = [
55+
{
56+
enabled = false
57+
expression = "histogram_quantile(0.99, sum(rate(jobs_duration_seconds_bucket{service=\"billing-processing\"}[5m])) by (job_type))\n"
58+
labels = {
59+
team = "prod"
60+
}
61+
record = "job_type:billing_jobs_duration_seconds:99p5m"
62+
},
63+
]
64+
scopes = [
65+
azapi_resource.account.id,
66+
]
67+
}
68+
69+
}
70+
schema_validation_enabled = false
71+
response_export_values = ["*"]
72+
}
73+

0 commit comments

Comments
 (0)