1. Look for the corresponding Terraform resource in the Terraform Azure Provider documentation.
2. Define the resource explicitly in your Terraform code.
3. Link the resource to its parent/dependent resource as necessary.
variable "resource_prefix" {
description = "Specifies a prefix for all the resource names."
type = string
}
variable "location" {
description = "(Required) Specifies the supported Azure location where the resource exists. Changing this forces a new resource to be created."
type = string
default = "WestEurope"
}
variable "blob_private_dns_zone" {
description = "Specifies the name of the log analytics workspace"
type = string
}
variable "azurerm_public_ip" {
description = "Specifies the name of the log analytics workspace"
type = string
}
variable "blob_private_endpoint" {
description = "Specifies the name of the log analytics workspace"
type = string
}
variable "storage_account" {
description = "Specifies the name of the log analytics workspace"
type = string
}
variable "network-security-group" {
description = "Specifies the name of the log analytics workspace"
type = string
}
variable "log_analytics_workspace_name" {
description = "Specifies the name of the log analytics workspace"
type = string
}
variable "log_analytics_retention_days" {
description = "Specifies the number of days of the retention policy for the log analytics workspace."
type = number
default = 30
}
variable "application_insights_name" {
description = "Specifies the name of the application insights resource."
type = string
}
variable "application_insights_application_type" {
description = "(Required) Specifies the type of Application Insights to create. Valid values are ios for iOS, java for Java web, MobileCenter for App Center, Node.JS for Node.js, other for General, phone for Windows Phone, store for Windows Store and web for ASP.NET. Please note these values are case sensitive; unmatched values are treated as ASP.NET by Azure. Changing this forces a new resource to be created."
type = string
default = "web"
}
variable "virtual_network" {
description = "Specifies the name of the virtual network"
type = string
}
variable "vnet_address_space" {
description = "Specifies the address prefix of the virtual network"
default = ["10.0.0.0/16"]
type = list(string)
}
variable "aca_subnet_name" {
description = "Specifies the name of the subnet"
type = string
}
variable "aca_subnet_address_prefix" {
description = "Specifies the address prefix of the Azure Container Apps environment subnet"
default = ["10.0.0.0/20"]
type = list(string)
}
variable "private_endpoint_subnet_name" {
description = "Specifies the name of the subnet"
type = string
}
variable "private_endpoint_subnet_address_prefix" {
description = "Specifies the address prefix of the private endpoints subnet"
default = ["10.0.16.0/24"]
type = list(string)
}
variable "storage_account_name" {
description = "(Optional) Specifies the name of the storage account"
type = string
}
variable "storage_account_replication_type" {
description = "(Optional) Specifies the replication type of the storage account"
default = "LRS"
type = string
validation {
condition = contains(["LRS", "ZRS", "GRS", "GZRS", "RA-GRS", "RA-GZRS"], var.storage_account_replication_type)
error_message = "The replication type of the storage account is invalid."
}
}
variable "storage_account_kind" {
description = "(Optional) Specifies the account kind of the storage account"
default = "StorageV2"
type = string
validation {
condition = contains(["Storage", "StorageV2"], var.storage_account_kind)
error_message = "The account kind of the storage account is invalid."
}
}
variable "storage_account_tier" {
description = "(Optional) Specifies the account tier of the storage account"
default = "Standard"
type = string
validation {
condition = contains(["Standard", "Premium"], var.storage_account_tier)
error_message = "The account tier of the storage account is invalid."
}
}
variable "managed_environment_name" {
description = "(Required) Specifies the name of the managed environment."
type = string
}
variable "internal_load_balancer_enabled" {
description = "(Optional) Should the Container Environment operate in Internal Load Balancing Mode? Defaults to false. Changing this forces a new resource to be created."
type = bool
default = false
}
variable "dapr_name" {
description = "(Required) Specifies the name of the dapr component."
type = string
default = "statestore"
}
variable "dapr_component_type" {
description = "(Required) Specifies the type of the dapr component."
type = string
default = "state.azure.blobstorage"
}
variable "dapr_ignore_errors" {
description = "(Required) Specifies if the component errors are ignored."
type = bool
default = false
}
variable "dapr_version" {
description = "(Required) Specifies the version of the dapr component."
type = string
default = "v1"
}
variable "dapr_init_timeout" {
description = "(Required) Specifies the init timeout of the dapr component."
type = string
default = "5s"
}
variable "dapr_scopes" {
description = "(Required) Specifies the init timeout of the dapr component."
type = list
default = ["nodeapp"]
}
variable "container_name" {
description = "Specifies the name of the container in the storage account."
type = string
default = "state"
}
variable "container_access_type" {
description = "Specifies the access type of the container in the storage account."
type = string
default = "private"
}
variable "container_apps" {
description = "Specifies the container apps in the managed environment."
type = list(object({
name = string
revision_mode = optional(string)
ingress = optional(object({
allow_insecure_connections = optional(bool)
external_enabled = optional(bool)
target_port = optional(number)
transport = optional(string)
traffic_weight = optional(list(object({
label = optional(string)
latest_revision = optional(bool)
revision_suffix = optional(string)
percentage = optional(number)
})))
}))
dapr = optional(object({
app_id = optional(string)
app_port = optional(number)
app_protocol = optional(string)
}))
secrets = optional(list(object({
name = string
value = string
})))
template = object({
containers = list(object({
name = string
image = string
args = optional(list(string))
command = optional(list(string))
cpu = optional(number)
memory = optional(string)
env = optional(list(object({
name = string
secret_name = optional(string)
value = optional(string)
})))
}))
min_replicas = optional(number)
max_replicas = optional(number)
revision_suffix = optional(string)
volume = optional(list(object({
name = string
storage_name = optional(string)
storage_type = optional(string)
})))
})
}))
default = [{
name = "nodeapp"
revision_mode = "Single"
ingress = {
external_enabled = false
target_port = 3000
transport = "http"
traffic_weight = [{
label = "blue"
latest_revision = true
revision_suffix = "blue"
percentage = 100
}]
}
dapr = {
app_id = "nodeapp"
app_port = 3000
app_protocol = "http"
}
template = {
containers = [{
name = "hello-k8s-node"
image = "dapriosamples/hello-k8s-node:latest"
cpu = 0.5
memory = "1Gi"
env = [{
name = "APP_PORT"
value = 3000
}]
}]
min_replicas = 1
max_replicas = 1
}
},
{
name = "pythonapp"
revision_mode = "Single"
dapr = {
app_id = "pythonapp"
app_port = 80
}
template = {
containers = [{
name = "hello-k8s-python"
image = "dapriosamples/hello-k8s-python:latest"
cpu = 0.5
memory = "1Gi"
}]
min_replicas = 1
max_replicas = 1
}
}]
}
2条答案
按热度按时间ibps3vxo1#
当您使用Terraform在Azure中部署资源时,Azure有时会创建额外的辅助资源来支持主要资源。这些自动生成的资源通常带有自动生成的名称。
某些Azure资源固有地依赖于其他资源。例如,当你创建虚拟机时,如果你没有指定现有的网络接口卡(NIC),Azure可能会创建其他资源。
为了避免意外,我总是,在应用任何更改之前,运行地形计划。这将显示Terraform打算创建、修改或销毁的所有资源。这是一个很好的机会,以捕捉意想不到的资源。
如果您发现有自动创建的资源,并且您希望通过Terraform定义和控制它们,您可以:
i7uaboj42#
我的问题是,我们可以使用Terraform来创建这些,这样我就可以应用命名约定,标签等。
要使用您的
own naming conventions
创建资源,下面是Terraform code
${var.resource_prefix}"
是用于所有资源的常量值。"${var.blob_private_endpoint}"
允许您在输入时定义自定义资源名称。例如,如果**“resource_prefix”设置为“Prod”,“blob_private_endpoint”设置为“demoendpoint ",则资源名称将按以下方式创建:[resource_prefix]-demoendpoint
请在所有资源中遵循相同的格式。
地形图:
下面是使用自己的命名约定创建Azure容器环境和应用程序的Terraform代码。
变量.tf
Resources
是在portal中使用我自己的命名约定创建的,如下所示。