Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

huangapple go评论59阅读模式
英文:

terraform azure logic app not importing workflow_parameters that has a $ in it

问题

以下是您要翻译的部分:

我正在尝试使用 Terraform 导入 Azure Logic App 工作流。我的模块定义如下:

resource "azurerm_logic_app_workflow" "logic_app_workflow" {
  for_each            = var.logic_app_workflows
  name                = each.value["name"]
  location            = each.value["location"]
  resource_group_name = each.value["resource_group_name"]
  enabled             = each.value["enabled"]
  workflow_parameters = { for k,v in each.value["workflow_parameters"] : k => jsonencode(v) } 
  tags               = each.value["logic_app_workflow_tags"]
}

我的变量定义如下:

variable "logic_app_workflows" {
  type = map(object({
    name                    = string
    location                = string
    resource_group_name     = string
    enabled                 = bool
    workflow_parameters     = any
    logic_app_workflow_tags = map(string)
  }))
}

我的 tfvars 文件如下:

logic_app_workflows = {
  logic_app_workflow1 = {
    name                = "test-logic"    
    location            = "canadacentral" 
    resource_group_name = "test-rg"       
    enabled             = true
    workflow_parameters = {
      connection = {
        defaultValue = {}
        type         = "Object" 
      }
    }
    logic_app_workflow_tags = {
      applicationName = "Logic App workflow"
    }
  }
}

在导入资源后,当我运行 terraform plan 时,我得到以下输出。我希望我的 tfvars 能够不创建/销毁/更改任何内容,该如何修复?

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

希望这有帮助!

英文:

I am trying to import an Azure logic App workfow using terraform. My module is defined as below :

 resource "azurerm_logic_app_workflow" "logic_app_workflow" {
  for_each            = var.logic_app_workflows
  name                = each.value["name"]
  location            = each.value["location"]
  resource_group_name = each.value["resource_group_name"]
  enabled             = each.value["enabled"]
  workflow_parameters = { for k,v in each.value["workflow_parameters"] : k =>jsonencode(v) } 
  tags               = each.value["logic_app_workflow_tags"]
}

and my variable is defined as below :

variable "logic_app_workflows" {
  type = map(object({
    name                    = string
    location                = string
    resource_group_name     = string
    enabled                 = bool
    workflow_parameters     = any
    logic_app_workflow_tags = map(string)
  }))
}

My tfvars file looks like this :

logic_app_workflows = {
  logic_app_workflow1 = {
    name                = "test-logic"    
    location            = "canadacentral" 
    resource_group_name = "test-rg"       
    enabled             = true
    workflow_parameters = {
      connection = {
        defaultValue = {}
        type         = "Object" 
      }
    }
    logic_app_workflow_tags = {
      applicationName = "Logic App workflow"
    }
  }
}

I am getting the following output when I run terraform plan after importing the resource, I want my tfvars to able to not create/destroy/change anything, how do I fix it ?
Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

答案1

得分: 1

我尝试使用**.tfvars**导入$connections,并成功获得您要查找的输出。

为了实现此配置,我的Terraform文件有两种情况。

  • 带有生命周期模块。
  • 不带生命周期模块。

让我们逐个检查每个!

1. 不带生命周期模块

我的main.tf:

resource "azurerm_logic_app_workflow" "logic_app_workflow" {
  for_each            = var.logic_app_workflows
  name                = each.value["name"]
  location            = each.value["location"]
  resource_group_name = each.value["resource_group_name"]
  enabled             = each.value["enabled"]
  workflow_parameters = { for k, v in each.value["workflow_parameters"] : k => jsonencode(v) } 
  tags                = each.value["logic_app_workflow_tags"]
}

我的vars文件如下。

.tfvars

logic_app_workflows = {
  "logic_app_workflow1" = {
    name                = "test-logicvk"    
    location            = "canadacentral" 
    resource_group_name = "v-bolliv"       
    enabled             = true
    workflow_parameters = {
      "$connections" = {
        defaultValue = {}
        type         = "Object" 
      }
      
      "connection" = {
        defaultValue = {}
        type         = "Object" 
      }
    }
    logic_app_workflow_tags = {
      applicationName = "Logic App workflow"
    }
  }
}

对于提到的脚本,输出如下:

输出:

在执行terraform apply时:

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

现在我在**.tfvars**中做一些更改,我们可以看到以下更改在状态文件中生效。

更新的**.tfvars**

logic_app_workflows = {
  "logic_app_workflow1" = {
    name                = "test-logicvk"    
    location            = "canadacentral" 
    resource_group_name = "v-bolliv"       
    enabled             = true
    workflow_parameters = {  
      "connection" = {
        defaultValue = {}
        type         = "Object" 
      }
    }
    logic_app_workflow_tags = {
      applicationName = "Logic App workflow"
    }
  }
}

