Skip to content

Commit

Permalink
Moved frontdoor id variable
Browse files Browse the repository at this point in the history
  • Loading branch information
tleguijt committed Nov 27, 2020
1 parent 3466e36 commit 12c7d93
Show file tree
Hide file tree
Showing 9 changed files with 101 additions and 8 deletions.
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
- Add support for multiple API endpoints:
- `base_url` replaced with `endpoints`
- `has_public_api` replaced with `endpoint`
- Add new required `frontdoor_id` Terraform variable for components with `endpoint` defined

### Breaking changes
- `base_url` has been replaced by the `endpoints` settings:<br>
Expand All @@ -31,6 +32,7 @@
```
When you name the endpoint that replaces `base_url` "main", it will have the least effect on your existing Terraform state.
- The `FRONTDOOR_ID` value is removed from the `var.variables` of a component. Replaced with `var.frontdoor_id`

## 0.5.1 (2020-11-10)
- Removed `aws` block in general_config
Expand Down
6 changes: 5 additions & 1 deletion docs/src/components/aws.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,11 @@ In addition to this, the component itself is responsible for [packaging and depl

## Terraform variables

In addition to the [base variables](./index.md#required-variables), an AWS component expects the following:
In addition to the [base variables](./index.md#required-variables) AWS components don't require additional variables, unless an `endpoint` is expected (and set in the configuration).

### With `endpoint`

In order to support the [`endpoint`](../deployment/config/aws.md#http-routing) attribute on the component, the component needs to have the following variables defined:

- `api_gateway` - API Gateway ID to publish in (only if component has an `endpoint` defined)
- `api_gateway_execution_arn` API Gateway API Execution ARN (only if component is has an `endpoint` defined)
Expand Down
8 changes: 8 additions & 0 deletions docs/src/components/azure.md
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,14 @@ variable "monitor_action_group_id" {
}
```


### With `endpoint`

