Merge pull request #318 from ravick4u/feature/create-azure-container-app

Added new folder to create azure container app
This commit is contained in:
Steven 2024-05-17 15:45:15 -07:00 коммит произвёл GitHub
Родитель 8a17dd2a7b 8039a0b4c9
Коммит b083b78cc3
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
5 изменённых файлов: 197 добавлений и 0 удалений

Просмотреть файл

@ -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
}
}
}

Просмотреть файл

@ -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
}

Просмотреть файл

@ -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 {}
}

Просмотреть файл

@ -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 |

Просмотреть файл

@ -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"
}