pulumi-django-azure 1.0.17__py3-none-any.whl → 1.0.18__py3-none-any.whl

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.

Potentially problematic release.


This version of pulumi-django-azure might be problematic. Click here for more details.

@@ -71,6 +71,8 @@ class DjangoDeployment(pulumi.ComponentResource):
71
71
  storage_allowed_origins: Optional[Sequence[str]] = None,
72
72
  pgadmin_access_ip: Optional[Sequence[str]] = None,
73
73
  pgadmin_dns_zone: Optional[azure.network.Zone] = None,
74
+ cache_ip_prefix: Optional[str] = None,
75
+ cache_sku: Optional[azure.cache.SkuArgs] = None,
74
76
  cdn_host: Optional[HostDefinition] = None,
75
77
  opts=None,
76
78
  ):
@@ -89,6 +91,8 @@ class DjangoDeployment(pulumi.ComponentResource):
89
91
  :param storage_allowed_origins: The origins (hosts) to allow access through CORS policy. You can specify '*' to allow all.
90
92
  :param pgadmin_access_ip: The IP addresses to allow access to pgAdmin. If empty, all IP addresses are allowed.
91
93
  :param pgadmin_dns_zone: The Azure DNS zone to a pgadmin DNS record in. (optional)
94
+ :param cache_ip_prefix: The IP prefix for the cache subnet. (optional)
95
+ :param cache_sku: The SKU for the cache. (optional)
92
96
  :param cdn_host: A custom CDN host name. (optional)
93
97
  :param opts: The resource options
94
98
  """
@@ -110,6 +114,12 @@ class DjangoDeployment(pulumi.ComponentResource):
110
114
  # PostgreSQL resources
111
115
  self._create_database(sku=pgsql_sku, ip_prefix=pgsql_ip_prefix)
112
116
 
117
+ # Cache resources
118
+ if cache_ip_prefix and cache_sku:
119
+ self._create_cache(sku=cache_sku, ip_prefix=cache_ip_prefix)
120
+ else:
121
+ self._cache = None
122
+
113
123
  # Subnet for the apps
114
124
  self._app_subnet = self._create_subnet(
115
125
  name="app-service",
@@ -299,6 +309,85 @@ class DjangoDeployment(pulumi.ComponentResource):
299
309
 
300
310
  pulumi.export("pgsql_host", self._pgsql.fully_qualified_domain_name)
301
311
 
312
+ def _create_cache(self, sku: azure.cache.SkuArgs, ip_prefix: str):
313
+ # Create a Redis cache
314
+ self._cache = azure.cache.Redis(
315
+ f"cache-{self._name}",
316
+ resource_group_name=self._rg,
317
+ sku=sku,
318
+ enable_non_ssl_port=False,
319
+ public_network_access=azure.cache.PublicNetworkAccess.DISABLED,
320
+ )
321
+
322
+ # Create an access policy that gives us access to the cache
323
+ self._cache_access_policy = azure.cache.AccessPolicy(
324
+ f"cache-access-policy-{self._name}",
325
+ resource_group_name=self._rg,
326
+ cache_name=self._cache.name,
327
+ # Same as the built in Data Contributor policy
328
+ permissions="+@all -@dangerous +cluster|info +cluster|nodes +cluster|slots allkeys",
329
+ )
330
+
331
+ # Allocate a subnet for the cache
332
+ subnet = self._create_subnet(
333
+ name="cache",
334
+ prefix=ip_prefix,
335
+ )
336
+
337
+ # Create a private DNS zone for the cache
338
+ dns = azure.network.PrivateZone(
339
+ f"dns-cache-{self._name}",
340
+ resource_group_name=self._rg,
341
+ location="global",
342
+ private_zone_name="privatelink.redis.cache.windows.net",
343
+ )
344
+
345
+ # Link the private DNS zone to the VNet in order to make resolving work
346
+ azure.network.VirtualNetworkLink(
347
+ f"vnet-link-cache-{self._name}",
348
+ resource_group_name=self._rg,
349
+ location="global",
350
+ private_zone_name=dns.name,
351
+ virtual_network=azure.network.SubResourceArgs(id=self._vnet.id),
352
+ registration_enabled=True,
353
+ )
354
+
355
+ # Create a private endpoint for the cache
356
+ endpoint = azure.network.PrivateEndpoint(
357
+ f"private-endpoint-cache-{self._name}",
358
+ resource_group_name=self._rg,
359
+ subnet=azure.network.SubnetArgs(id=subnet.id),
360
+ custom_network_interface_name=f"nic-cache-{self._name}",
361
+ private_link_service_connections=[
362
+ azure.network.PrivateLinkServiceConnectionArgs(
363
+ name=f"pls-cache-{self._name}",
364
+ private_link_service_id=self._cache.id,
365
+ group_ids=["redisCache"],
366
+ )
367
+ ],
368
+ )
369
+
370
+ # Get the private IP address of the endpoint NIC
371
+ ip = endpoint.network_interfaces.apply(
372
+ lambda nics: azure.network.get_network_interface(
373
+ network_interface_name=nics[0].id.split("/")[-1],
374
+ resource_group_name=self._rg,
375
+ )
376
+ .ip_configurations[0]
377
+ .private_ip_address
378
+ )
379
+
380
+ # Create a DNS record for the cache
381
+ azure.network.PrivateRecordSet(
382
+ f"dns-a-cache-{self._name}",
383
+ resource_group_name=self._rg,
384
+ private_zone_name=dns.name,
385
+ relative_record_set_name=self._cache.name,
386
+ record_type="A",
387
+ ttl=300,
388
+ a_records=[azure.network.ARecordArgs(ipv4_address=ip)],
389
+ )
390
+
302
391
  def _create_subnet(
303
392
  self,
304
393
  name,
@@ -329,7 +418,8 @@ class DjangoDeployment(pulumi.ComponentResource):
329
418
  resource_group_name=self._rg,
330
419
  virtual_network_name=self._vnet.name,
331
420
  address_prefix=prefix,
332
- delegations=[delegation_service],
421
+ # We cannot pass an empty list to the delegations parameter, so either list or None
422
+ delegations=[delegation_service] if delegation_service else None,
333
423
  service_endpoints=service_endpoints,
334
424
  )
335
425
 
@@ -562,7 +652,7 @@ class DjangoDeployment(pulumi.ComponentResource):
562
652
 
563
653
  # DKIM records (two CNAME records)
564
654
  for record in ("d_kim", "d_kim2"):
565
- if host.host == "@":
655
+ if host.host == "@": # noqa: SIM108
566
656
  relative_record_set_name = records[record]["name"]
567
657
  else:
568
658
  relative_record_set_name = f"{records[record]['name']}.{host.host}"
@@ -753,6 +843,7 @@ class DjangoDeployment(pulumi.ComponentResource):
753
843
  comms_domains: Optional[list[HostDefinition]] = None,
754
844
  dedicated_app_service_sku: Optional[azure.web.SkuDescriptionArgs] = None,
755
845
  vault_administrators: Optional[list[str]] = None,
846
+ cache_db: Optional[int] = None,
756
847
  ) -> azure.web.WebApp:
757
848
  """