In order to support the [`endpoint`](../deployment/config/azure.md#http-routing) attribute on the component, the component needs to have the following variables defined:

- `frontdoor_id` - Frontdoor ID on which routing is created for that component


## Packaging and deploying

For Azure functions, the deployment process constist of two steps:
Expand Down
4 changes: 0 additions & 4 deletions src/mach/templates/partials/component.tf
Original file line number Diff line number Diff line change
Expand Up @@ -39,10 +39,6 @@ module "{{ component.name }}" {
{{ key }} = {{ value|component_value }}
{% endfor %}

{% if site.azure.front_door and component.endpoint %}
FRONTDOOR_ID = azurerm_frontdoor.app-service.header_frontdoor_id
{% endif %}

{% if site.commercetools %}
{# BACKWARDS COMPATABILITY - DEPRECATED #}
CT_API_URL = "{{ site.commercetools.api_url }}"
Expand Down
3 changes: 3 additions & 0 deletions src/mach/templates/partials/component_azure_variables.tf
Original file line number Diff line number Diff line change
Expand Up @@ -11,4 +11,7 @@ app_service_plan_id = azurerm_app_service_plan.functionapps.id
tags = local.tags
{% if site.azure.alert_group %}
monitor_action_group_id = azurerm_monitor_action_group.alert_action_group.id
{% endif %}
{% if component.endpoint %}
frontdoor_id = azurerm_frontdoor.app-service.header_frontdoor_id
{% endif %}
4 changes: 3 additions & 1 deletion tests/files/azure_config1_expected_mach-site-eu.json
Original file line number Diff line number Diff line change
Expand Up @@ -629,6 +629,9 @@
"tags": [
"${local.tags}"
],
"frontdoor_id": [
"${azurerm_frontdoor.app-service.header_frontdoor_id}"
],
"component_version": [
"0a9a0b5"
],
Expand All @@ -640,7 +643,6 @@
],
"variables": [
{
"FRONTDOOR_ID": "${azurerm_frontdoor.app-service.header_frontdoor_id}",
"CT_API_URL": "https://api.europe-west1.gcp.commercetools.com",
"CT_AUTH_URL": "https://auth.europe-west1.gcp.commercetools.com",
"CT_PROJECT_KEY": "mach-site-eu"
Expand Down
4 changes: 3 additions & 1 deletion tests/files/azure_config1_expected_mach-site-us.json
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,9 @@
"tags": [
"${local.tags}"
],
"frontdoor_id": [
"${azurerm_frontdoor.app-service.header_frontdoor_id}"
],
"component_version": [
"0a9a0b5"
],
Expand All @@ -638,7 +641,6 @@
],
"variables": [
{
"FRONTDOOR_ID": "${azurerm_frontdoor.app-service.header_frontdoor_id}",
"CT_API_URL": "https://api.europe-west1.gcp.commercetools.com",
"CT_AUTH_URL": "https://auth.europe-west1.gcp.commercetools.com",
"CT_PROJECT_KEY": "mach-site-us"
Expand Down
48 changes: 48 additions & 0 deletions tests/fixtures/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,54 @@ def config():
)


@pytest.fixture
def azure_config():
return types.MachConfig(
general_config=types.GeneralConfig(
environment="test",
terraform_config=types.TerraformConfig(
azure_remote_state=types.AzureTFState(
resource_group="shared-rg",
storage_account="machsaterra",
container_name="tfstate",
state_folder="test",
)
),
azure=types.AzureConfig(
tenant_id="6f10659d-4227-43e6-95ab-80d12a18acf9",
subscription_id="5f34d95d-4dd8-40b3-9d18-f9007e2ce6ac",
region="westeurope",
),
cloud="azure",
sentry=types.SentryConfig(dsn="sentry-dsn"),
),
sites=[
types.Site(
identifier="unittest-nl",
components=[
types.Component(
name="api-extensions",
)
],
),
],
components=[
types.ComponentConfig(
name="api-extensions",
source="some-source//terraform",
short_name="apiexts",
version="1.0",
)
],
output_path=tempfile.gettempdir(),
)


@pytest.fixture
def parsed_config(config):
return parse.parse_config(config)


@pytest.fixture
def parsed_azure_config(azure_config):
return parse.parse_config(azure_config)
30 changes: 29 additions & 1 deletion tests/unittests/test_validate.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def test_validate_sentry():
)


def test_validate_endpoints(parsed_config: types.MachConfig):
def test_validate_aws_endpoints(parsed_config: types.MachConfig):
config = parsed_config

config.sites[0].endpoints = {
Expand All @@ -44,6 +44,34 @@ def test_validate_endpoints(parsed_config: types.MachConfig):
validate.validate_config(config)


def test_validate_azure_endpoints(parsed_azure_config: types.MachConfig):
config = parsed_azure_config

config.sites[0].endpoints = {
"public": "api.mach-example.com",
"services": "services.mach-example.com",
}

with pytest.raises(ValidationError):
validate.validate_config(config)

config.general_config.azure.front_door = types.FrontDoorSettings(
resource_group="my-shared-rg",
dns_zone="mach-example.com",
ssl_key_vault_name="mysharedwekvcdn",
ssl_key_vault_secret_name="wildcard-my-services-domain-net",
ssl_key_vault_secret_version="IOlB8XmYLH1keYcpkcji23sp",
)
config = parse.parse_config(config)

validate.validate_config(config)

# Change one of the components that does not match the DNS zone anymore
config.sites[0].endpoints["services"] = "api.mach-services.com"
with pytest.raises(ValidationError):
validate.validate_config(config)


def test_validate_component_endpoint(parsed_config: types.MachConfig):
"""An endpoint defined on a component must exist for all sites that use that component."""
config = parsed_config
Expand Down

1 comment on commit 12c7d93

@tleguijt
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

#43

Please sign in to comment.