Created
November 22, 2021 09:23
-
-
Save alexs77/0b2bd07aae7fbf22bd3c145132475e7d to your computer and use it in GitHub Desktop.
Creating a "Standard (preview) test" in Terraform using azurerm_resource_group_template_deployment
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
data "azurerm_resource_group" "this" { | |
name = "Your Resource Group" | |
} | |
data "azurerm_application_insights" "this" { | |
name = "Application Insights Name" | |
resource_group_name = data.azurerm_resource_group.this.resource_group_name | |
} | |
resource "azurerm_resource_group_template_deployment" "tls_cert_ttl_webtest_yellow" { | |
name = "yellow-cert-ttl-depl" | |
resource_group_name = data.azurerm_application_insights.this.resource_group_name | |
deployment_mode = "Incremental" | |
parameters_content = jsonencode({ | |
"appInsightsName" = { value = data.azurerm_application_insights.this.name } | |
"certRemainingLifetimeCheck" = { value = 30 } | |
"resourceLocation" = { value = data.azurerm_resource_group.this.location }, | |
"testCategory" = { value = "yellow" } | |
"testHostname" = { value = "some.example.domain.com" } | |
"testHostnameSafe" = { value = "some.example.domain.com" } | |
"testHttpCode" = { value = 404 } | |
"testLocations" = { value = "apac-hk-hkn-azr,apac-jp-kaw-edge,apac-sg-sin-azr,emea-au-syd-edge,emea-ch-zrh-edge,emea-fr-pra-edge,emea-gb-db3-azr,emea-nl-ams-azr,emea-ru-msa-edge,emea-se-sto-edge,latam-br-gru-edge,us-ca-sjc-azr,us-fl-mia-edge,us-il-ch1-azr,us-tx-sn1-azr,us-va-ash-azr" } | |
}) | |
template_content = local.tls_cert_ttl_webtest_template_content | |
} | |
locals { | |
tls_cert_ttl_webtest_template_content = <<TEMPLATE | |
{ | |
"$schema": "https://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"appInsightsName": {"type": "String"}, | |
"certRemainingLifetimeCheck": {"type": "Int"}, | |
"resourceLocation": {"type": "String"}, | |
"testCategory": {"type": "String"}, | |
"testHostname": {"type": "String"}, | |
"testHostnameSafe": {"type": "String"}, | |
"testHttpCode": {"type": "String"}, | |
"testLocations": {"type": "String"} | |
}, | |
"variables": { | |
"requestUrl": "[concat('https://',parameters('testHostname'))]", | |
"testLocations": "[split(parameters('testLocations'),',')]", | |
"hiddenLink": "[concat('hidden-link:',resourceId('microsoft.insights/components',parameters('appInsightsName')))]", | |
"copy": [ | |
{ | |
"name": "locations", | |
"count": "[length(variables('testLocations'))]", | |
"input":{ | |
"Id": "[variables('testLocations')[copyIndex('locations')]]" | |
} | |
} | |
] | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Insights/webtests", | |
"apiVersion": "2018-05-01-preview", | |
"name": "[concat(parameters('testHostnameSafe'),'-tls-ttl-', parameters('testCategory'), '-webtest')]", | |
"location":"[parameters('resourceLocation')]", | |
"tags": { | |
"Managed By": "Terraform", | |
"[variables('hiddenLink')]": "Resource" | |
}, | |
"properties": { | |
"SyntheticMonitorId": "[concat(parameters('testHostname'), '_', parameters('testCategory'))]", | |
"Name": "[concat(parameters('testHostname'), '-', parameters('testCategory'))]", | |
"Description": "[concat('Check lifetime of TLS certificate on ', parameters('testHostnameSafe'))]", | |
"Enabled": true, | |
"Frequency": 300, | |
"Timeout": 120, | |
"Kind": "standard", | |
"RetryEnabled": true, | |
"Locations": "[variables('locations')]", | |
"Configuration": null, | |
"Request": { | |
"RequestUrl": "[variables('requestUrl')]", | |
"Headers": null, | |
"HttpVerb": "GET", | |
"RequestBody": null, | |
"ParseDependentRequests": false, | |
"FollowRedirects": null | |
}, | |
"ValidationRules": { | |
"ExpectedHttpStatusCode": "[int(parameters('testHttpCode'))]", | |
"IgnoreHttpsStatusCode": false, | |
"ContentValidation": null, | |
"SSLCheck": true, | |
"SSLCertRemainingLifetimeCheck": "[parameters('certRemainingLifetimeCheck')]" | |
} | |
} | |
} | |
], | |
"outputs": {} | |
} | |
TEMPLATE | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment