forked from microsoft/azure-grpc-telemetry-pipeline
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merged PR 2: Terraform script for EventHub
Since ability to manage eventhub namespace firewall and virtual network rules from Terraform is not supported yet (hashicorp/terraform-provider-azurerm#2579) we need to use ARM templates. Another challenge - azurerm_template_deployment fails to pass "array" type parameters properly with error Error: azurerm_template_deployment.eventhub: parameters (subnetIds): '' expected type 'string', got unconvertible type '[]interface {}’ (hashicorp/terraform-provider-azurerm#2579 closed but doesn’t seem resolved) Related work items: #47
- Loading branch information
Anastasia Zolochevska
committed
Apr 17, 2019
1 parent
1ac75e4
commit 3414d20
Showing
5 changed files
with
151 additions
and
1 deletion.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
|
||
resource "azurerm_template_deployment" "eventhub" { | ||
name = "${var.prefix}-eventhub" | ||
resource_group_name = "${azurerm_resource_group.rg.name}" | ||
|
||
template_body = <<DEPLOY | ||
{ | ||
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | ||
"contentVersion": "1.0.0.0", | ||
"parameters": { | ||
"prefix": { | ||
"type": "string", | ||
"defaultValue": "[take(tolower(uniqueString(resourceGroup().id)), 12)]" | ||
}, | ||
"subnetIds": { | ||
"type": "array", | ||
"defaultValue": ${var.subnetIds} | ||
}, | ||
"messageRetentionInDays": { | ||
"type": "string", | ||
"defaultValue": "1" | ||
}, | ||
"partitionCount": { | ||
"type": "string", | ||
"defaultValue": "4" | ||
} | ||
}, | ||
"variables": { | ||
"ehNamespace": "[concat('eh-', parameters('prefix'))]", | ||
"ehName": "telemetry", | ||
"consumerGroups": [ | ||
"databricks" | ||
] | ||
}, | ||
"resources": [ | ||
{ | ||
"apiVersion": "2017-04-01", | ||
"type": "Microsoft.EventHub/namespaces", | ||
"name": "[variables('ehNamespace')]", | ||
"location": "[resourceGroup().location]", | ||
"sku": { | ||
"name": "Standard", | ||
"tier": "Standard" | ||
}, | ||
"properties": { | ||
"kafkaEnabled": true | ||
} | ||
}, | ||
{ | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.EventHub/namespaces', variables('ehNamespace'))]" | ||
], | ||
"apiVersion": "2017-04-01", | ||
"type": "Microsoft.EventHub/namespaces/eventhubs", | ||
"name": "[concat(variables('ehNamespace'), '/', variables('ehName'))]", | ||
"properties": { | ||
"messageRetentionInDays": "[parameters('messageRetentionInDays')]", | ||
"partitionCount": "[parameters('partitionCount')]" | ||
} | ||
}, | ||
{ | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.EventHub/namespaces/eventHubs', variables('ehNamespace'), variables('ehName'))]" | ||
], | ||
"copy": { | ||
"name": "cgCopy", | ||
"count": "[length(variables('consumerGroups'))]" | ||
}, | ||
"apiVersion": "2017-04-01", | ||
"type": "Microsoft.EventHub/namespaces/eventhubs/consumergroups", | ||
"name": "[concat(variables('ehNamespace'), '/', variables('ehName'), '/', variables('consumerGroups')[copyIndex()])]", | ||
"properties": {} | ||
}, | ||
{ | ||
"dependsOn": [ | ||
"[resourceId('Microsoft.EventHub/namespaces', variables('ehNamespace'))]" | ||
], | ||
"copy": { | ||
"name": "networkRuleCopy", | ||
"count": "[length(parameters('subnetIds'))]" | ||
}, | ||
"apiVersion": "2018-01-01-preview", | ||
"type": "Microsoft.EventHub/namespaces/virtualnetworkrules", | ||
"name": "[concat(variables('ehNamespace'), '/vnet-', copyIndex())]", | ||
"properties": { | ||
"virtualNetworkSubnetId": "[parameters('subnetIds')[copyIndex()]]" | ||
} | ||
} | ||
], | ||
"outputs": {} | ||
} | ||
DEPLOY | ||
|
||
# these key-value pairs are passed into the ARM Template's `parameters` block | ||
parameters = { | ||
"prefix" = "${var.prefix}", | ||
"messageRetentionInDays" = "${var.messageRetentionInDays}", | ||
"partitionCount" = "${var.partitionCount}" | ||
} | ||
|
||
deployment_mode = "Incremental" | ||
} |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
provider "azurerm" { | ||
version = "~>1.24" | ||
} | ||
|
||
resource "azurerm_resource_group" "rg" { | ||
name = "${var.resource_group_name}" | ||
location = "${var.location}" | ||
} | ||
|
||
|
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
resource_group_name = "rg" | ||
location = "westus2" | ||
prefix = "foo" | ||
partitionCount = 4 | ||
messageRetentionInDays = 1 | ||
subnetIds = "[\"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RG_NAME>/providers/Microsoft.Network/virtualNetworks/databricks-vnet/subnets/<SUBNET_NAME>\",\"/subscriptions/<SUBSCRIPTION_ID>/resourceGroups/<RG_NAME>/providers/Microsoft.Network/virtualNetworks/databricks-vnet/subnets/<SUBNET_NAME>\"]" |
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
# Common properties | ||
|
||
variable "resource_group_name" { | ||
description = "The name of the resource group." | ||
} | ||
|
||
variable "location" { | ||
description = "The location/region where the resources are created." | ||
} | ||
|
||
variable "prefix" { | ||
description = "The Prefix used for resources." | ||
} | ||
|
||
|
||
# EventHub | ||
|
||
variable "subnetIds" { | ||
description = "IDs of subnets. Event Hub Namespace will only accept connections from these subnets." | ||
type = "string" | ||
} | ||
|
||
variable "partitionCount" { | ||
description = "The number of partitions must be between 2 and 32. The partition count is not changeable." | ||
type = "string" | ||
} | ||
variable "messageRetentionInDays" { | ||
description = "The Event Hubs Standard tier allows message retention period for a maximum of seven days." | ||
type = "string" | ||
} |