azure Terraform计划输出显示正在重新创建现有配置/资源

eaf3rand  于 2023-02-05  发布在  其他
关注(0)|答案(2)|浏览(122)

我现在遇到了一个奇怪的问题。我有一个通过terraform部署的应用网关。如果我尝试在前端和后端都添加端口443,terraform计划显示它将删除端口80的前端和后端,然后在添加443的沿着重新创建端口80。

~ resource "azurerm_application_gateway" "xyz" {
        id                                = "xyz"
        name                              = "xyz"
        tags                              = {
            "BusinessUnit"   = "ehs"
            "LineOfBusiness" = "corp"
        }
        # (8 unchanged attributes hidden)

      - backend_http_settings {
          - cookie_based_affinity               = "Disabled" -> null
          - id                                  = "xyz" -> null
          - name                                = "xyz" -> null
          - path                                = "/path1/" -> null
          - pick_host_name_from_backend_address = false -> null
          - port                                = 80 -> null
          - protocol                            = "Http" -> null
          - request_timeout                     = 60 -> null
          - trusted_root_certificate_names      = [] -> null
        }
      + backend_http_settings {
          + cookie_based_affinity               = "Disabled"
          + host_name                           = "xyz"
          + id                                  = (known after apply)
          + name                                = "xyz"
          + path                                = "/path1/"
          + pick_host_name_from_backend_address = false
          + port                                = 443
          + probe_id                            = (known after apply)
          + protocol                            = "Https"
          + request_timeout                     = 60
          + trusted_root_certificate_names      = [
              + "irmscer",
            ]
        }
      + backend_http_settings {
          + cookie_based_affinity               = "Disabled"
          + id                                  = "xyz"
          + name                                = "xyz"
          + path                                = "/path1/"
          + pick_host_name_from_backend_address = false
          + port                                = 80
          + protocol                            = "Http"
          + request_timeout                     = 60
          + trusted_root_certificate_names      = []
        }

      + frontend_port {
          + id   = (known after apply)
          + name = "xyz"
          + port = 443
        }

如何解决这个问题呢?我并没有指定地形使用特定的版本
这是地形后端

terraform {
  backend "azurerm" {
    storage_account_name = "xyz"
    resource_group_name  = "xyz"
    container_name       = "appgw"
    tenant_id            = "xyz"
    subscription_id      = "xyz"
    key                  = "xyz"
  }
}

provider "azurerm" {
  features {}
}
11dmarpk

11dmarpk1#

它不是重新创建整个应用程序网关。它是重新创建端口80和443的设置,这是正常的。这是正常的行为,不是一个问题。可能是,Terraform在未来的版本中解决了这类问题。

bwleehnv

bwleehnv2#

backend_http_settings协议不会侦听port 443,并且端口不支持backend pools
因此,您无法更改后端的端口,唯一受支持的端口是80
对于front end configuration,如果要将任何现有侦听器端口添加到以前的端口80,则必须再添加一个frontend port块,以便它考虑两个端口并侦听我们提供的特定端口。

  • 添加前端端口,如下所示:*
frontend_port{
    name = local.frontend_port_name_new
    port = 443
}

首先,使用侦听器端口80部署应用程序网关:

  • 我已按照 * terraform registry * 模板编写了以下脚本,并根据您的要求进行了一些更改,能够成功更新端口更改。*
provider "azurerm"{
features{}
}

resource "azurerm_resource_group" "example" {
  name     = "xxxresources"
  location = "West Europe"
}

resource "azurerm_virtual_network" "example" {
  name                = "xxxnetwork"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  address_space       = xxxx
}

resource "azurerm_subnet" "frontend" {
  name                 = "frontend"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = xxxx
}

resource "azurerm_subnet" "backend" {
  name                 = "backend"
  resource_group_name  = azurerm_resource_group.example.name
  virtual_network_name = azurerm_virtual_network.example.name
  address_prefixes     = xxx
}

resource "azurerm_public_ip" "example" {
  name                = "xxxx"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location
  allocation_method   = "Dynamic"
}

# since these variables are re-used - a locals block makes this more maintainable
locals {
  backend_address_pool_name      = "${azurerm_virtual_network.example.name}-beapname"
  frontend_port_name             = "${azurerm_virtual_network.example.name}-fendport"
  frontend_port_name_new         = "${azurerm_virtual_network.example.name}-feportnew"
  frontend_ip_configuration_name = "${azurerm_virtual_network.example.name}-fconfig"
  http_setting_name              = "${azurerm_virtual_network.example.name}-htstname"
  listener_name                  = "${azurerm_virtual_network.example.name}-httplisten"
  request_routing_rule_name      = "${azurerm_virtual_network.example.name}-rt"
  redirect_configuration_name    = "${azurerm_virtual_network.example.name}-rcfg"
}

resource "azurerm_application_gateway" "network" {
  name                = "xxxxappgateway"
  resource_group_name = azurerm_resource_group.example.name
  location            = azurerm_resource_group.example.location

  sku {
    name     = "Standard_Small"
    tier     = "Standard"
    capacity = 2
  }

  gateway_ip_configuration {
    name      = "my-gateway-ip-configuration"
    subnet_id = azurerm_subnet.frontend.id
  }

  frontend_port {
    name = local.frontend_port_name
    port = 80
  }
  frontend_port{
    name = local.frontend_port_name_new
    port = 443
}

  frontend_ip_configuration {
    name                 = local.frontend_ip_configuration_name
    public_ip_address_id = azurerm_public_ip.example.id
  }

  backend_address_pool {
    name = local.backend_address_pool_name
  }

  backend_http_settings {
    name                  = local.http_setting_name
    cookie_based_affinity = "Disabled"
    path                  = "/path1/"
    port                  = 80
    protocol              = "Http"
    request_timeout       = 60
  }

  http_listener {
    name                           = local.listener_name
    frontend_ip_configuration_name = local.frontend_ip_configuration_name
    frontend_port_name             = local.frontend_port_name
    protocol                       = "Http"
  }

  request_routing_rule {
    name                       = local.request_routing_rule_name
    rule_type                  = "Basic"
    http_listener_name         = local.listener_name
    backend_address_pool_name  = local.backend_address_pool_name
    backend_http_settings_name = local.http_setting_name
  }
}

terraform init

更新端口后terraform plan显示输出如下:

terraform apply

更改部署成功,您可以通过转到已部署的application_gateway资源***下的Activity Log来跟踪change analysis***:

相关问题