Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 5 additions & 0 deletions .changeset/loud-camels-tickle.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"azure_cdn": patch
---

Remove old tests, use new for contracts, integration, unit and e2e
1 change: 1 addition & 0 deletions go.work
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
go 1.25.3

use (
./infra/modules/azure_cdn/tests
./infra/modules/azure_cosmos_account/tests
./providers/aws
./providers/aws/tools
Expand Down
1,211 changes: 1,210 additions & 1 deletion go.work.sum

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion infra/modules/azure_cdn/custom_domain.tf
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ resource "azurerm_cdn_frontdoor_secret" "certificate" {

secret {
customer_certificate {
key_vault_certificate_id = each.value.dns.key_vault_certificate_versionless_id
key_vault_certificate_id = each.value.custom_certificate.key_vault_certificate_versionless_id
}
}
}
Expand Down
37 changes: 37 additions & 0 deletions infra/modules/azure_cdn/examples/e2e/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
# advanced

<!-- BEGIN_TF_DOCS -->
## Requirements

| Name | Version |
|------|---------|
| <a name="requirement_terraform"></a> [terraform](#requirement\_terraform) | ~> 1.9 |
| <a name="requirement_azurerm"></a> [azurerm](#requirement\_azurerm) | ~> 4.0 |
| <a name="requirement_dx"></a> [dx](#requirement\_dx) | ~> 0.0.6 |

## Modules

| Name | Source | Version |
|------|--------|---------|
| <a name="module_azure_cdn"></a> [azure\_cdn](#module\_azure\_cdn) | ../../ | n/a |
| <a name="module_storage_account"></a> [storage\_account](#module\_storage\_account) | pagopa-dx/azure-storage-account/azurerm | ~> 2.1 |

## Resources

| Name | Type |
|------|------|
| [azurerm_cdn_frontdoor_profile.integration](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/cdn_frontdoor_profile) | data source |
| [azurerm_resource_group.integration](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/resource_group) | data source |
| [azurerm_subnet.pep](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/data-sources/subnet) | data source |

## Inputs

No inputs.

## Outputs

| Name | Description |
|------|-------------|
| <a name="output_endpoint_host_name"></a> [endpoint\_host\_name](#output\_endpoint\_host\_name) | CDN endpoint |
| <a name="output_profile_id"></a> [profile\_id](#output\_profile\_id) | The ID of the CDN profile |
<!-- END_TF_DOCS -->
38 changes: 38 additions & 0 deletions infra/modules/azure_cdn/examples/e2e/locals.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
locals {
environment = {
prefix = "dx"
env_short = "d"
location = "italynorth"
domain = "e2e"
app_name = "test"
instance_number = "01"
}

naming_config = {
prefix = local.environment.prefix,
environment = local.environment.env_short,
location = local.environment.location
name = local.environment.app_name,
instance_number = tonumber(local.environment.instance_number),
}

virtual_network = {
name = provider::dx::resource_name(merge(local.naming_config, {
name = "common",
resource_type = "virtual_network"
}))
resource_group_name = provider::dx::resource_name(merge(local.naming_config, {
name = "network",
resource_type = "resource_group"
}))
}

tags = {
CostCenter = "TS000 - Tecnologia e Servizi"
CreatedBy = "Terraform"
Environment = "Dev"
BusinessUnit = "DevEx"
ManagementTeam = "Developer Experience"
Source = "https://github.com/pagopa/dx/modules/azure_cdn/examples/e2e"
}
}
71 changes: 71 additions & 0 deletions infra/modules/azure_cdn/examples/e2e/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,71 @@

data "azurerm_resource_group" "integration" {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
data "azurerm_resource_group" "integration" {
data "azurerm_resource_group" "e2e" {

name = provider::dx::resource_name(merge(local.naming_config, {
name = "integration",
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
name = "integration",
name = "e2e",

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I know it's not ideal, but to avoid creating two identical CDNs, I leveraged the existing integration one. Do you think it would be better to create a dedicated one for E2E as well?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As discussed in this morning, I believe it'd be better to have two different infrastructures for the two kind of tests. Keep in mind that also foundational infrastructure (vnet, peps, etc.) is also doubled

resource_type = "resource_group"
}))
}

data "azurerm_cdn_frontdoor_profile" "integration" {
name = "dx-d-itn-test-afd-01"
resource_group_name = data.azurerm_resource_group.integration.name
}

data "azurerm_subnet" "pep" {
name = provider::dx::resource_name(merge(local.naming_config, {
name = "pep",
resource_type = "subnet"
}))
virtual_network_name = local.virtual_network.name
resource_group_name = local.virtual_network.resource_group_name
}

# Create a storage account with static website enabled
module "storage_account" {
source = "pagopa-dx/azure-storage-account/azurerm"
version = "~> 2.1"

environment = local.environment

resource_group_name = data.azurerm_resource_group.integration.name
use_case = "default"
subnet_pep_id = data.azurerm_subnet.pep.id

force_public_network_access_enabled = true # Public network access enabled for CDN origin reachability

static_website = {
enabled = true
index_document = "index.html"
}

subservices_enabled = {
blob = true
}

tags = local.tags
}

module "azure_cdn" {
# source = "pagopa-dx/azure-cdn/azurerm"
# version = "~> 0.5"
source = "../../"

resource_group_name = data.azurerm_resource_group.integration.name

environment = local.environment

# Reuse the existing CDN profile created above
existing_cdn_frontdoor_profile_id = data.azurerm_cdn_frontdoor_profile.integration.id

# WAF is already enabled on the profile, create security policy for this endpoint
waf_enabled = true

origins = {
primary = {
host_name = module.storage_account.primary_web_host
priority = 1
}
}

tags = local.tags
}
10 changes: 10 additions & 0 deletions infra/modules/azure_cdn/examples/e2e/outputs.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
output "profile_id" {
description = "The ID of the CDN profile"
value = module.azure_cdn.id
}


output "endpoint_host_name" {
value = module.azure_cdn.endpoint_hostname
description = "CDN endpoint"
}
17 changes: 17 additions & 0 deletions infra/modules/azure_cdn/examples/e2e/versions.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
terraform {
required_version = "~> 1.9"
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "~> 4.0"
}
dx = {
source = "pagopa-dx/azure"
version = "~> 0.0.6"
}
}
}

provider "azurerm" {
features {}
}
9 changes: 8 additions & 1 deletion infra/modules/azure_cdn/package.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,12 @@
"version": "0.4.0",
"private": true,
"provider": "azurerm",
"description": "Allows to easily create an Azure FrontDoor CDN"
"description": "Allows to easily create an Azure FrontDoor CDN",
"scripts": {
"tf-init": "terraform init",
"test:unit": "terraform test -filter='tests/unit.tftest.hcl'",
"test:contract": "terraform test -filter='tests/contract.tftest.hcl'",
"test:integration": "terraform test -filter='tests/integration.tftest.hcl'",
"test:e2e": "go test -v -timeout 1h ./tests"
}
}
16 changes: 0 additions & 16 deletions infra/modules/azure_cdn/tests/README.md

This file was deleted.

Loading