forked from MsftArgHacks/Terraform
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.tf
220 lines (208 loc) · 7.3 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
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
//Backend Example.
terraform {
backend "azurerm" {
resource_group_name = "terraform"
storage_account_name = "hackterraform"
container_name = "tfstate"
key = "prod.terraform.tfstate"
}
required_providers {
azurerm = {
version = "~> 2.19"
}
}
}
//Provider example
provider "azurerm" {
features {}
}
//Generation of ramdom String App Service
resource "random_string" "str" {
length = 3
special = false
upper = false
number = false
}
//Declaration of Locals Variables.
locals {
common_tags = {
environment = "${var.prefix}"
project = "${var.project}"
Terraform = "true"
Environment = "dev"
Owner = "test-user"
}
extra_tags = {
network = "HackTest"
extra = "Terraform"
}
}
//RG
module "RGroups" {
source = "./Modules/RGroups"
tupla_rgname_lc = var.tupla_rgname_lc
}
//Log Analytics
module "LogAnalitycs" {
source = "./Modules/LogAnalitycs"
name = var.loganalytics_name
depends_on = [module.RGroups] // Dependencia Explicita.
resource_group_name = join("," , module.RGroups.name[*].RGEU2001.name) // Dependencia implicita
location = join("," , module.RGroups.name[*].RGEU2001.location) // Dependencia implicita
sku = "Free"
//retention_in_days = 7
tags = merge(local.common_tags, local.extra_tags)
solutions = [
{
solution_name = "AzureActivity",
publisher = "Microsoft",
product = "OMSGallery/AzureActivity",
},
]
}
//SQLServer
module "SQLServer" {
source = "./Modules/SQLServer"
depends_on = [module.RGroups, module.LogAnalitycs]
location = join("," , module.RGroups.name[*].RGEU2001.location)
sc_name = "holaychao"
sqlserver_name = var.sqlserver_name == null ? "sqlserver${random_string.str.result}" : var.sqlserver_name
db_name = var.db_name
admin_username = var.admin_username
admin_password = var.admin_password
sql_database_edition = "Standard"
sqldb_service_objective_name = "S1"
resource_group_name = join("," , module.RGroups.name[*].RGEU2001.name)
log_analytics_workspace_id = module.LogAnalitycs.resource_id
log_retention_days = 7
firewall_rules = [
{
name = "access-to-azure"
start_ip_address = "0.0.0.0"
end_ip_address = "0.0.0.0"
},
{
name = "desktop-ip"
start_ip_address = "190.233.207.107"
end_ip_address = "190.233.207.107"
}
]
tags = merge(local.common_tags, local.extra_tags)
}
//AppServices
module "Appservice" {
for_each = var.tupla_rgname_lc
source = "./Modules/AppServices"
depends_on = [module.RGroups, module.SQLServer]
asp_name = "${var.asp_name}${substr(each.value.location, 0, 4)}"
wa_name = "${var.wa_name}${substr(each.value.location, 0, 4)}"
location = each.value.location
resource_group_name = each.value.name
sku = {
tier = "Standard"
size = "S1"
}
site_config = {
dotnet_framework_version = "v4.0"
scm_type = "None"
}
app_settings = {}
connection_string = [{
name = "DefaultConnectionString"
type = "SQLAzure"
value = module.SQLServer.connection_string
}]
app_insights_name = "${random_string.str.result}app_insights"
application_insights_type = "web"
//workspace_id = module.LogAnalitycs.workspace_id
}
//FrontDoor
module "Frontdoor" {
source = "./modules/FrontDoor"
tags = merge(local.common_tags)
frontdoorname = var.frontdoor_name
location = "Global"
resource_group_name = join("," , module.RGroups.name[*].RGEU2001.name) // Dependencia implicita
enforcebpcert = "false"
backendpoolname = "myservers"
acceptedprotocols = ["Http"]
patternstomatch = ["/*"]
frontend_endpoint = {
name = var.frontdoor_name
host_name = "${var.frontdoor_name}.azurefd.net"
}
///////////////////////////
routing_rule = {
rr1 = {
name = var.frontdoor_name
frontend_endpoints = [var.frontdoor_name]
accepted_protocols = ["Http", "Https"]
patterns_to_match = ["/*"]
enabled = true
configuration = "Forwarding"
forwarding_configuration = {
backend_pool_name = "misservers"
cache_enabled = false
cache_use_dynamic_compression = false
cache_query_parameter_strip_directive = "StripNone"
custom_forwarding_path = ""
forwarding_protocol = "MatchRequest"
}
redirect_configuration = {
custom_host = ""
redirect_protocol = "MatchRequest"
redirect_type = "Found"
custom_path = ""
custom_query_string = ""
}
}
}
///////////////////////////
backend_pool_load_balancing = {
lb1 = {
name = "exampleLoadBalancingSettings1"
sample_size = 4
successful_samples_required = 2
additional_latency_milliseconds = 0
}
}
///////////////////////////
backend_pool_health_probe = {
hp1 = {
name = "exampleHealthProbeSetting1"
path = "/"
protocol = "Http"
interval_in_seconds = 120
}
}
////////////////////////////
front-door-object-backend-pool = {
backend_pool = {
bp1 = {
name = "misservers"
backend = {
app1 = {
enabled = true
address = join("," , module.Appservice.*.RGCU001.app_service_default_site_hostname)
host_header = join("," , module.Appservice.*.RGCU001.app_service_default_site_hostname)
http_port = 80
https_port = 443
priority = 1
weight = 50
},
app2 = {
enabled = true
address = join("," , module.Appservice.*.RGEU2001.app_service_default_site_hostname)
host_header = join("," , module.Appservice.*.RGEU2001.app_service_default_site_hostname)
http_port = 80
https_port = 443
priority = 1
weight = 50
}
}
load_balancing_name = "exampleLoadBalancingSettings1"
health_probe_name = "exampleHealthProbeSetting1"
}
}
}
}