输出:

这是当我执行terraform plan时的情况:

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

这是查询中提到的错误。为了克服这个问题,要在主文件main.tf中使用**"lifecycle_module"**来跟踪状态文件中的更改,并希望更改在资源中生效。

  1. 使用生命周期模块:

我的main.tf如下,与上述更新的**.tfvars**中提到的更改相同。

main.tf

resource "azurerm_logic_app_workflow" "logic_app_workflow" {
  for_each            = var.logic_app_workflows
  name                = each.value["name"]
  location            = each.value["location"]
  resource_group_name = each.value["resource_group_name"]
  enabled             = each.value["enabled"]
  workflow_parameters = { for k, v in each.value["workflow_parameters"] : k => jsonencode(v) } 
  tags                = each.value["logic_app_workflow_tags"]
 
 lifecycle {
    ignore_changes = [
      workflow_parameters,
      tags,
    ]
  }
}

现在,根据上述更新的**.tfvars**,输出如下:

输出:

这是当我运行terraform planterraform apply时的情况:

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

在这里,资源已经根据必要的更改进行了配置,但未在状态文件中进行跟踪。

这就是如何传递**"$connections"**参数,并通过在main.tf中添加生命周期模块来跳过状态文件中的更改,从而能够在资源中进行参数更改。

英文:

> I tried to import the $connections using ".tfvars" and I successfully got the output you're looking for.

To achieve this configuration my terraform files go with two cases.

  • with lifecycle module.
  • without a lifecycle module.

Let's check one by one each!

1. Without a life cycle module

my main.tf:

resource "azurerm_logic_app_workflow" "logic_app_workflow" {
  for_each            = var.logic_app_workflows
  name                = each.value["name"]
  location            = each.value["location"]
  resource_group_name = each.value["resource_group_name"]
  enabled             = each.value["enabled"]
  workflow_parameters = { for k, v in each.value["workflow_parameters"] : k => jsonencode(v) } 
  tags                = each.value["logic_app_workflow_tags"]

}

my "vars" file goes as follows.

".tfvars"

logic_app_workflows = {
  "logic_app_workflow1" = {
    name                = "test-logicvk"    
    location            = "canadacentral" 
    resource_group_name = "v-bolliv"       
    enabled             = true
    workflow_parameters = {
      "$connections" = {
        defaultValue = {}
        type         = "Object" 
      }
      
      "connection" = {
        defaultValue = {}
        type         = "Object" 
      }
    }
    logic_app_workflow_tags = {
      applicationName = "Logic App workflow"
    }
  }
}

for the script mentioned the output is

Output:

while doing `terraform apply

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

now I make some changes in ".tfvars" and we can see the changes takes place in the state file as follows.

Updated "tfvars"

logic_app_workflows = {
  "logic_app_workflow1" = {
    name                = "test-logicvk"    
    location            = "canadacentral" 
    resource_group_name = "v-bolliv"       
    enabled             = true
    workflow_parameters = {  
      "connection" = {
        defaultValue = {}
        type         = "Object" 
      }
    }
    logic_app_workflow_tags = {
      applicationName = "Logic App workflow"
    }
  }
}

Output:

This is when I Execute the terraform plan

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

This is the error mentioned in the query. In order to overcome it while tracking the changes in the state file and also want changes to be implemented in the resource we need to use "lifecycle_module" in main.tf

  1. With lifecycle module:

my main.tf goes as follows for the same changes mentioned above in updated "tfvars".

main.tf

resource "azurerm_logic_app_workflow" "logic_app_workflow" {
  for_each            = var.logic_app_workflows
  name                = each.value["name"]
  location            = each.value["location"]
  resource_group_name = each.value["resource_group_name"]
  enabled             = each.value["enabled"]
  workflow_parameters = { for k, v in each.value["workflow_parameters"] : k => jsonencode(v) } 
  tags                = each.value["logic_app_workflow_tags"]

 lifecycle {
    ignore_changes = [
      workflow_parameters,
      tags,
    ]
  }
}

now with the updated "tfvars" mentioned above the output will go as follows.

Output:

This is when I run terraform plan & terraform apply
Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

Terraform Azure逻辑应用未导入包含$符号的workflow_parameters。

Here the resources are provisioned with necessary changes but not tracked in the state file.

This is how we can pass "$connections" parameters and by adding lifecycle modules in the main.tf we can skip changes in the state file and will be able to make parameter changes in resources.

huangapple
  • 本文由 发表于 2023年7月6日 22:35:17
  • 转载请务必保留本文链接:https://go.coder-hub.com/76629956.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定