Skip to content

Commit

Permalink
created terraform config
Browse files Browse the repository at this point in the history
  • Loading branch information
Houssem Dellai committed May 17, 2023
1 parent 2748b5f commit 70c10ce
Show file tree
Hide file tree
Showing 11 changed files with 431 additions and 0 deletions.
42 changes: 42 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# Local .terraform directories
**/.terraform/*

# .tfstate files
# *.tfstate
*.tfstate.*

# tfplan files
*tfplan
*tfplan.json

# Crash log files
crash.log

# ignore .terraform.lock.hcl
*.terraform.lock.hcl

# Exclude all .tfvars files, which are likely to contain sentitive data, such as
# password, private keys, and other secrets. These should not be part of version
# control as they are data points which are potentially sensitive and subject
# to change depending on the environment.
#
# *.tfvars

# Ignore override files as they are usually used to override resources locally and so
# are not checked in
override.tf
override.tf.json
*_override.tf
*_override.tf.json

# Include override files you do wish to add to version control using negated pattern
#
# !example_override.tf

# Include tfplan files to ignore the plan output of command: terraform plan -out=tfplan
# example: *tfplan*

# Ignore CLI configuration files
.terraformrc
terraform.rc
# .gitignore
File renamed without changes.
File renamed without changes.
17 changes: 17 additions & 0 deletions 03_create_aca_terraform/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Deploying Container Apps using Terraform

This lab will walk you through the deployment of Azure Container Apps using Terraform configuration file.
The terraform config in `main.tf` file will create the following resources:
1. Resource group
2. Azure Container Apps Environment
3. Azure Container Apps that deploys the container image from MCR registry: `mcr.microsoft.com/azuredocs/containerapps-helloworld:latest`.

To deploy this config, you need to cd into the folder where you have the `main.tf` file. Then run the following commands.

```shell
terraform init

terraform plan -out tfplan

terraform apply tfplan
```
51 changes: 51 additions & 0 deletions 03_create_aca_terraform/main.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
resource "azurerm_resource_group" "rg" {
name = "rg-containerapps-terraform"
location = "westeurope"
}

resource "azurerm_log_analytics_workspace" "workspace" {
name = "workspace-aca"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
sku = "PerGB2018"
retention_in_days = 30
}

resource "azurerm_container_app_environment" "aca_environment" {
name = "aca-environment"
location = azurerm_resource_group.rg.location
resource_group_name = azurerm_resource_group.rg.name
log_analytics_workspace_id = azurerm_log_analytics_workspace.workspace.id
}

resource "azurerm_container_app" "aca" {
name = "aca-app-demo"
container_app_environment_id = azurerm_container_app_environment.aca_environment.id
resource_group_name = azurerm_resource_group.rg.name
revision_mode = "Single"

template {
container {
name = "helloworld-app"
image = "mcr.microsoft.com/azuredocs/containerapps-helloworld:latest"
cpu = 0.25
memory = "0.5Gi"
}
}

ingress {
allow_insecure_connections = false
external_enabled = true
target_port = 80
transport = "auto"

traffic_weight {
latest_revision = true
percentage = 100
}
}
}

output "app_url" {
value = azurerm_container_app.aca.latest_revision_fqdn
}
13 changes: 13 additions & 0 deletions 03_create_aca_terraform/providers.tf
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
terraform {
required_providers {
azurerm = {
source = "hashicorp/azurerm"
version = "3.56.0"
}
}
}

provider "azurerm" {
# Configuration options
features {}
}
184 changes: 184 additions & 0 deletions 03_create_aca_terraform/terraform.tfstate
Original file line number Diff line number Diff line change
@@ -0,0 +1,184 @@
{
"version": 4,
"terraform_version": "1.4.6",
"serial": 18,
"lineage": "e6c42f27-7e8b-50c9-37fe-54910e732dc8",
"outputs": {
"app_url": {
"value": "aca-app-demo--5znv50z.ashyglacier-e49ba8fd.westeurope.azurecontainerapps.io",
"type": "string"
}
},
"resources": [
{
"mode": "managed",
"type": "azurerm_container_app",
"name": "aca",
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"container_app_environment_id": "/subscriptions/17b12858-3960-4e6f-a663-a06fdae23428/resourceGroups/rg-containerapps-terraform/providers/Microsoft.App/managedEnvironments/aca-environment",
"custom_domain_verification_id": "DF0B4BB4814E8042F44F076D46BFB6F39E274E13A710920AD11386B0425E0F63",
"dapr": [],
"id": "/subscriptions/17b12858-3960-4e6f-a663-a06fdae23428/resourceGroups/rg-containerapps-terraform/providers/Microsoft.App/containerApps/aca-app-demo",
"identity": [],
"ingress": [
{
"allow_insecure_connections": false,
"custom_domain": [],
"external_enabled": true,
"fqdn": "aca-app-demo.ashyglacier-e49ba8fd.westeurope.azurecontainerapps.io",
"target_port": 80,
"traffic_weight": [
{
"label": "",
"latest_revision": true,
"percentage": 100,
"revision_suffix": ""
}
],
"transport": "auto"
}
],
"latest_revision_fqdn": "aca-app-demo--5znv50z.ashyglacier-e49ba8fd.westeurope.azurecontainerapps.io",
"latest_revision_name": "aca-app-demo--5znv50z",
"location": "westeurope",
"name": "aca-app-demo",
"outbound_ip_addresses": [
"20.126.164.146"
],
"registry": [],
"resource_group_name": "rg-containerapps-terraform",
"revision_mode": "Single",
"secret": [],
"tags": null,
"template": [
{
"container": [
{
"args": null,
"command": null,
"cpu": 0.25,
"env": [],
"ephemeral_storage": "1Gi",
"image": "mcr.microsoft.com/azuredocs/containerapps-helloworld:latest",
"liveness_probe": [],
"memory": "0.5Gi",
"name": "helloworld-app",
"readiness_probe": [],
"startup_probe": [],
"volume_mounts": []
}
],
"max_replicas": 10,
"min_replicas": 0,
"revision_suffix": "",
"volume": []
}
],
"timeouts": null
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjoxODAwMDAwMDAwMDAwfX0=",
"dependencies": [
"azurerm_container_app_environment.aca_environment",
"azurerm_log_analytics_workspace.workspace",
"azurerm_resource_group.rg"
]
}
]
},
{
"mode": "managed",
"type": "azurerm_container_app_environment",
"name": "aca_environment",
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"default_domain": "ashyglacier-e49ba8fd.westeurope.azurecontainerapps.io",
"docker_bridge_cidr": "",
"id": "/subscriptions/17b12858-3960-4e6f-a663-a06fdae23428/resourceGroups/rg-containerapps-terraform/providers/Microsoft.App/managedEnvironments/aca-environment",
"infrastructure_subnet_id": "",
"internal_load_balancer_enabled": false,
"location": "westeurope",
"log_analytics_workspace_id": "/subscriptions/17b12858-3960-4e6f-a663-a06fdae23428/resourceGroups/rg-containerapps-terraform/providers/Microsoft.OperationalInsights/workspaces/workspace-aca",
"name": "aca-environment",
"platform_reserved_cidr": "",
"platform_reserved_dns_ip_address": "",
"resource_group_name": "rg-containerapps-terraform",
"static_ip_address": "20.103.12.61",
"tags": null,
"timeouts": null
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjoxODAwMDAwMDAwMDAwfX0=",
"dependencies": [
"azurerm_log_analytics_workspace.workspace",
"azurerm_resource_group.rg"
]
}
]
},
{
"mode": "managed",
"type": "azurerm_log_analytics_workspace",
"name": "workspace",
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
"instances": [
{
"schema_version": 3,
"attributes": {
"allow_resource_only_permissions": true,
"cmk_for_query_forced": false,
"daily_quota_gb": -1,
"id": "/subscriptions/17b12858-3960-4e6f-a663-a06fdae23428/resourceGroups/rg-containerapps-terraform/providers/Microsoft.OperationalInsights/workspaces/workspace-aca",
"internet_ingestion_enabled": true,
"internet_query_enabled": true,
"local_authentication_disabled": false,
"location": "westeurope",
"name": "workspace-aca",
"primary_shared_key": "F9AUuNLS6MYvZsYXY3fs1NEM0kf5l5TnN2Sm9GVT80MNQfwUEdgy13WbeP+p407eN2Y6wtc9AhDDrfe0MMgKOg==",
"reservation_capacity_in_gb_per_day": null,
"resource_group_name": "rg-containerapps-terraform",
"retention_in_days": 30,
"secondary_shared_key": "0JjyoGaJzK2kn6sPd8Fi/h6i6ue1NVcCozM7lfc5+QKiFGZH1nMPg1B02cuS4ui3Y5NzPaSDERmxt3GEbXZ2DA==",
"sku": "PerGB2018",
"tags": null,
"timeouts": null,
"workspace_id": "ce5887f3-d038-4ff1-bd8e-7e49d3a62032"
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjoxODAwMDAwMDAwMDAwLCJkZWxldGUiOjE4MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjoxODAwMDAwMDAwMDAwfSwic2NoZW1hX3ZlcnNpb24iOiIzIn0=",
"dependencies": [
"azurerm_resource_group.rg"
]
}
]
},
{
"mode": "managed",
"type": "azurerm_resource_group",
"name": "rg",
"provider": "provider[\"registry.terraform.io/hashicorp/azurerm\"]",
"instances": [
{
"schema_version": 0,
"attributes": {
"id": "/subscriptions/17b12858-3960-4e6f-a663-a06fdae23428/resourceGroups/rg-containerapps-terraform",
"location": "westeurope",
"name": "rg-containerapps-terraform",
"tags": null,
"timeouts": null
},
"sensitive_attributes": [],
"private": "eyJlMmJmYjczMC1lY2FhLTExZTYtOGY4OC0zNDM2M2JjN2M0YzAiOnsiY3JlYXRlIjo1NDAwMDAwMDAwMDAwLCJkZWxldGUiOjU0MDAwMDAwMDAwMDAsInJlYWQiOjMwMDAwMDAwMDAwMCwidXBkYXRlIjo1NDAwMDAwMDAwMDAwfX0="
}
]
}
],
"check_results": null
}
18 changes: 18 additions & 0 deletions 04_create_aca_apps_terraform/Readme.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Deploying Container Apps using Terraform

This lab will walk you through the deployment of Azure Container Apps using Terraform configuration file.
The terraform config in `main.tf` file will create the following resources:
1. Resource group
2. Azure Container Apps Environment
3. Azure Container Apps that deploys a backend container image from Github Container registry (GHCR): `ghcr.io/houssemdellai/containerapps-album-backend:v1`.
4. Azure Container Apps that deploys a frontend container image from Github Container registry (GHCR): `ghcr.io/houssemdellai/containerapps-album-frontend:v1`.

To deploy this config, you need to cd into the folder where you have the `main.tf` file. Then run the following commands.

```shell
terraform init

terraform plan -out tfplan

terraform apply tfplan
```
Loading

0 comments on commit 70c10ce

Please sign in to comment.