-
Notifications
You must be signed in to change notification settings - Fork 26
/
main.tf
313 lines (284 loc) · 7.36 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
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
resource "random_id" "rg_name" {
byte_length = 8
}
resource "random_id" "env_name" {
byte_length = 8
}
resource "random_id" "keyvault_name" {
byte_length = 8
}
resource "random_id" "sa_name" {
byte_length = 4
}
resource "random_id" "container_name" {
byte_length = 4
}
resource "azurerm_resource_group" "rg" {
location = var.location
name = "rg-${random_id.rg_name.hex}"
}
data "azurerm_client_config" "current" {}
data "curl" "public_ip" {
http_method = "GET"
uri = "https://api.ipify.org?format=json"
}
locals {
public_ip = jsondecode(data.curl.public_ip.response).ip
}
resource "azurerm_key_vault" "test" {
location = azurerm_resource_group.rg.location
name = "testkv${random_id.keyvault_name.hex}"
resource_group_name = azurerm_resource_group.rg.name
sku_name = "premium"
tenant_id = data.azurerm_client_config.current.tenant_id
purge_protection_enabled = true
network_acls {
bypass = "AzureServices"
default_action = "Deny"
ip_rules = [local.public_ip, "0.0.0.0/0"]
}
depends_on = [azurerm_storage_container.test]
}
resource "azurerm_key_vault_key" "test" {
key_opts = [
"decrypt",
"encrypt",
"sign",
"unwrapKey",
"verify",
"wrapKey"
]
key_type = "RSA-HSM"
key_vault_id = azurerm_key_vault.test.id
name = "testkey"
expiration_date = timeadd("${formatdate("YYYY-MM-DD", timestamp())}T00:00:00Z", "168h")
key_size = 2048
depends_on = [azurerm_key_vault_access_policy.client]
lifecycle {
ignore_changes = [expiration_date]
}
}
resource "azurerm_log_analytics_workspace" "test" {
location = azurerm_resource_group.rg.location
name = "testlaworkspace"
resource_group_name = azurerm_resource_group.rg.name
retention_in_days = 30
sku = "PerGB2018"
}
resource "azurerm_key_vault_access_policy" "storage" {
key_vault_id = azurerm_key_vault.test.id
object_id = azurerm_storage_account.test.identity[0].principal_id
tenant_id = azurerm_storage_account.test.identity[0].tenant_id
key_permissions = [
"Get",
"Create",
"List",
"Restore",
"Recover",
"UnwrapKey",
"WrapKey",
"Purge",
"Encrypt",
"Decrypt",
"Sign",
"Verify",
"GetRotationPolicy",
"SetRotationPolicy"
]
secret_permissions = [
"Backup",
"Delete",
"Get",
"List",
"Purge",
"Recover",
"Restore",
"Set"
]
storage_permissions = [
"Get",
"List",
"Set",
"Update",
"RegenerateKey",
"Recover",
"Purge"
]
}
resource "azurerm_key_vault_access_policy" "client" {
key_vault_id = azurerm_key_vault.test.id
object_id = coalesce(var.managed_identity_principal_id, data.azurerm_client_config.current.object_id)
tenant_id = data.azurerm_client_config.current.tenant_id
key_permissions = [
"Get",
"Create",
"Delete",
"List",
"Restore",
"Recover",
"UnwrapKey",
"WrapKey",
"Purge",
"Encrypt",
"Decrypt",
"Sign",
"Verify",
"GetRotationPolicy",
"SetRotationPolicy"
]
secret_permissions = [
"Backup",
"Delete",
"Get",
"List",
"Purge",
"Recover",
"Restore",
"Set"
]
storage_permissions = [
"Get",
"List",
"Set",
"Update",
"RegenerateKey",
"Recover",
"Purge"
]
}
resource "azurerm_storage_account" "test" {
account_replication_type = "RAGRS"
account_tier = "Standard"
location = azurerm_resource_group.rg.location
name = "testsa${random_id.sa_name.hex}"
resource_group_name = azurerm_resource_group.rg.name
min_tls_version = "TLS1_2"
identity {
type = "SystemAssigned"
}
network_rules {
default_action = "Deny"
bypass = ["AzureServices"]
ip_rules = ["0.0.0.0/0"]
}
queue_properties {
logging {
delete = true
read = true
version = "1.0"
write = true
}
}
lifecycle {
ignore_changes = [customer_managed_key]
}
}
resource "azurerm_log_analytics_storage_insights" "test" {
name = "teststorageinsights"
resource_group_name = azurerm_resource_group.rg.name
storage_account_id = azurerm_storage_account.test.id
storage_account_key = azurerm_storage_account.test.primary_access_key
workspace_id = azurerm_log_analytics_workspace.test.id
blob_container_names = ["blobExample"]
}
resource "azurerm_storage_account_customer_managed_key" "managedkey" {
key_name = azurerm_key_vault_key.test.name
storage_account_id = azurerm_storage_account.test.id
key_vault_id = azurerm_key_vault.test.id
key_version = azurerm_key_vault_key.test.version
depends_on = [azurerm_key_vault_access_policy.storage]
}
resource "azurerm_storage_container" "test" {
#checkov:skip=CKV2_AZURE_21:lll
name = "testcontainer"
storage_account_name = azurerm_storage_account.test.name
container_access_type = "private"
}
resource "azurerm_user_assigned_identity" "test" {
location = azurerm_resource_group.rg.location
name = "testidentity"
resource_group_name = azurerm_resource_group.rg.name
}
module "containerapps" {
source = "../.."
resource_group_name = azurerm_resource_group.rg.name
location = azurerm_resource_group.rg.location
container_app_environment_name = "example-env-${random_id.env_name.hex}"
container_app_environment_tags = {
environment = "test"
}
log_analytics_workspace_name = "testlaworkspace"
dapr_component = {
statestore = {
name = "statestore-${random_id.container_name.hex}"
component_type = "state.azure.blobstorage"
version = "v1"
scopes = ["nodeapp"]
metadata = [
{
name = "accountName"
value = azurerm_storage_account.test.name
},
{
name = "containerName"
value = azurerm_storage_container.test.name
},
{
name = "azureClientId"
value = azurerm_user_assigned_identity.test.client_id
}
]
}
}
container_apps = {
pythonapp = {
name = "pythonapp-${random_id.container_name.hex}"
revision_mode = "Single"
template = {
containers = [
{
name = "pythonapp"
cpu = 0.25
image = "dapriosamples/hello-k8s-python:latest"
memory = "0.5Gi"
}
]
}
dapr = {
app_id = "pythonapp"
app_port = 0
}
tags = {
"environment" = "dev"
}
},
nodeapp = {
name = "nodeapp-${random_id.container_name.hex}"
revision_mode = "Single"
template = {
containers = [
{
name = "nodeapp"
cpu = 0.25
image = "dapriosamples/hello-k8s-node:latest"
memory = "0.5Gi"
env = [
{
name = "APP_PORT"
value = "3000"
}
]
}
]
}
dapr = {
app_id = "nodeapp"
app_port = 3000
}
identity = {
type = "UserAssigned"
identity_ids = [azurerm_user_assigned_identity.test.id]
}
}
}
}