Skip to content

Commit

Permalink
Add infra part two
Browse files Browse the repository at this point in the history
  • Loading branch information
ahelland committed Jan 31, 2024
1 parent 853b310 commit b1686cf
Show file tree
Hide file tree
Showing 18 changed files with 1,383 additions and 1 deletion.
421 changes: 421 additions & 0 deletions infra/level-4/main.bicep

Large diffs are not rendered by default.

26 changes: 26 additions & 0 deletions infra/level-4/main.bicepparam
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
using './main.bicep'

param resourceTags = {
IaC: 'Bicep'
Source: 'GitHub'
}

param location = 'westeurope'

// Conditionals for granular deployment of individual services
// Note: You may see deployment errors when not enabling services,
// but it should still go through for the ones set to 'true'.
param deploy_postgres = true
param deploy_rabbitMQ = true
param deploy_redis = true

param deploy_basketAPI = true
param deploy_bff = true
param deploy_catalogAPI = true
param deploy_identityAPI = true
param deploy_orderProcessor = true
param deploy_orderingAPI = true
param deploy_paymentProcessor = true
param deploy_webApp = true
param deploy_webhooksAPI = true
param deploy_webhooksClient = true
46 changes: 46 additions & 0 deletions infra/modules/containers/container-app-acr/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
# Container App ACR

Container App ACR

## Details

{{Add detailed information about the module}}

## Parameters

| Name | Type | Required | Description |
| :-------------------------- | :-------------: | :------: | :----------------------------------------------------------------------------------------- |
| `location` | `string` | No | Specifies the location for resources. |
| `resourceTags` | `object` | No | Tags retrieved from parameter file. |
| `name` | `string` | Yes | Name of container app. |
| `containerAppEnvironmentId` | `string` | Yes | The id of the container environment to deploy app to. |
| `containerImage` | `string` | No | Image of container. Defaults to mcr quickstart. |
| `targetPort` | `int` | Yes | The port exposed on the target container. |
| `transport` | `string` | No | Which transport protocol to expose. |
| `externalIngress` | `bool` | No | Enable external ingress. |
| `minReplicas` | `int` | No | Minimum number of replicas. |
| `maxReplicas` | `int` | No | Maximum number of replicas. |
| `containerName` | `string` | No | Name of container. |
| `containerRegistry` | `string` | Yes | Registry to use for pulling images from. (Assumed to be in the form contosoacr.azurecr.io) |
| `identityName` | `string` | Yes | Id of the user-assigned managed identity to use. |
| `envVars` | `array` | No | Environment variables. |
| `serviceId` | `null | string` | No | Container App Service (Redis) to bind to. |

## Outputs

| Name | Type | Description |
| :------------ | :------: | :---------------------------------------------------------- |
| `name` | `string` | Name of the container app. |
| `principalId` | `string` | The principalId for the system managed identity of the app. |

## Examples

### Example 1

```bicep
```

### Example 2

```bicep
```
111 changes: 111 additions & 0 deletions infra/modules/containers/container-app-acr/main.bicep
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
metadata name = 'Container App ACR'
metadata description = 'Container App ACR'
metadata owner = 'ahelland'

@description('Specifies the location for resources.')
param location string = resourceGroup().location
@description('Tags retrieved from parameter file.')
param resourceTags object = {}
@description('Name of container app.')
param name string
@description('The id of the container environment to deploy app to.')
param containerAppEnvironmentId string
@description('Image of container. Defaults to mcr quickstart.')
param containerImage string = 'mcr.microsoft.com/k8se/quickstart:latest'
@description('The port exposed on the target container.')
param targetPort int
@allowed([
'Auto'
'http'
'http2'
'tcp'
])
@description('Which transport protocol to expose.')
param transport string = 'Auto'
@description('Enable external ingress.')
param externalIngress bool = true
@description('Minimum number of replicas.')
param minReplicas int = 0
@description('Maximum number of replicas.')
param maxReplicas int = 10
@description('Name of container.')
param containerName string = 'simple-hello-world-container'
@description('Registry to use for pulling images from. (Assumed to be in the form contosoacr.azurecr.io)')
param containerRegistry string
@description('Id of the user-assigned managed identity to use.')
param identityName string
@description('Environment variables.')
param envVars array = []
@description('Container App Service (Redis) to bind to.')
param serviceId string?

resource mi 'Microsoft.ManagedIdentity/userAssignedIdentities@2023-07-31-preview' existing = {
name: identityName
}

resource containerApp 'Microsoft.App/containerApps@2023-05-02-preview' = {
name: name
location: location
tags: resourceTags
identity: {
type: 'SystemAssigned,UserAssigned'
userAssignedIdentities: {
'${mi.id}':{}
}
}
properties: {
managedEnvironmentId: containerAppEnvironmentId
environmentId: containerAppEnvironmentId
workloadProfileName: 'Consumption'
configuration: {
registries: [
{
identity: mi.id
server: containerRegistry
}
]
activeRevisionsMode: 'Single'
ingress: {
external: externalIngress
targetPort: targetPort
exposedPort: 0
transport: transport
traffic: [
{
weight: 100
latestRevision: true
}
]
allowInsecure: false
}
}
template: {
serviceBinds: (!empty(serviceId)) ? [
{
serviceId: serviceId
name: 'redis'
}
] : []
containers: [
{
image: containerImage
name: containerName
env: envVars
resources: {
cpu: json('0.25')
memory: '0.5Gi'
}
}
]
scale: {
minReplicas: minReplicas
maxReplicas: maxReplicas
}
}
}
}

