Created
December 4, 2018 20:43
-
-
Save timmyreilly/6839d0e6014167ecf68f720cb0f7794f to your computer and use it in GitHub Desktop.
Terraform Main.tf for Azure Event Grid Subscription from Azure Storage to EventHub.
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
resource "azurerm_resource_group" "test" { | |
name = "tempresourceGroup1" | |
location = "West US" | |
} | |
resource "azurerm_eventhub_namespace" "test" { | |
name = "demo-EventHubNamespace" | |
location = "${azurerm_resource_group.test.location}" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
sku = "Standard" | |
capacity = 1 | |
tags { | |
environment = "Development" | |
} | |
} | |
resource "azurerm_eventhub" "test" { | |
name = "demo-EventHub" | |
namespace_name = "${azurerm_eventhub_namespace.test.name}" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
partition_count = 2 | |
message_retention = 1 | |
} | |
resource "azurerm_storage_account" "test" { | |
location = "${azurerm_resource_group.test.location}" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
name = "payattentiontome" | |
account_replication_type = "lrs" | |
account_tier = "standard" | |
account_kind = "StorageV2" | |
} | |
### This doesn't get us far enough. This will create the resource, but there's currenlty no way to add the subscription. | |
# See this issue: https://github.com/terraform-providers/terraform-provider-azurerm/issues/1794 | |
# resource "azurerm_eventgrid_topic" "test" { | |
# name = "my-eventgrid-topic" | |
# location = "${azurerm_resource_group.test.location}" | |
# resource_group_name = "${azurerm_resource_group.test.name}" | |
# tags { | |
# environment = "Production" | |
# } | |
# } | |
### Instead we use an azure_template_deployment to fill the gap: | |
resource "azurerm_template_deployment" "test" { | |
name = "acctesttemplate-01" | |
resource_group_name = "${azurerm_resource_group.test.name}" | |
depends_on = ["azurerm_storage_account.test"] | |
template_body = <<DEPLOY | |
{ | |
"$schema": "http://schema.management.azure.com/schemas/2015-01-01/deploymentTemplate.json#", | |
"contentVersion": "1.0.0.0", | |
"parameters": { | |
"storageName": { | |
"type": "string", | |
"metadata": { | |
"description": "Provide a unique name for the Blob Storage account." | |
} | |
}, | |
"eventSubName": { | |
"type": "string", | |
"defaultValue": "subscribeToStorage", | |
"metadata": { | |
"description": "Provide a name for the Event Grid subscription." | |
} | |
}, | |
"endpoint": { | |
"type": "string", | |
"metadata": { | |
"description": "Provide the resource id for the EventHub to receive events." | |
} | |
} | |
}, | |
"resources": [ | |
{ | |
"type": "Microsoft.Storage/storageAccounts/providers/eventSubscriptions", | |
"name": "[concat(parameters('storageName'), '/Microsoft.EventGrid/', parameters('eventSubName'))]", | |
"apiVersion": "2018-01-01", | |
"properties": { | |
"destination": { | |
"endpointType": "EventHub", | |
"properties": { | |
"resourceId": "[parameters('endpoint')]" | |
} | |
}, | |
"filter": { | |
"subjectBeginsWith": "", | |
"subjectEndsWith": "", | |
"isSubjectCaseSensitive": false, | |
"includedEventTypes": [ | |
"All" | |
] | |
} | |
} | |
} | |
] | |
} | |
DEPLOY | |
# these key-value pairs are passed into the ARM Template's `parameters` block | |
parameters { | |
# "storageAccountType" = "Standard" | |
"endpoint" = "${azurerm_eventhub.test.id}" | |
"storageName" = "${azurerm_storage_account.test.name}" | |
} | |
deployment_mode = "Incremental" | |
} | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment