-2

我正在使用 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
4

1 回答 1

3

对于init命令,您可以使用-backend-config选项来配置后端,例如azurerm.

您可以提供单个值:

terraform init -backend-config="storage_account_name=abcd1234"

或包含后端配置值的文件的路径:

terraform init -backend-config=../shared_config.tfvars

对于planapply命令,您可以使用-var-file选项指定包含变量的文件:

terraform plan -var-file=../common_variable.tf
于 2017-12-19T10:49:46.753 回答