在 rundeck / terraform 中,如何使用选项块来捕获用户输入并在命令块中使用它?

问题描述 投票:0回答:1

我对 terraform 和 rundeck 非常陌生。我正在尝试使用选项块来捕获输入并在命令中使用它,但只有在使用“terraform plan”时才会出现错误。

我尝试过以下方法:

resource "rundeck_job" "my_first_rundeck" {
        name              = var.job_name
    project_name      = var.project_name
    description       = var.job_description
    schedule          = var.job_schedule

    #give the option of choosing from a dropdown list of nicknames
    option {
                name = var.nickname
        label = var.nickname
        required = true
        value_choices = var.nickname_choices
    }
    #give the option of choosing from a dropdown list of scripts,
    #to reduce the error of user input
    option {
                name = var.scripts
        label = var.scripts
        required = true
        value_choices_url = ""
        
    }

    command {
        description = "Testing for ${option.scripts}"

    }
}

我试图弄清楚行 description = "Testing for ${option.scripts}" 是如何工作的。

当我使用 terraform plan 时,出现以下错误:

╷
│ Error: Reference to undeclared resource
│ 
│   on main.tf line 38, in resource "rundeck_job" "my_first_rundeck":
│   38:                 description = "Testing for ${option.scripts}"
│ 
│ A managed resource "option" "scripts" has not been declared in the root module.

我有另一个文件(variables.tf),其中存在var.*变量

我怎样才能实现我想要的目标?

terraform rundeck
1个回答
0
投票

您需要“解析”

this
后面的$字符。所以,使用
$${option.opt1}
而不是
${option.opt1}

它的工作原理如下:

command {
  shell_command  = "echo $${option.opt1}"
}

在 Rundeck 5.6.0 上测试。

© www.soinside.com 2019 - 2024. All rights reserved.