-
Notifications
You must be signed in to change notification settings - Fork 745
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #318 from ravick4u/feature/create-azure-container-app
Added new folder to create azure container app
- Loading branch information
Showing
5 changed files
with
197 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
data "azurerm_client_config" "current" {} | ||
|
||
# Generate random resource group name | ||
resource "random_pet" "rg_name" { | ||
prefix = var.resource_group_name_prefix | ||
} | ||
|
||
resource "azurerm_resource_group" "rg" { | ||
location = var.resource_group_location | ||
name = random_pet.rg_name.id | ||
} | ||
|
||
# Generate random value for the log analytics workspace name | ||
resource "random_string" "log_analytics_workspace_name" { | ||
length = 8 | ||
lower = true | ||
numeric = false | ||
special = false | ||
upper = false | ||
} | ||
|
||
resource "azurerm_log_analytics_workspace" "log_analytics_workspace" { | ||
resource_group_name = azurerm_resource_group.rg.name | ||
location = azurerm_resource_group.rg.location | ||
|
||
name = random_string.log_analytics_workspace_name.result | ||
|
||
sku = var.log_analytics_workspace_sku | ||
retention_in_days = var.log_analytics_workspace_retention_in_days | ||
} | ||
|
||
# Generate random value for the container app environment name | ||
resource "random_string" "container_app_environment_name" { | ||
length = 8 | ||
lower = true | ||
numeric = false | ||
special = false | ||
upper = false | ||
} | ||
|
||
resource "azurerm_container_app_environment" "container_app_environment" { | ||
resource_group_name = azurerm_resource_group.rg.name | ||
location = azurerm_resource_group.rg.location | ||
|
||
name = random_string.container_app_environment_name.result | ||
|
||
log_analytics_workspace_id = azurerm_log_analytics_workspace.log_analytics_workspace.id | ||
} | ||
|
||
# Generate random value for the container app name | ||
resource "random_string" "container_app_name" { | ||
length = 8 | ||
lower = true | ||
numeric = false | ||
special = false | ||
upper = false | ||
} | ||
|
||
resource "azurerm_container_app" "container_app" { | ||
resource_group_name = azurerm_resource_group.rg.name | ||
|
||
name = random_string.container_app_name.result | ||
container_app_environment_id = azurerm_container_app_environment.container_app_environment.id | ||
|
||
revision_mode = var.container_app_revision_mode | ||
|
||
ingress { | ||
allow_insecure_connections = false | ||
external_enabled = true | ||
target_port = 80 | ||
|
||
traffic_weight { | ||
latest_revision = true | ||
percentage = 100 | ||
} | ||
} | ||
|
||
template { | ||
container { | ||
name = var.container_name | ||
image = var.container_image | ||
cpu = var.container_cpu | ||
memory = var.container_memory | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,15 @@ | ||
output "resource_group_name" { | ||
value = azurerm_resource_group.rg.name | ||
} | ||
|
||
output "log_analytics_workspace_name" { | ||
value = azurerm_log_analytics_workspace.log_analytics_workspace.name | ||
} | ||
|
||
output "container_app_environment_name" { | ||
value = azurerm_container_app_environment.container_app_environment.name | ||
} | ||
|
||
output "container_app_name" { | ||
value = azurerm_container_app.container_app.name | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
terraform { | ||
required_version = ">=1.0" | ||
|
||
required_providers { | ||
azurerm = { | ||
source = "hashicorp/azurerm" | ||
version = "~>3.0" | ||
} | ||
|
||
random = { | ||
source = "hashicorp/random" | ||
version = "~>3.0" | ||
} | ||
} | ||
} | ||
|
||
provider "azurerm" { | ||
features {} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
# Azure Container App Environment with Container App | ||
|
||
This template deploys an [Azure Container App Environment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app_environment) with [Azure Container App](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app). | ||
## Terraform resource types | ||
|
||
- [random_pet](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/pet) | ||
- [azurerm_resource_group](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/resource_group) | ||
- [random_string](https://registry.terraform.io/providers/hashicorp/random/latest/docs/resources/string) | ||
- [azurerm_container_app_environment](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app_environment) | ||
- [azurerm_container_app](https://registry.terraform.io/providers/hashicorp/azurerm/latest/docs/resources/container_app) | ||
|
||
## Variables | ||
|
||
| Name | Description | Default | | ||
|-|-|-| | ||
| `resource_group_name_prefix` | Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription. | rg | | ||
| `resource_group_location` | Location of the resource group. | eastus | | ||
| `log_analytics_workspace_sku` | Log analytics workspace sku| PerGB2018 | | ||
| `log_analytics_workspace_retention_in_days` | Log analytics workspace retention in days | 30 | | ||
| `container_app_revision_mode` | Container app revision mode | Single | | ||
| `container_name` | Container name | examplecontainerapp | | ||
| `container_image` | Container image | mcr.microsoft.com/azuredocs/containerapps-helloworld:latest | | ||
| `container_cpu` | Container cpu | 0.25 | | ||
| `container_memory` | Container memory | 0.5Gi | |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
variable "resource_group_location" { | ||
type = string | ||
description = "Location of the resource group." | ||
default = "eastus" | ||
} | ||
|
||
variable "resource_group_name_prefix" { | ||
type = string | ||
description = "Prefix of the resource group name that's combined with a random ID so name is unique in your Azure subscription." | ||
default = "rg" | ||
} | ||
|
||
variable "log_analytics_workspace_sku" { | ||
type = string | ||
description = "Log analytics workspace sku" | ||
default = "PerGB2018" | ||
} | ||
|
||
variable "log_analytics_workspace_retention_in_days" { | ||
type = number | ||
description = "Log analytics workspace retention in days" | ||
default = 30 | ||
} | ||
|
||
variable "container_app_revision_mode" { | ||
type = string | ||
description = "Container app revision mode" | ||
default = "Single" | ||
} | ||
|
||
variable "container_name" { | ||
type = string | ||
description = "Container name" | ||
default = "examplecontainerapp" | ||
} | ||
|
||
variable "container_image" { | ||
type = string | ||
description = "Container image" | ||
default = "mcr.microsoft.com/azuredocs/containerapps-helloworld:latest" | ||
} | ||
|
||
variable "container_cpu" { | ||
type = number | ||
description = "Container cpu" | ||
default = 0.25 | ||
} | ||
|
||
variable "container_memory" { | ||
type = string | ||
description = "Container memory" | ||
default = "0.5Gi" | ||
} |