我的目标是通过模块和TFvars在Terraform中实现日志分析工作区,以便将其用于其他环境(DTAP)。我正在尝试这个测试,但我得到一个错误:
文件夹结构
env-tfvars\mg-sandbox-d.tfvars
tfvars_resource_group_name = "rg-ter-mg-sandbox"
tfvars_storage_account_name = "censored"
tfvars_container_name = "tfstate"
tfvars_key = "censored.terraform.tfstate"
location = "westeurope"
log-workspace-application-name = "test-law"
modules\log-analytic-workspace\main.tf
resource "azurerm_log_analytics_workspace" "log-workspace-application" {
name = var.log-workspace-application-name
location = var.location
resource_group_name = var.tfvars_resource_group_name
sku = "PerGB2018"
retention_in_days = 30
}
modules\log-analytic-workspace\variables.tf
variable "log-workspace-application-name" {
type = string
}
variable "location" {
type = string
}
variable "tfvars_resource_group_name" {
type = string
}
$\main.tf
resource "azurerm_resource_group" "rg-test" {
name = var.tfvars_resource_group_name
location = var.location
}
module "log-analytic-workspace" {
source = "./modules/log-analytic-workspace"
name = var.log-workspace-application-name
location = var.location
resource_group_name = var.tfvars_resource_group_name
depends_on = [azurerm_resource_group.rg-test]
}
$\variables.tf
variable "location" {
type = string
}
variable "tfvars_resource_group_name" {
type = string
}
variable "tfvars_storage_account_name" {
type = string
}
variable "tfvars_container_name" {
type = string
}
variable "tfvars_key" {
type = string
}
variable "log-workspace-application-name" {
type = string
}
1条答案
按热度按时间q9rjltbz1#
我尝试在Terraform中使用DTAP TFvars模块来创建log_analytics工作空间,我能够成功地提供需求。
错误消息表明
log-workspace-application
模块缺少所需的参数tfvars_resource_group_name
和log-workspace-application-name
。要修复此错误,需要在
main.tf
文件中示例化模块时将这些参数传递给模块。文件夹结构:
我的地形配置:
env-tfvars/mg-sandbox-d.tfvars:
modules/log-analytic-workspace/main.tf:
modules/log-analytic-workspace/variables.tf:
main.tf:
variables.tf:
输出: