我正在尝试使用第三方提供商编写一个模块,但它一直给我以下错误
╷
│ Error: Missing required argument
│
│ The argument "base_endpoint" is required, but was not set.
╵
╷
│ Error: Invalid provider configuration
│
│ Provider "registry.terraform.io/djlemkes/airflow" requires explicit configuration. Add a provider block to the root module and configure the provider's required arguments as described in the provider
│ documentation.
│
╵
以下是我的模块代码
模块/气流/roles.tf
locals {
developer_role = jsondecode(file(var.role_json_file_path))
}
data "google_client_config" "airflow" {
provider = google
}
provider "airflow" {
base_endpoint = var.airflow_url
oauth2_token = data.google_client_config.airflow.access_token
}
resource "airflow_role" "role" {
name = var.role_name
dynamic "action" {
for_each = local.developer_role
content {
action = action.value.action
resource = action.value.resource
}
}
}
模块/气流/provider.tf
terraform {
required_version = ">= 0.13"
required_providers {
google = {
source = "hashicorp/google"
version = "~> 4.53"
}
airflow = {
source = "DJLemkes/airflow"
version = "0.10.1"
}
}
}
模块/气流/变量.tf
variable "role_name" {
type = string
description = "role name for airflow"
}
variable "role_json_file_path" {
type = string
description = "json file for airflow role"
}
variable "airflow_url" {
type = string
description = "airflow url"
}
我就是这么称呼它的。
module "def-airflow-developer" {
source = "modules/airflow"
role_name = "airflow-developer"
role_json_file_path = "./developer_role.json"
airflow_url = var.test_composer_url
}
所以有两个错误:
base_endpoint
:模块中的 airflow
提供程序需要设置 Airflow 实例 URL (base_endpoint
)。修复:
module "def-airflow-developer" {
source = "modules/airflow"
role_name = "airflow-developer"
role_json_file_path = "./developer_role.json"
airflow_url = var.test_composer_url # Pass the URL from the main configuration
}
provider.tf
:单独的
provider.tf
文件是多余的,因为您已经在 roles.tf
文件中配置提供程序。
只需删除 provider.tf
文件即可。
清理后的模块结构应如下所示:
modules/airflow/
├── roles.tf
└── variables.tf
您需要的更改
roles.tf
:
locals {
developer_role = jsondecode(file(var.role_json_file_path))
}
data "google_client_config" "airflow" {
provider = google
}
provider "airflow" {
base_endpoint = module.def-airflow-developer.airflow_url # Access URL from module input
oauth2_token = data.google_client_config.airflow.access_token
}
resource "airflow_role" "role" {
name = var.role_name
dynamic "action" {
for_each = local.developer_role
content {
action = action.value.action
resource = action.value.resource
}
}
}
这应该能让你的 Terraform 模块正常工作!
现在它使用您在调用模块时提供的
airflow_url
并直接在模块内配置气流提供程序。