1
+ resource "azurerm_resource_group" "current" {
2
+ count = var. existing_resource_group_name == " " ? 1 : 0
3
+ provider = azurerm. deployment_subscription
4
+ location = var. location
5
+ name = " ${ module . naming . resource_group . name } -${ var . prefix } firefly${ var . suffix } "
6
+ tags = local. tags
7
+ }
8
+
9
+ resource "azurerm_storage_account" "current" {
10
+ count = var. existing_storage_account_id == " " ? 1 : 0
11
+ provider = azurerm. deployment_subscription
12
+ account_replication_type = " LRS"
13
+ cross_tenant_replication_enabled = false
14
+ account_tier = " Standard"
15
+ location = var. location
16
+ name = " ${ module . naming . storage_account . name } ${ var . prefix != " " ? regex (" \\ w+" , var. prefix ) : " " } firefly${ var . suffix != " " ? regex (" \\ w+" , var. suffix ) : " " } "
17
+ resource_group_name = local. resource_group_name
18
+ tags = local. tags
19
+ dynamic "network_rules" {
20
+ for_each = var. enforce_storage_network_rules ? [1 ] : []
21
+ content {
22
+ default_action = " Deny"
23
+ ip_rules = var. firefly_eips
24
+ }
25
+ }
26
+ }
27
+
28
+ resource "azurerm_eventgrid_system_topic" "current" {
29
+ count = var. existing_eventgrid_topic_name == " " ? 1 : 0
30
+ provider = azurerm. deployment_subscription
31
+ name = " ${ module . naming . eventgrid_topic . name } -${ var . prefix } firefly${ var . suffix } "
32
+ location = var. location
33
+ resource_group_name = local. resource_group_name
34
+ source_arm_resource_id = local. storage_account_id
35
+ topic_type = " microsoft.storage.storageaccounts"
36
+ tags = local. tags
37
+ }
38
+
39
+ resource "azurerm_eventgrid_system_topic_event_subscription" "current" {
40
+ count = var. existing_eventgrid_topic_name == " " ? 1 : 0
41
+ provider = azurerm. deployment_subscription
42
+ name = " ${ module . naming . eventgrid_event_subscription . name } -${ var . prefix } firefly${ var . suffix } "
43
+ resource_group_name = local. resource_group_name
44
+ system_topic = local. eventgrid_system_topic_name
45
+ included_event_types = [" Microsoft.Storage.BlobCreated" ]
46
+
47
+ webhook_endpoint {
48
+ url = var. firefly_webhook_url
49
+ max_events_per_batch = 1
50
+ preferred_batch_size_in_kilobytes = 64
51
+ }
52
+ retry_policy {
53
+ event_time_to_live = 1440
54
+ max_delivery_attempts = 30
55
+ }
56
+ }
57
+
58
+ resource "azurerm_role_definition" "FireflyStorageAccountBlobReader" {
59
+ provider = azurerm. deployment_subscription
60
+
61
+ name = " ${ module . naming . role_definition . name } -${ var . prefix } FireflyStorageAccountBlobReader-${ var . subscription_id } ${ var . suffix } "
62
+ scope = " /subscriptions/${ var . subscription_id } "
63
+ description = " Firefly's requested permissions"
64
+
65
+ permissions {
66
+ data_actions = [
67
+ " Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read"
68
+ ]
69
+ }
70
+ assignable_scopes = [
71
+ " /subscriptions/${ var . subscription_id } "
72
+ ]
73
+ }
74
+
75
+ resource "azurerm_role_assignment" "FireflyStorageAccountBlobReader" {
76
+ provider = azurerm. deployment_subscription
77
+
78
+ principal_id = local. service_principle_object_id
79
+ role_definition_name = azurerm_role_definition. FireflyStorageAccountBlobReader . name
80
+ scope = " /subscriptions/${ var . subscription_id } "
81
+ condition_version = " 2.0"
82
+ condition = <<- EOT
83
+ (
84
+ (
85
+ !(ActionMatches{'Microsoft.Storage/storageAccounts/blobServices/containers/blobs/read'} AND NOT
86
+ SubOperationMatches{'Blob.List'})
87
+ )
88
+ OR
89
+ (
90
+ @Resource[Microsoft.Storage/storageAccounts/blobServices/containers/blobs:path] StringLike '*state'
91
+ )
92
+ OR
93
+ (
94
+ @Resource[Microsoft.Storage/storageAccounts/blobServices/containers/blobs:path] StringLike '*.tfstateenv:*'
95
+ )
96
+ )
97
+ EOT
98
+ }
99
+
100
+ resource "azurerm_monitor_diagnostic_setting" "current" {
101
+ provider = azurerm. deployment_subscription
102
+ name = " ${ module . naming . monitor_diagnostic_setting . name } -${ var . prefix } firefly${ var . subscription_id } ${ var . suffix } "
103
+ target_resource_id = " /subscriptions/${ var . subscription_id } "
104
+ storage_account_id = local. storage_account_id
105
+ enabled_log {
106
+ category = " Administrative"
107
+ }
108
+ depends_on = [local . storage_account_id ]
109
+ }
0 commit comments