-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.tf
71 lines (61 loc) · 2.57 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
provider "azurerm" {
version = "~> 1.19"
}
variable "regions" {
type = "list"
default = ["East US"]
description = "Regions to deploy your resources, can be one or more. Defaults to East US and West US."
}
locals {
tags = {
"managed" = "terraformed"
"owner" = "me@me.me"
"environment" = "learning"
}
}
resource "azurerm_resource_group" "main" {
name = "MyDB-RG-${count.index}"
location = "${element(var.regions, count.index)}"
tags = "${local.tags}"
count = "${length(var.regions)}"
}
resource "azurerm_sql_server" "main" {
name = "mytfqlserver-${count.index}"
resource_group_name = "${element(azurerm_resource_group.main.*.name, count.index)}"
location = "${element(azurerm_resource_group.main.*.location, count.index)}"
version = "12.0"
administrator_login = "4dm1n157r470r"
administrator_login_password = "4-v3ry-53cr37-p455w0rd"
tags = "${local.tags}"
count = "${length(var.regions)}"
}
resource "azurerm_sql_firewall_rule" "main" {
name = "AllowAzureServices"
resource_group_name = "${element(azurerm_resource_group.main.*.name, count.index)}"
server_name = "${element(azurerm_sql_server.main.*.name, count.index)}"
start_ip_address = "0.0.0.0"
end_ip_address = "0.0.0.0"
count = "${length(var.regions)}"
}
resource "azurerm_sql_database" "main" {
name = "mysqldatabase"
resource_group_name = "${azurerm_resource_group.main.*.name[0]}"
location = "${azurerm_resource_group.main.*.location[0]}"
server_name = "${azurerm_sql_server.main.*.name[0]}"
edition = "Standard"
requested_service_objective_name = "S1"
tags = "${local.tags}"
}
resource "azurerm_template_deployment" "failovergroup" {
name = "failover"
resource_group_name = "${azurerm_resource_group.main.*.name[0]}"
template_body = "${file("arm/failover.json")}"
parameters {
"sqlServerPrimaryName" = "${azurerm_sql_server.main.*.name[0]}"
"sqlDatabaseName" = "${azurerm_sql_database.main.name}"
"sqlFailoverGroupName" = "myfailover"
"partnerServers" = "${join(",", slice(azurerm_sql_server.main.*.name, 1, length(var.regions)))}"
"partnerResourceGroups" = "${join(",", slice(azurerm_resource_group.main.*.name, 1, length(var.regions)))}"
}
deployment_mode = "Incremental"
}