-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathmain.tf
133 lines (121 loc) · 5.45 KB
/
main.tf
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
# Create a resource group for below resources
resource "azurerm_resource_group" "rgsa" {
name = "stream-analytics-rg"
location = var.location
}
# Create an Azure Event Hub Namespace and corresponding Event Hub for data input into Azure Stream Analytics
resource "azurerm_eventhub_namespace" "ehnamespace" {
name = "input-event-hub-namespace"
location = var.location
resource_group_name = azurerm_resource_group.rgsa.name
sku = "Standard"
}
resource "azurerm_eventhub" "eh" {
name = "input-event-hub"
namespace_name = azurerm_eventhub_namespace.ehnamespace.name
resource_group_name = azurerm_resource_group.rgsa.name
partition_count = 2
message_retention = 1
}
resource "azurerm_eventhub_consumer_group" "ehconsumergroup" {
name = "input-event-hub-consumer-group"
namespace_name = azurerm_eventhub_namespace.ehnamespace.name
eventhub_name = azurerm_eventhub.eh.name
resource_group_name = azurerm_resource_group.rgsa.name
}
resource "azurerm_eventhub_authorization_rule" "ehsend" {
name = "input-event-hub-authorization"
namespace_name = azurerm_eventhub_namespace.ehnamespace.name
eventhub_name = azurerm_eventhub.eh.name
resource_group_name = azurerm_resource_group.rgsa.name
listen = false
send = true
}
# Generate a random password
resource "random_password" "dbpassword" {
length = 17
special = true
min_special = 1
min_numeric = 1
min_upper = 1
min_lower = 1
override_special = "$%&-_+{}<>"
}
# Create an Azure SQL Database to store reference data
resource "azurerm_sql_server" "sqlserver" {
name = "sqlserver-refdata-event-hub"
resource_group_name = azurerm_resource_group.rgsa.name
location = var.location
version = "12.0"
administrator_login = var.administrator_login
administrator_login_password = random_password.dbpassword.result
}
resource "azurerm_sql_database" "sqldb" {
name = "sqldb-refdata-eventhub"
resource_group_name = azurerm_resource_group.rgsa.name
location = var.location
server_name = azurerm_sql_server.sqlserver.name
}
# Create an Azure Service Bus Namespace and Topic for data output
resource "azurerm_servicebus_namespace" "sb" {
name = "servicebus-output"
location = var.location
resource_group_name = azurerm_resource_group.rgsa.name
sku = "Standard"
}
resource "azurerm_servicebus_topic" "sbtopic" {
name = "sb-output-topic"
resource_group_name = azurerm_resource_group.rgsa.name
namespace_name = azurerm_servicebus_namespace.sb.name
}
resource "azurerm_servicebus_topic_authorization_rule" "sbtopicauthrulewrite" {
name = "sb-output-topic-auth-rule-write"
namespace_name = azurerm_servicebus_namespace.sb.name
topic_name = azurerm_servicebus_topic.sbtopic.name
resource_group_name = azurerm_resource_group.rgsa.name
listen = false
send = true
manage = false
}
# Create an Azure blob storage account for Azure Stream Analytics
resource "azurerm_storage_account" "ehstor" {
name = "ehstorage1"
resource_group_name = azurerm_resource_group.rgsa.name
location = var.location
account_tier = "Standard"
account_replication_type = "GRS"
}
# Define ARM deployment template for the Azure Stream Analytics deployment
resource "azurerm_resource_group_template_deployment" "azure_stream_analytics" {
name = "azure_stream_analytics"
resource_group_name = azurerm_resource_group.rgsa.name
deployment_mode = "Incremental"
parameters_content = jsonencode({
"parameterBlock" : {
"value" : {
"asa_query" : file("${path.module}/stream-analytics/asaquery.asaql")
"name" : "azure_stream_analytics"
"location" : var.location
"server" : azurerm_sql_server.sqlserver.name
"database" : azurerm_sql_database.sqldb.name
"user" : var.administrator_login
"password" : random_password.dbpassword.result
"referenceQuery" : file("${path.module}/stream-analytics/referencequery.snapshot.sql")
"refreshRate" : "00:05:00"
"streamingUnits" : 1
"eh_consumer_group_name" : azurerm_eventhub_consumer_group.ehconsumergroup.name
"eh_name" : azurerm_eventhub.eh.name
"eh_namespace" : azurerm_eventhub_namespace.ehnamespace.name
"eh_sharedAccessPolicyName" : azurerm_eventhub_authorization_rule.ehsend.name
"eh_sharedAccessPolicyKey" : azurerm_eventhub_authorization_rule.ehsend.primary_key
"sb_namespace" : azurerm_servicebus_namespace.sb.name
"sb_sharedAccessPolicyName" : azurerm_servicebus_topic_authorization_rule.sbtopicauthrulewrite.name
"sb_sharedAccessPolicyKey" : azurerm_servicebus_topic_authorization_rule.sbtopicauthrulewrite.primary_key
"sb_topic_name" : azurerm_servicebus_topic.sbtopic.name
"sa_accountName" : azurerm_storage_account.ehstor.name
"sa_accountKey" : azurerm_storage_account.ehstor.primary_access_key
}
}
})
template_content = file("${path.module}/stream-analytics/asa-template.json")
}