@description('Name of the container app.')
output name string = containerApp.name
@description('The principalId for the system managed identity of the app.')
output principalId string = containerApp.identity.principalId
208 changes: 208 additions & 0 deletions infra/modules/containers/container-app-acr/main.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,208 @@
{
"$schema": "https://schema.management.azure.com/schemas/2019-04-01/deploymentTemplate.json#",
"languageVersion": "2.0",
"contentVersion": "1.0.0.0",
"metadata": {
"_generator": {
"name": "bicep",
"version": "0.24.24.22086",
"templateHash": "8607675583624901773"
},
"name": "Container App ACR",
"description": "Container App ACR",
"owner": "ahelland"
},
"parameters": {
"location": {
"type": "string",
"defaultValue": "[resourceGroup().location]",
"metadata": {
"description": "Specifies the location for resources."
}
},
"resourceTags": {
"type": "object",
"defaultValue": {},
"metadata": {
"description": "Tags retrieved from parameter file."
}
},
"name": {
"type": "string",
"metadata": {
"description": "Name of container app."
}
},
"containerAppEnvironmentId": {
"type": "string",
"metadata": {
"description": "The id of the container environment to deploy app to."
}
},
"containerImage": {
"type": "string",
"defaultValue": "mcr.microsoft.com/k8se/quickstart:latest",
"metadata": {
"description": "Image of container. Defaults to mcr quickstart."
}
},
"targetPort": {
"type": "int",
"metadata": {
"description": "The port exposed on the target container."
}
},
"transport": {
"type": "string",
"defaultValue": "Auto",
"allowedValues": [
"Auto",
"http",
"http2",
"tcp"
],
"metadata": {
"description": "Which transport protocol to expose."
}
},
"externalIngress": {
"type": "bool",
"defaultValue": true,
"metadata": {
"description": "Enable external ingress."
}
},
"minReplicas": {
"type": "int",
"defaultValue": 0,
"metadata": {
"description": "Minimum number of replicas."
}
},
"maxReplicas": {
"type": "int",
"defaultValue": 10,
"metadata": {
"description": "Maximum number of replicas."
}
},
"containerName": {
"type": "string",
"defaultValue": "simple-hello-world-container",
"metadata": {
"description": "Name of container."
}
},
"containerRegistry": {
"type": "string",
"metadata": {
"description": "Registry to use for pulling images from. (Assumed to be in the form contosoacr.azurecr.io)"
}
},
"identityName": {
"type": "string",
"metadata": {
"description": "Id of the user-assigned managed identity to use."
}
},
"envVars": {
"type": "array",
"defaultValue": [],
"metadata": {
"description": "Environment variables."
}
},
"serviceId": {
"type": "string",
"nullable": true,
"metadata": {
"description": "Container App Service (Redis) to bind to."
}
}
},
"resources": {
"mi": {
"existing": true,
"type": "Microsoft.ManagedIdentity/userAssignedIdentities",
"apiVersion": "2023-07-31-preview",
"name": "[parameters('identityName')]"
},
"containerApp": {
"type": "Microsoft.App/containerApps",
"apiVersion": "2023-05-02-preview",
"name": "[parameters('name')]",
"location": "[parameters('location')]",
"tags": "[parameters('resourceTags')]",
"identity": {
"type": "SystemAssigned,UserAssigned",
"userAssignedIdentities": {
"[format('{0}', resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('identityName')))]": {}
}
},
"properties": {
"managedEnvironmentId": "[parameters('containerAppEnvironmentId')]",
"environmentId": "[parameters('containerAppEnvironmentId')]",
"workloadProfileName": "Consumption",
"configuration": {
"registries": [
{
"identity": "[resourceId('Microsoft.ManagedIdentity/userAssignedIdentities', parameters('identityName'))]",
"server": "[parameters('containerRegistry')]"
}
],
"activeRevisionsMode": "Single",
"ingress": {
"external": "[parameters('externalIngress')]",
"targetPort": "[parameters('targetPort')]",
"exposedPort": 0,
"transport": "[parameters('transport')]",
"traffic": [
{
"weight": 100,
"latestRevision": true
}
],
"allowInsecure": false
}
},
"template": {
"serviceBinds": "[if(not(empty(parameters('serviceId'))), createArray(createObject('serviceId', parameters('serviceId'), 'name', 'redis')), createArray())]",
"containers": [
{
"image": "[parameters('containerImage')]",
"name": "[parameters('containerName')]",
"env": "[parameters('envVars')]",
"resources": {
"cpu": "[json('0.25')]",
"memory": "0.5Gi"
}
}
],
"scale": {
"minReplicas": "[parameters('minReplicas')]",
"maxReplicas": "[parameters('maxReplicas')]"
}
}
},
"dependsOn": [
"mi"
]
}
},
"outputs": {
"name": {
"type": "string",
"metadata": {
"description": "Name of the container app."
},
"value": "[parameters('name')]"
},
"principalId": {
"type": "string",
"metadata": {
"description": "The principalId for the system managed identity of the app."
},
"value": "[reference('containerApp', '2023-05-02-preview', 'full').identity.principalId]"
}
}
}
Loading

0 comments on commit b1686cf

Please sign in to comment.