gpt4 book ai didi

azure - Terraform 未声明 tfvars

转载 作者:行者123 更新时间:2023-12-03 04:47:49 30 4
gpt4 key购买 nike

我是 Terraform 新手,正在编写脚本。以下是我的目录结构

folder
---.terraform
---..terraform.lock.hcl
---main.tf
---terraform.tfvars
---variables.tf

以下是我在 terraform.tfvars 上的内容。

environment    = "development"

以下是我在 main.tf 上的内容。

tags = {
environment = var.environment
}

但是这些值没有更新。以下是错误:


│ Warning: Value for undeclared variable

│ The root module does not declare a variable named "environment" but a value was found in file "terraform.tfvars". If you meant to use this value, add a "variable" block to the configuration.

│ To silence these warnings, use TF_VAR_... environment variables to provide certain "global" settings to all configurations in your organization. To reduce the verbosity of these warnings, use the
│ -compact-warnings option.


│ Warning: Value for undeclared variable

│ The root module does not declare a variable named "admin_username" but a value was found in file "terraform.tfvars". If you meant to use this value, add a "variable" block to the configuration.

│ To silence these warnings, use TF_VAR_... environment variables to provide certain "global" settings to all configurations in your organization. To reduce the verbosity of these warnings, use the
│ -compact-warnings option.


│ Warning: Values for undeclared variables

│ In addition to the other similar warnings shown, 1 other variable(s) defined without being declared.


│ Error: Reference to undeclared input variable

│ on main.tf line 22, in resource "azurerm_resource_group" "tf_example_rg":
│ 22: environment = var.environment

│ An input variable with the name "environment" has not been declared. This variable can be declared with a variable "environment" {} block.

由于我使用的是 terraform.tfvars,因此我不需要在 CLI 上提供文件名。我认为我做的一切都是正确的,但还没有发挥作用。

最佳答案

您必须使用variable实际声明您的变量堵塞。例如:

variable "environment" {}

如果您有此类声明,则必须仔细检查它们的拼写和位置。

关于azure - Terraform 未声明 tfvars,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/74821218/

30 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com