11resource "azurerm_resource_group" "e2e_appcs" {
2- name = provider::pagopa- dx::resource_name (merge (local. naming_config , {
2+ name = provider::dx::resource_name (merge (local. naming_config , {
33 domain = " e2e"
44 name = " appcs" ,
55 resource_type = " resource_group"
@@ -8,3 +8,217 @@ resource "azurerm_resource_group" "e2e_appcs" {
88
99 tags = local. tags
1010}
11+
12+ resource "azurerm_container_group" "public_app" {
13+ name = provider::dx::resource_name (
14+ merge (local. naming_config , { name = " appcs-public" , resource_type = " container_instance" })
15+ )
16+ location = local. environment . location
17+ resource_group_name = azurerm_resource_group. e2e_appcs . name
18+
19+ identity { type = " SystemAssigned" }
20+
21+ os_type = " Linux"
22+
23+ container {
24+ name = " network-access"
25+ image = local. docker_image
26+ cpu = " 0.5"
27+ memory = " 1.5"
28+ ports {
29+ port = 8080
30+ }
31+ }
32+
33+ diagnostics {
34+ log_analytics {
35+ workspace_id = data. azurerm_log_analytics_workspace . e2e . workspace_id
36+ workspace_key = data. azurerm_log_analytics_workspace . e2e . primary_shared_key
37+ }
38+ }
39+
40+ tags = local. tags
41+ }
42+
43+ resource "dx_available_subnet_cidr" "private_app" {
44+ virtual_network_id = data. azurerm_virtual_network . e2e . id
45+ prefix_length = 26
46+ }
47+
48+ resource "azurerm_subnet" "private_app" {
49+ name = provider::dx::resource_name (merge (local. naming_config , {
50+ name = " appcs-private" ,
51+ resource_type = " container_instance_subnet"
52+ }))
53+ resource_group_name = local. e2e_virtual_network . resource_group_name
54+ virtual_network_name = local. e2e_virtual_network . name
55+ address_prefixes = [dx_available_subnet_cidr . private_app . cidr_block ]
56+
57+ delegation {
58+ name = " Microsoft.ContainerInstance/containerGroups"
59+
60+ service_delegation {
61+ name = " Microsoft.ContainerInstance/containerGroups"
62+ actions = [
63+ " Microsoft.Network/virtualNetworks/subnets/action" ,
64+ ]
65+ }
66+ }
67+ }
68+
69+ resource "azurerm_container_group" "private_app" {
70+ name = provider::dx::resource_name (
71+ merge (local. naming_config , { name = " appcs-private" , resource_type = " container_instance" })
72+ )
73+ location = local. environment . location
74+ resource_group_name = azurerm_resource_group. e2e_appcs . name
75+
76+ identity { type = " SystemAssigned" }
77+
78+ os_type = " Linux"
79+
80+ container {
81+ name = " network-access"
82+ image = local. docker_image
83+ cpu = " 0.5"
84+ memory = " 1.5"
85+ ports {
86+ port = 8080
87+ }
88+ }
89+
90+ ip_address_type = " Private"
91+
92+ subnet_ids = [
93+ azurerm_subnet . private_app . id
94+ ]
95+
96+ diagnostics {
97+ log_analytics {
98+ workspace_id = data. azurerm_log_analytics_workspace . e2e . workspace_id
99+ workspace_key = data. azurerm_log_analytics_workspace . e2e . primary_shared_key
100+ }
101+ }
102+
103+ tags = local. tags
104+ }
105+
106+ # trivy:ignore:AVD-AZU-0016
107+ resource "azurerm_key_vault" "kv" {
108+ name = provider::dx::resource_name (merge (local. naming_config , { resource_type = " key_vault" , instance_number = random_integer.appcs_instance.result }))
109+ location = azurerm_resource_group. e2e_appcs . location
110+ resource_group_name = azurerm_resource_group. e2e_appcs . name
111+ tenant_id = data. azurerm_client_config . current . tenant_id
112+ rbac_authorization_enabled = true
113+ sku_name = " standard"
114+ purge_protection_enabled = false
115+ public_network_access_enabled = false
116+
117+ network_acls {
118+ bypass = " AzureServices"
119+ default_action = " Deny"
120+ }
121+
122+ tags = local. tags
123+ }
124+
125+ # trivy:ignore:AVD-AZU-0015
126+ # trivy:ignore:AVD-AZU-0017
127+ resource "azurerm_key_vault_secret" "test_secret" {
128+ name = " secret-key"
129+ key_vault_id = azurerm_key_vault. kv . id
130+ value = " secret-value"
131+
132+ depends_on = [
133+ module . integration_github_roles
134+ ]
135+ }
136+
137+ resource "azurerm_private_endpoint" "kv" {
138+ name = provider::dx::resource_name (merge (local. naming_config , { resource_type = " key_vault_private_endpoint" , instance_number = random_integer.appcs_instance.result }))
139+ location = azurerm_resource_group. e2e_appcs . location
140+ resource_group_name = azurerm_resource_group. e2e_appcs . name
141+ subnet_id = data. azurerm_subnet . pep . id
142+
143+ private_service_connection {
144+ name = provider::dx::resource_name (merge (local. naming_config , { resource_type = " key_vault_private_endpoint" , instance_number = random_integer.appcs_instance.result }))
145+ private_connection_resource_id = azurerm_key_vault. kv . id
146+ is_manual_connection = false
147+ subresource_names = [" vault" ]
148+ }
149+
150+ private_dns_zone_group {
151+ name = " private-dns-zone-group"
152+ private_dns_zone_ids = [data . azurerm_private_dns_zone . kv . id ]
153+ }
154+
155+ tags = local. tags
156+ }
157+
158+ module "role_appcs_private" {
159+ source = " pagopa-dx/azure-role-assignments/azurerm"
160+ version = " ~> 1.0"
161+
162+ principal_id = azurerm_container_group. private_app . identity [0 ]. principal_id
163+ subscription_id = data. azurerm_subscription . current . subscription_id
164+
165+ app_config = [
166+ {
167+ name = module.private_appcs.name
168+ resource_group_name = module.private_appcs.resource_group_name
169+ description = " Allow private Container Instance to read from App Configuration"
170+ role = " reader"
171+ }
172+ ]
173+
174+ # key_vault = {
175+ # name = module.private_keyvault.key_vault_name
176+ # resource_group_name = module.private_keyvault.resource_group_name
177+ # has_rbac_enabled = true
178+ # }
179+ }
180+
181+ module "role_appcs_public" {
182+ source = " pagopa-dx/azure-role-assignments/azurerm"
183+ version = " ~> 1.0"
184+
185+ principal_id = azurerm_container_group. public_app . identity [0 ]. principal_id
186+ subscription_id = data. azurerm_subscription . current . subscription_id
187+
188+ app_config = [
189+ {
190+ name = module.private_appcs.name
191+ resource_group_name = module.private_appcs.resource_group_name
192+ description = " Allow public Container Instance to read from App Configuration"
193+ role = " reader"
194+ }
195+ ]
196+ }
197+
198+ module "integration_github_roles" {
199+ source = " pagopa-dx/azure-role-assignments/azurerm"
200+ version = " ~> 1.0"
201+
202+ principal_id = data. azurerm_user_assigned_identity . integration_github . principal_id
203+ subscription_id = data. azurerm_subscription . current . subscription_id
204+
205+ app_config = [
206+ {
207+ name = module.private_appcs.name
208+ resource_group_name = module.private_appcs.resource_group_name
209+ description = " Allow GitHub to write settings on App Configuration"
210+ role = " writer"
211+ }
212+ ]
213+
214+ key_vault = [
215+ {
216+ name = azurerm_key_vault.kv.name
217+ resource_group_name = azurerm_key_vault.kv.resource_group_name
218+ description = " Allow GitHub to write secrets on Key Vault"
219+ roles = {
220+ secrets = " writer"
221+ }
222+ }
223+ ]
224+ }
0 commit comments