-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.tf
120 lines (102 loc) · 3.67 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
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~>2.0"
}
}
}
provider "azurerm" {
features {}
}
# Create resource group
resource "azurerm_resource_group" "dataeng" {
name = "dataeng"
location = "southcentralus"
}
# Create azure postgres sql server
resource "azurerm_postgresql_flexible_server" "bikedata" {
name = "bikedata"
resource_group_name = azurerm_resource_group.dataeng.name
location = azurerm_resource_group.dataeng.location
version = "13"
administrator_login = "china"
administrator_password = "bebe1234!"
zone = "3"
storage_mb = 32768
sku_name = "B_Standard_B1ms"
}
# Create azure firewall rules for postgres sql server
resource "azurerm_postgresql_flexible_server_firewall_rule" "AllowAll" {
name = "AllowAll"
server_id = azurerm_postgresql_flexible_server.bikedata.id
start_ip_address = "0.0.0.0"
end_ip_address = "255.255.255.255"
}
# Create azure storage account
resource "azurerm_storage_account" "bikedatastc" {
name = "bikedatastc"
resource_group_name = azurerm_resource_group.dataeng.name
location = azurerm_resource_group.dataeng.location
account_tier = "Standard"
account_replication_type = "LRS"
account_kind = "StorageV2"
is_hns_enabled = "true"
}
# Create azure datalake gen 2 filesystem
resource "azurerm_storage_data_lake_gen2_filesystem" "bikedatafs" {
name = "bikedatafs"
storage_account_id = azurerm_storage_account.bikedatastc.id
}
# Create azure synapse workspace
resource "azurerm_synapse_workspace" "bikedataspace" {
name = "bikedataspace"
resource_group_name = azurerm_resource_group.dataeng.name
location = azurerm_resource_group.dataeng.location
storage_data_lake_gen2_filesystem_id = azurerm_storage_data_lake_gen2_filesystem.bikedatafs.id
sql_administrator_login = "china"
sql_administrator_login_password = "bebe1234!"
}
# Create azure synapse firewall rule
resource "azurerm_synapse_firewall_rule" "allowAcc" {
name = "allowAcc"
synapse_workspace_id = azurerm_synapse_workspace.bikedataspace.id
start_ip_address = "0.0.0.0"
end_ip_address = "255.255.255.255"
}
# Create dedicated sql pool
resource "azurerm_synapse_sql_pool" "bikedatapool" {
name = "bikedatapool"
synapse_workspace_id = azurerm_synapse_workspace.bikedataspace.id
sku_name = "DW100c"
create_mode = "Default"
}
resource "time_sleep" "wait_for_synapse" {
create_duration = "60s"
depends_on = [azurerm_synapse_firewall_rule.allowAcc]
}
#linked service for blob storage
resource "azurerm_synapse_linked_service" "bloblink" {
name = "bloblink"
synapse_workspace_id = azurerm_synapse_workspace.bikedataspace.id
type = "AzureBlobStorage"
type_properties_json = <<JSON
{
"connectionString": "${azurerm_storage_account.bikedatastc.primary_connection_string}"
}
JSON
depends_on = [time_sleep.wait_for_synapse]
}
#linked service for postgres
resource "azurerm_synapse_linked_service" "postgreslink" {
name = "postgreslink"
synapse_workspace_id = azurerm_synapse_workspace.bikedataspace.id
type = "AzurePostgreSql"
type_properties_json = <<JSON
{
"connectionString": "host=bikedata.postgres.database.azure.com; port=5432; database=postgres; UID=china; password=bebe1234!; EncryptionMethod=1"
}
JSON
depends_on = [
azurerm_synapse_firewall_rule.allowAcc]
}