我正在使用 Terraform 在 Azure 上工作。我想以这样一种方式构建我的代码,它应该足够模块化以使用一个 variable.tf 文件,该文件应该可以从所有目录访问(目录将具有特定的 VM 代码)。假设我有一个common_variable.tf
文件和一些目录,如 db_servers、fe_servers、be_servers 等。这些目录中的代码将使用 common_variable.tf 文件,该文件位于所有目录的上一级。目前,我的设置抛出错误,因为它没有在同一目录中找到变量。我怎样才能把它链接起来?
错误:
$ terraform init
Initializing modules...
- module.frontend_deploy
- module.network
Error getting plugins: module root:
module frontend_deploy.root: 17 error(s) occurred:
* resource 'azurerm_storage_account.storage' config: unknown variable referenced: 'location'. define it with 'variable' blocks
* resource 'azurerm_storage_account.storage' config: unknown variable referenced: 'dns_name'. define it with 'variable' blocks
* resource 'azurerm_network_interface.nic' config: unknown variable referenced: 'location'. define it with 'variable' blocks
* resource 'azurerm_public_ip.external_lb_pip' config: unknown variable referenced: 'location'. define it with 'variable' blocks
* resource 'azurerm_virtual_machine.external_nginx' config: unknown variable referenced: 'location'. define it with 'variable' blocks
* resource 'azurerm_lb.lb' config: unknown variable referenced: 'location'. define it with 'variable' blocks
* resource 'azurerm_lb_rule.lb_rule' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name
* resource 'azurerm_virtual_machine.external_nginx' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name
* resource 'azurerm_virtual_machine.external_nginx' config: unknown resource 'azurerm_availability_set.external_nginx' referenced in variable azurerm_availability_set.external_nginx.id
* resource 'azurerm_lb.lb' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name
* resource 'azurerm_lb_backend_address_pool.backend_pool' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name
* resource 'azurerm_lb_probe.lb_probe' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name
* output 'vm_fqdn': unknown resource 'azurerm_public_ip.lbpip' referenced in variable azurerm_public_ip.lbpip.fqdn
* resource 'azurerm_storage_account.storage' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name
* resource 'azurerm_network_interface.nic' config: unknown resource 'azurerm_subnet.subnet' referenced in variable azurerm_subnet.subnet.id
* resource 'azurerm_network_interface.nic' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name
* resource 'azurerm_public_ip.external_lb_pip' config: unknown resource 'azurerm_resource_group.wmic_rg' referenced in variable azurerm_resource_group.wmic_rg.name