将变量传递给 Terraform 模块中的 .sh 脚本

Pass variables to .sh script in Terraform module

我试图将变量传递给 Terraform 模块“matti/resource/shell”中的 .sh 脚本,但没有成功。

在main.tf中:

module "account_create" {
  source  = "matti/resource/shell"
  command = "/bin/bash ${path.module}/create_account.sh"
}

在create_account.sh

#!/bin/bash

curl -X POST -H 'api-key:'"$API_KEY"'' -H 'Content-Type:application/json' -d '{"account":{"name":"$ACCOUNT_NAME"}, "users":[{"email":"$EMAIL", "password":"$PASSWORD", "first_name":"$FIRST_NAME", "last_name":"$LAST_NAME", "role":"readonly", "owner":"true"}]}' https://***/accounts > /tmp/return.json

在variables.tf

variable "API_KEY" {
  description = "API Key"
  default = "***"
}

我不知道为什么会发生这种情况。

我找到了解决方案: 在模块中添加 environment = { var.abc }.