pulumi-django-azure 1.0.6__tar.gz → 1.0.8__tar.gz

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.

@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pulumi-django-azure
3
- Version: 1.0.6
3
+ Version: 1.0.8
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
@@ -45,6 +45,7 @@ To have a proper and secure environment, we need these components:
45
45
  * Storage account for media and static files
46
46
  * CDN endpoint in front with a domain name of our choosing
47
47
  * PostgreSQL server
48
+ * Azure Communication Services to send e-mails
48
49
  * Webapp with multiple custom host names and managed SSL for the website itself
49
50
  * Webapp running pgAdmin
50
51
 
@@ -101,6 +102,8 @@ django.add_django_website(
101
102
  repository_branch="main",
102
103
  website_hosts=["example.com", "www.example.com"],
103
104
  django_settings_module="mywebsite.settings.production",
105
+ comms_data_location="europe",
106
+ comms_domains=["mydomain.com"],
104
107
  )
105
108
 
106
109
  django.add_database_administrator(
@@ -120,6 +123,7 @@ django.add_database_administrator(
120
123
  6. Re-deploy with custom hosts
121
124
  7. Re-deploy once more to enable HTTPS on website domains
122
125
  8. Manually activate HTTPS on the CDN host
126
+ 9. Go to the e-mail communications service on Azure and configure DKIM, SPF,... for your custom domains.
123
127
 
124
128
  ## Custom domain name for CDN
125
129
  When deploying the first time, you will get a `cdn_cname` output. You need to create a CNAME to this domain before the deployment of the custom domain will succeed.
@@ -6,6 +6,7 @@ To have a proper and secure environment, we need these components:
6
6
  * Storage account for media and static files
7
7
  * CDN endpoint in front with a domain name of our choosing
8
8
  * PostgreSQL server
9
+ * Azure Communication Services to send e-mails
9
10
  * Webapp with multiple custom host names and managed SSL for the website itself
10
11
  * Webapp running pgAdmin
11
12
 
@@ -62,6 +63,8 @@ django.add_django_website(
62
63
  repository_branch="main",
63
64
  website_hosts=["example.com", "www.example.com"],
64
65
  django_settings_module="mywebsite.settings.production",
66
+ comms_data_location="europe",
67
+ comms_domains=["mydomain.com"],
65
68
  )
66
69
 
67
70
  django.add_database_administrator(
@@ -81,6 +84,7 @@ django.add_database_administrator(
81
84
  6. Re-deploy with custom hosts
82
85
  7. Re-deploy once more to enable HTTPS on website domains
83
86
  8. Manually activate HTTPS on the CDN host
87
+ 9. Go to the e-mail communications service on Azure and configure DKIM, SPF,... for your custom domains.
84
88
 
85
89
  ## Custom domain name for CDN
86
90
  When deploying the first time, you will get a `cdn_cname` output. You need to create a CNAME to this domain before the deployment of the custom domain will succeed.
@@ -4,7 +4,7 @@ build-backend = "setuptools.build_meta"
4
4
 
5
5
  [project]
6
6
  name = "pulumi-django-azure"
7
- version = "1.0.6"
7
+ version = "1.0.8"
8
8
  description = "Simply deployment of Django on Azure with Pulumi"
9
9
  readme = "README.md"
10
10
  authors = [{ name = "Maarten Ureel", email = "maarten@youreal.eu" }]
@@ -27,7 +27,7 @@ Homepage = "https://gitlab.com/MaartenUreel/pulumi-django-azure"
27
27
 
28
28
  [tool.poetry]
29
29
  name = "pulumi-django-azure"
30
- version = "1.0.6"
30
+ version = "1.0.8"
31
31
  description = "Simply deployment of Django on Azure with Pulumi"
32
32
  authors = ["Maarten Ureel <maarten@youreal.eu>"]
33
33
 
@@ -29,11 +29,13 @@ class DjangoDeployment(pulumi.ComponentResource):
29
29
  :param tenant_id: The Entra tenant ID for the database authentication.
30
30
  :param resource_group_name: The resource group name to create the resources in.
31
31
  :param vnet: The virtual network to create the subnets in.
32
+ :param pgsql_sku: The SKU for the PostgreSQL server.
32
33
  :param pgsql_ip_prefix: The IP prefix for the PostgreSQL subnet.
33
34
  :param appservice_ip_prefix: The IP prefix for the app service subnet.
34
35
  :param app_service_sku: The SKU for the app service plan.
35
36
  :param storage_account_name: The name of the storage account. Should be unique across Azure.
36
37
  :param cdn_host: A custom CDN host name (optional)
38
+ :param comms_data_location: The data location for the Communication Services (optional if you don't need it)
37
39
  :param opts: The resource options
38
40
  """
39
41
 
@@ -344,6 +346,51 @@ class DjangoDeployment(pulumi.ComponentResource):
344
346
  host_name=host,
345
347
  )
346
348
 
349
+ def _add_webapp_comms(self, data_location: str, domains: list[str], suffix: str) -> azure.communication.CommunicationService:
350
+ email_service = azure.communication.EmailService(
351
+ f"comms-email-{suffix}",
352
+ resource_group_name=self._rg,
353
+ location="global",
354
+ data_location=data_location,
355
+ )
356
+
357
+ domain_resources = []
358
+ if domains:
359
+ # Add our own custom domains
360
+ for domain in domains:
361
+ safe_host = domain.replace(".", "-")
362
+ d = azure.communication.Domain(
363
+ f"comms-email-domain-{suffix}-{safe_host}",
364
+ resource_group_name=self._rg,
365
+ location="global",
366
+ domain_management=azure.communication.DomainManagement.CUSTOMER_MANAGED,
367
+ domain_name=domain,
368
+ email_service_name=email_service.name,
369
+ )
370
+ domain_resources.append(d.id.apply(lambda n: n))
371
+ else:
372
+ # Add an Azure managed domain
373
+ d = azure.communication.Domain(
374
+ f"comms-email-domain-{suffix}-azure",
375
+ resource_group_name=self._rg,
376
+ location="global",
377
+ domain_management=azure.communication.DomainManagement.AZURE_MANAGED,
378
+ domain_name="AzureManagedDomain",
379
+ email_service_name=email_service.name,
380
+ )
381
+ domain_resources.append(d.id.apply(lambda n: n))
382
+
383
+ # Create Communication Services and link the domains
384
+ comm_service = azure.communication.CommunicationService(
385
+ f"comms-{suffix}",
386
+ resource_group_name=self._rg,
387
+ location="global",
388
+ data_location=data_location,
389
+ linked_domains=domain_resources,
390
+ )
391
+
392
+ return comm_service
393
+
347
394
  def _get_storage_account_access_keys(
348
395
  self, storage_account: azure.storage.StorageAccount
349
396
  ) -> Sequence[azure.storage.outputs.StorageAccountKeyResponse]:
@@ -390,6 +437,8 @@ class DjangoDeployment(pulumi.ComponentResource):
390
437
  website_hosts: list[str],
391
438
  django_settings_module: str,
392
439
  environment_variables: dict[str, str] = {},
440
+ comms_data_location: Optional[str] = None,
441
+ comms_domains: Optional[list[str]] = [],
393
442
  ) -> azure.web.WebApp:
394
443
  """
395
444
  Create a Django website with it's own database and storage containers.
@@ -401,6 +450,8 @@ class DjangoDeployment(pulumi.ComponentResource):
401
450
  :param website_hosts: The list of custom host names for the website.
402
451
  :param django_settings_module: The Django settings module to load.
403
452
  :param environment_variables: A dictionary of environment variables to set.
453
+ :param comms_data_location: The data location for the Communication Services (optional if you don't need it).
454
+ :param comms_domains: The list of custom domains for the E-mail Communication Services (optional).
404
455
  """
405
456
 
406
457
  # Create a database
@@ -429,6 +480,14 @@ class DjangoDeployment(pulumi.ComponentResource):
429
480
  container_name=f"{name}-static",
430
481
  )
431
482
 
483
+ # Communication Services (optional)
484
+ if comms_data_location:
485
+ comms = self._add_webapp_comms(comms_data_location, comms_domains, f"{name}-{self._name}")
486
+ # Add the domains as environment variable
487
+ environment_variables["AZURE_COMMUNICATION_SERVICE_ENDPOINT"] = comms.host_name.apply(lambda host: f"https://{host}")
488
+ else:
489
+ comms = None
490
+
432
491
  # Create a Django Secret Key (random)
433
492
  secret_key = pulumi_random.RandomString(f"django-secret-{name}-{self._name}", length=50)
434
493
 
@@ -530,6 +589,24 @@ class DjangoDeployment(pulumi.ComponentResource):
530
589
  scope=self._storage_account.id,
531
590
  )
532
591
 
592
+ # Grant the app to send e-mails
593
+ if comms:
594
+ comms_role = comms.id.apply(
595
+ lambda scope: azure.authorization.get_role_definition(
596
+ # Contributor
597
+ role_definition_id="b24988ac-6180-42a0-ab88-20f7382dd24c",
598
+ scope=scope,
599
+ )
600
+ )
601
+
602
+ azure.authorization.RoleAssignment(
603
+ f"ra-{name}-comms",
604
+ principal_id=principal_id,
605
+ principal_type=azure.authorization.PrincipalType.SERVICE_PRINCIPAL,
606
+ role_definition_id=comms_role.id,
607
+ scope=comms.id,
608
+ )
609
+
533
610
  # Create a CORS rules for this website
534
611
  if website_hosts:
535
612
  origins = [f"https://{host}" for host in website_hosts]
@@ -1,6 +1,6 @@
1
1
  Metadata-Version: 2.1
2
2
  Name: pulumi-django-azure
3
- Version: 1.0.6
3
+ Version: 1.0.8
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
@@ -45,6 +45,7 @@ To have a proper and secure environment, we need these components:
45
45
  * Storage account for media and static files
46
46
  * CDN endpoint in front with a domain name of our choosing
47
47
  * PostgreSQL server
48
+ * Azure Communication Services to send e-mails
48
49
  * Webapp with multiple custom host names and managed SSL for the website itself
49
50
  * Webapp running pgAdmin
50
51
 
@@ -101,6 +102,8 @@ django.add_django_website(
101
102
  repository_branch="main",
102
103
  website_hosts=["example.com", "www.example.com"],
103
104
  django_settings_module="mywebsite.settings.production",
105
+ comms_data_location="europe",
106
+ comms_domains=["mydomain.com"],
104
107
  )
105
108
 
106
109
  django.add_database_administrator(
@@ -120,6 +123,7 @@ django.add_database_administrator(
120
123
  6. Re-deploy with custom hosts
121
124
  7. Re-deploy once more to enable HTTPS on website domains
122
125
  8. Manually activate HTTPS on the CDN host
126
+ 9. Go to the e-mail communications service on Azure and configure DKIM, SPF,... for your custom domains.
123
127
 
124
128
  ## Custom domain name for CDN
125
129
  When deploying the first time, you will get a `cdn_cname` output. You need to create a CNAME to this domain before the deployment of the custom domain will succeed.