758
849
  Create a Django website with it's own database and storage containers.
@@ -770,7 +861,8 @@ class DjangoDeployment(pulumi.ComponentResource):
770
861
  :param comms_data_location: The data location for the Communication Services (optional if you don't need it).
771
862
  :param comms_domains: The list of custom domains for the E-mail Communication Services (optional).
772
863
  :param dedicated_app_service_sku: The SKU for the dedicated App Service Plan (optional).
773
- :param vault_administrator: The principal ID of the vault administrator (optional).
864
+ :param vault_administrators: The principal IDs of the vault administrators (optional).
865
+ :param cache_db: The index of the cache database to use (optional).
774
866
  """
775
867
 
776
868
  # Create a database
@@ -819,6 +911,12 @@ class DjangoDeployment(pulumi.ComponentResource):
819
911
  s = self._add_webapp_secret(vault, env_name, config_name, f"{name}-{self._name}")
820
912
  environment_variables[f"{env_name}_SECRET_NAME"] = s.name
821
913
 
914
+ # Cache
915
+ if self._cache and cache_db:
916
+ environment_variables["REDIS_CACHE_HOST"] = self._cache.host_name
917
+ environment_variables["REDIS_CACHE_PORT"] = self._cache.ssl_port.apply(lambda port: str(port))
918
+ environment_variables["REDIS_CACHE_DB"] = str(cache_db)
919
+
822
920
  # Create a Django Secret Key (random)
823
921
  secret_key = pulumi_random.RandomString(f"django-secret-{name}-{self._name}", length=50)
824
922
 
@@ -832,7 +930,7 @@ class DjangoDeployment(pulumi.ComponentResource):
832
930
  ]
833
931
 
834
932
  allowed_hosts = pulumi.Output.concat(*[pulumi.Output.concat(host.full_host, ",") for host in website_hosts])
835
-
933
+
836
934
  # Create a dedicated App Service Plan if requested
837
935
  if dedicated_app_service_sku:
838
936
  app_service_plan = azure.web.AppServicePlan(
@@ -877,14 +975,8 @@ class DjangoDeployment(pulumi.ComponentResource):
877
975
  # Vault settings
878
976
  azure.web.NameValuePairArgs(name="AZURE_KEY_VAULT", value=vault.name),
879
977
  # Storage settings
880
- azure.web.NameValuePairArgs(
881
- name="AZURE_STORAGE_ACCOUNT_NAME",
882
- value=self._storage_account.name,
883
- ),
884
- azure.web.NameValuePairArgs(
885
- name="AZURE_STORAGE_CONTAINER_STATICFILES",
886
- value=static_container.name,
887
- ),
978
+ azure.web.NameValuePairArgs(name="AZURE_STORAGE_ACCOUNT_NAME", value=self._storage_account.name),
979
+ azure.web.NameValuePairArgs(name="AZURE_STORAGE_CONTAINER_STATICFILES", value=static_container.name),
888
980
  azure.web.NameValuePairArgs(name="AZURE_STORAGE_CONTAINER_MEDIA", value=media_container.name),
889
981
  # CDN
890
982
  azure.web.NameValuePairArgs(name="CDN_HOST", value=self._cdn_host),
@@ -1024,6 +1116,17 @@ class DjangoDeployment(pulumi.ComponentResource):
1024
1116
  scope=self._storage_account.id,
1025
1117
  )
1026
1118
 
1119
+ # Grant the app access to the cache if needed
1120
+ if self._cache and cache_db:
1121
+ azure.cache.AccessPolicyAssignment(
1122
+ f"ra-{name}-cache",
1123
+ resource_group_name=self._rg,
1124
+ cache_name=self._cache.name,
1125
+ object_id=principal_id,
1126
+ object_id_alias=f"app-{name}-managed-identity",
1127
+ access_policy_name=self._cache_access_policy.name,
1128
+ )
1129
+
1027
1130
  # Grant the app to send e-mails
1028
1131
  if comms:
1029
1132
  comms_role = comms.id.apply(
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.2
2
2
  Name: pulumi-django-azure
3
- Version: 1.0.17
3
+ Version: 1.0.18
4
4
  Summary: Simply deployment of Django on Azure with Pulumi
5
5
  Author-email: Maarten Ureel <maarten@youreal.eu>
6
6
  License: MIT License
@@ -0,0 +1,7 @@
1
+ pulumi_django_azure/__init__.py,sha256=5RY9reSVNw-HULrOXfhcq3cyPne-94ojFmeV1m6kIVg,79
2
+ pulumi_django_azure/django_deployment.py,sha256=dL_IiQEjY6M-xI-ZEZarirtaQTe5DRYjYTQARJ79onA,49053
3
+ pulumi_django_azure-1.0.18.dist-info/LICENSE,sha256=NX2LN3U319Zaac8b7ZgfNOco_nTBbN531X_M_13niSg,1087
4
+ pulumi_django_azure-1.0.18.dist-info/METADATA,sha256=oe7FrZIcRWMRKL2JljxqvqebA9LiCBz4LumwmA_SlYQ,13955
5
+ pulumi_django_azure-1.0.18.dist-info/WHEEL,sha256=jB7zZ3N9hIM9adW7qlTAyycLYW9npaWKLRzaoVcLKcM,91
6
+ pulumi_django_azure-1.0.18.dist-info/top_level.txt,sha256=MNPRJhq-_G8EMCHRkjdcb_xrqzOkmKogXUGV7Ysz3g0,20
7
+ pulumi_django_azure-1.0.18.dist-info/RECORD,,
@@ -1,5 +1,5 @@
1
1
  Wheel-Version: 1.0
2
- Generator: setuptools (75.8.0)
2
+ Generator: setuptools (75.8.2)
3
3
  Root-Is-Purelib: true
4
4
  Tag: py3-none-any
5
5
 
@@ -1,7 +0,0 @@
1
- pulumi_django_azure/__init__.py,sha256=5RY9reSVNw-HULrOXfhcq3cyPne-94ojFmeV1m6kIVg,79
2
- pulumi_django_azure/django_deployment.py,sha256=y5Jk4W9tIYihlc46z8Nt-Jrn_fmKLDJfc3nbo66M9oY,44619
3
- pulumi_django_azure-1.0.17.dist-info/LICENSE,sha256=NX2LN3U319Zaac8b7ZgfNOco_nTBbN531X_M_13niSg,1087
4
- pulumi_django_azure-1.0.17.dist-info/METADATA,sha256=p-UAXhOPFUb5d5kX9wpMmh0bauaYA7p8xDfORsJ8nYQ,13955
5
- pulumi_django_azure-1.0.17.dist-info/WHEEL,sha256=In9FTNxeP60KnTkGw7wk6mJPYd_dQSjEZmXdBdMCI-8,91
6
- pulumi_django_azure-1.0.17.dist-info/top_level.txt,sha256=MNPRJhq-_G8EMCHRkjdcb_xrqzOkmKogXUGV7Ysz3g0,20
7
- pulumi_django_azure-1.0.17.dist-info/RECORD,,