Skip to content

Commit 2f94f73

Browse files
author
Mahsa Hanifi
committed
added the first draft of the az-svc-data-integration-mlw
1 parent aad5569 commit 2f94f73

30 files changed

+1803
-0
lines changed
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
export ARM_ACCESS_KEY=
2+
export ARM_CLIENT_ID=
3+
export ARM_CLIENT_SECRET=
4+
export ARM_SUBSCRIPTION_ID=
5+
export ARM_TENANT_ID=
6+
export BUILD_BUILDID=1
7+
export GO_VERSION=1.12.5
8+
export TF_VAR_remote_state_account=
9+
export TF_VAR_remote_state_container=
10+
export TF_VERSION=0.12.4
11+
export TF_WARN_OUTPUT_ERRORS=1
12+
export TF_VAR_resource_group_location=eastus
Lines changed: 139 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,139 @@
1+
# Azure Application Services
2+
3+
The `az-svc-data-integration-mlw` template is intended to be a reference for running a set of app services.
4+
5+
6+
## Use-Case
7+
8+
This particular template creates an Azure environment with a small set of fully managed microservices.
9+
10+
11+
## Scenarios this template should avoid
12+
13+
This template is an adequate solution where the service count is less than 10. For Azure customers interested with provisioning more than 10 services, we recommend using AKS. Reason being that with Kubernetes you can maximize cluster node CPU cores which helps minimize cloud resourcing costs.
14+
15+
## Technical Design
16+
Template design [specifications](docs/design/README.md).
17+
18+
## Architecture
19+
![Template Topology](docs/design/images/deployment-topology.jpg "Template Topology")
20+
21+
22+
## Prerequisites
23+
24+
1. Azure Subscription
25+
2. An available Service Principal with API Permissions granted with Admin Consent within Azure app registration. The required Azure Active Directory Graph app role is `Application.ReadWrite.OwnedBy`
26+
27+
![image](https://user-images.githubusercontent.com/7635865/71312782-d9b91800-23f4-11ea-80ee-cc646f1c74be.png)
28+
29+
3. Terraform and Go are locally installed
30+
4. Azure Storage Account is [setup](https://docs.microsoft.com/en-us/azure/terraform/terraform-backend) to store Terraform state
31+
5. Set up your Local environment variables by creating a `.env` file that contains the following information:
32+
33+
```
34+
ARM_SUBSCRIPTION_ID="<az-service-principal-subscription-id>"
35+
ARM_CLIENT_ID="<az-service-principal-client-id>"
36+
ARM_CLIENT_SECRET="<az-service-principal-auth-secret>"
37+
ARM_TENANT_ID="<az-service-principal-tenant>"
38+
ARM_ACCESS_KEY="<remote-state-storage-account-primary-key>"
39+
TF_VAR_remote_state_account="<tf-remote-state-storage-account-name>"
40+
TF_VAR_remote_state_container="<tf-remote-state-storage-container-name>"
41+
```
42+
43+
## Cost
44+
45+
Azure environment cost ballpark [estimate](https://azure.com/e/92b05a7cd1e646368ab74772e3122500). This is subject to change and is driven from the resource pricing tiers configured when the template is deployed.
46+
47+
## Deployment Steps
48+
49+
1. Execute the following commands to set up your local environment variables:
50+
51+
*Note for Windows Users using WSL*: We recommend running dos2unix utility on the environment file via `dos2unix .env` prior to sourcing your environment variables to chop trailing newline and carriage return characters.
52+
53+
```bash
54+
# these commands setup all the environment variables needed to run this template
55+
DOT_ENV=<path to your .env file>
56+
export $(cat $DOT_ENV | xargs)
57+
```
58+
59+
2. Execute the following command to configure your local Azure CLI.
60+
61+
```bash
62+
# This logs your local Azure CLI in using the configured service principal.
63+
az login --service-principal -u $ARM_CLIENT_ID -p $ARM_CLIENT_SECRET --tenant $ARM_TENANT_ID
64+
```
65+
66+
3. Navigate to the `terraform.tfvars` terraform file. Here's a sample of the terraform.tfvars file for this template.
67+
68+
```HCL
69+
resource_group_location = "centralus"
70+
prefix = "test-services"
71+
72+
# Targets that will be configured to also setup AuthN with Easy Auth
73+
app_services = [
74+
{
75+
app_name = "tf-test-svc-1"
76+
image = null
77+
app_settings = {
78+
"one_sweet_app_setting" = "brilliant"
79+
}
80+
},
81+
{
82+
app_name = "tf-test-svc-2"
83+
image = null
84+
app_settings = {
85+
"another_sweet_svc_app_setting" = "ok"
86+
}
87+
}
88+
]
89+
```
90+
91+
4. Execute the following commands to set up your terraform workspace.
92+
93+
```bash
94+
# This configures terraform to leverage a remote backend that will help you and your
95+
# team keep consistent state
96+
terraform init -backend-config "storage_account_name=${TF_VAR_remote_state_account}" -backend-config "container_name=${TF_VAR_remote_state_container}"
97+
98+
# This command configures terraform to use a workspace unique to you. This allows you to work
99+
# without stepping over your teammate's deployments
100+
TF_WORKSPACE="az-micro-svc-$USER"
101+
terraform workspace new $TF_WORKSPACE || terraform workspace select $TF_WORKSPACE
102+
```
103+
104+
5. Execute the following commands to orchestrate a deployment.
105+
106+
```bash
107+
# See what terraform will try to deploy without actually deploying
108+
terraform plan
109+
110+
# Execute a deployment
111+
terraform apply
112+
```
113+
114+
6. Optionally execute the following command to teardown your deployment and delete your resources.
115+
116+
```bash
117+
# Destroy resources and tear down deployment. Only do this if you want to destroy your deployment.
118+
terraform destroy
119+
```
120+
121+
## Automated Testing
122+
123+
### Unit Testing
124+
125+
Navigate to the template folder `infra/templates/az-svc-data-integration-mlw`. Unit tests can be run using the following command:
126+
127+
```
128+
go test -v $(go list ./... | grep "unit")
129+
```
130+
131+
### Integration Testing
132+
133+
Please confirm that you've completed the `terraform apply` step before running the integration tests as we're validating the active terraform workspace.
134+
135+
Integration tests can be run using the following command:
136+
137+
```
138+
go test -v $(go list ./... | grep "integration")
139+
```
Lines changed: 114 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,114 @@
1+
resource "azurerm_resource_group" "app_rg" {
2+
name = local.app_rg_name
3+
location = local.region
4+
}
5+
6+
# Note: this should be uncommented for production scenarios. It is commented
7+
# to support a teardown after deployment for the CICD pipeline.
8+
# resource "azurerm_management_lock" "app_rg_lock" {
9+
# name = local.app_rg_lock
10+
# scope = azurerm_resource_group.app_rg.id
11+
# lock_level = "CanNotDelete"
12+
13+
# lifecycle {
14+
# prevent_destroy = true
15+
# }
16+
# }
17+
18+
module "network" {
19+
source = "../../modules/providers/azure/network"
20+
vnet_name = local.vnet_name
21+
resource_group_name = azurerm_resource_group.app_rg.name
22+
address_space = var.address_space
23+
subnets = local.subnets
24+
}
25+
26+
module "container_registry" {
27+
source = "../../modules/providers/azure/container-registry"
28+
container_registry_name = local.acr_name
29+
resource_group_name = azurerm_resource_group.app_rg.name
30+
container_registry_admin_enabled = false
31+
// Note: only premium ACRs allow configuration of network access restrictions
32+
container_registry_sku = var.container_registry_sku
33+
subnet_id_whitelist = module.network.subnet_ids
34+
}
35+
36+
module "app_insights" {
37+
source = "../../modules/providers/azure/app-insights"
38+
service_plan_resource_group_name = azurerm_resource_group.app_rg.name
39+
appinsights_name = local.ai_name
40+
appinsights_application_type = "web"
41+
}
42+
43+
44+
module "func_app_service_plan" {
45+
source = "../../modules/providers/azure/service-plan"
46+
resource_group_name = azurerm_resource_group.app_rg.name
47+
service_plan_name = local.func_app_sp_name
48+
# scaling_rules = var.scaling_rules
49+
service_plan_tier = var.func_app_service_plan_tier
50+
service_plan_size = var.func_app_service_plan_size
51+
service_plan_kind = var.func_app_service_plan_kind
52+
service_plan_reserved = var.func_app_service_plan_reserved
53+
}
54+
55+
56+
57+
58+
module "app_monitoring" {
59+
source = "../../modules/providers/azure/app-monitoring"
60+
resource_group_name = azurerm_resource_group.app_rg.name
61+
resource_ids = [module.func_app_service_plan.app_service_plan_id]
62+
action_group_name = var.action_group_name
63+
action_group_email_receiver = var.action_group_email_receiver
64+
metric_alert_name = var.metric_alert_name
65+
metric_alert_frequency = var.metric_alert_frequency
66+
metric_alert_period = var.metric_alert_period
67+
metric_alert_criteria_namespace = var.metric_alert_criteria_namespace
68+
metric_alert_criteria_name = var.metric_alert_criteria_name
69+
metric_alert_criteria_aggregation = var.metric_alert_criteria_aggregation
70+
metric_alert_criteria_operator = var.metric_alert_criteria_operator
71+
metric_alert_criteria_threshold = var.metric_alert_criteria_threshold
72+
monitoring_dimension_values = var.monitoring_dimension_values
73+
}
74+
75+
resource "azurerm_resource_group" "mlw_rg" {
76+
name = local.mlw_rg_name
77+
location = local.region
78+
}
79+
80+
module "mlw_app_insights" {
81+
source = "../../modules/providers/azure/app-insights"
82+
service_plan_resource_group_name = azurerm_resource_group.mlw_rg.name
83+
appinsights_name = local.mlw_ai_name
84+
appinsights_application_type = "web"
85+
}
86+
87+
module "ml_workspace" {
88+
source = "../../modules/providers/azure/ml-workspace"
89+
name = local.mlw_name
90+
resource_group_name = azurerm_resource_group.mlw_rg.name
91+
application_insights_id = module.mlw_app_insights.id
92+
key_vault_id = module.keyvault.keyvault_id
93+
storage_account_id = module.sys_storage_account.id
94+
sku_name = var.sku_name
95+
}
96+
97+
module "function_app" {
98+
source = "../../modules/providers/azure/function-app"
99+
fn_name_prefix = local.func_app_name_prefix
100+
resource_group_name = azurerm_resource_group.app_rg.name
101+
service_plan_name = module.func_app_service_plan.service_plan_name
102+
storage_account_resource_group_name = module.sys_storage_account.resource_group_name
103+
storage_account_name = module.sys_storage_account.name
104+
vnet_subnet_id = module.network.subnet_ids[0]
105+
fn_app_settings = local.func_app_settings
106+
fn_app_config = var.fn_app_config
107+
}
108+
109+
module "data-factory" {
110+
source = "../../modules/providers/azure/data-factory"
111+
data_factory_name = local.data_factory_name
112+
resource_group_name = azurerm_resource_group.app_rg.name
113+
}
114+
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
terraform {
2+
backend "azurerm" {
3+
key = "terraform.tfstate"
4+
}
5+
}
6+
7+
provider "azurerm" {
8+
version = "~>2.6.0"
9+
features {}
10+
}

0 commit comments

Comments
 (0)