无法在Terraform模块中使用Terraform.tfvars
面对某些问题,可以在模块内使用Terraform.TFVAR。 我的文件夹结构是
module/
main.tf
variable.tf
terraform.tfvars
demo.tf
provider.tf
emo.tf的代码在
module "module" {
source = "./module"
}
模块文件夹内,我在变量内声明了变量,并将其值放在terraform.tfvars中。
当我运行Terraform计划时,它显示出来,
Error: Missing required argument
on main.tf line 1, in module "module":
1: module "module" {
The argument "<variable_name>" is required, but no definition was found.
请让我知道解决方案,谢谢。
(当我将值作为默认变量中的值放置时,它是在工作文件。)
有关更多详细信息,我将在下面添加所有文件
-Main.tf
resource "aws_glue_catalog_database" "glue_database_demo" {
name = var.database_name # var
location_uri = "s3://${var.bucket_location}" # var
}
resource "aws_glue_catalog_table" "aws_glue_catalog_table" {
name = var.table_name # var
database_name = aws_glue_catalog_database.glue_database_demo.name
table_type = "EXTERNAL_TABLE"
parameters = {
EXTERNAL = "TRUE"
"parquet.compression" = "SNAPPY"
}
storage_descriptor {
location = "s3://${var.bucket_location}" # var
input_format = "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat"
output_format = "org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat"
ser_de_info {
name = "my-stream"
serialization_library = "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe"
}
columns {
name = "filekey"
type = "string"
}
columns {
name = "reead_dt"
type = "string"
}
}
partition_keys {
name = "load_dt"
type = "string"
}
}
variables.tf
variable "database_name" {
}
variable "bucket_location" {
}
variable "table_name" {
}
terraform.tfvars
database_name = "mydatabase"
bucket_location = "kgvjgfkjhglbg"
table_name = "mytable"
Facing some issue to use terraform.tfvars inside module.
My folder structure is
module/
main.tf
variable.tf
terraform.tfvars
demo.tf
provider.tf
The code of demo.tf is
module "module" {
source = "./module"
}
Inside the module folder I have decleared variables inside variable.tf and put their values inside terraform.tfvars.
when I run terraform plan then it is showing
Error: Missing required argument
on main.tf line 1, in module "module":
1: module "module" {
The argument "<variable_name>" is required, but no definition was found.
Please let me know the solution, Thanks in advance.
( When I put values as default inside variables.tf then it is working file.)
For more details, I am adding all files below -
main.tf
resource "aws_glue_catalog_database" "glue_database_demo" {
name = var.database_name # var
location_uri = "s3://${var.bucket_location}" # var
}
resource "aws_glue_catalog_table" "aws_glue_catalog_table" {
name = var.table_name # var
database_name = aws_glue_catalog_database.glue_database_demo.name
table_type = "EXTERNAL_TABLE"
parameters = {
EXTERNAL = "TRUE"
"parquet.compression" = "SNAPPY"
}
storage_descriptor {
location = "s3://${var.bucket_location}" # var
input_format = "org.apache.hadoop.hive.ql.io.parquet.MapredParquetInputFormat"
output_format = "org.apache.hadoop.hive.ql.io.parquet.MapredParquetOutputFormat"
ser_de_info {
name = "my-stream"
serialization_library = "org.apache.hadoop.hive.ql.io.parquet.serde.ParquetHiveSerDe"
}
columns {
name = "filekey"
type = "string"
}
columns {
name = "reead_dt"
type = "string"
}
}
partition_keys {
name = "load_dt"
type = "string"
}
}
variables.tf
variable "database_name" {
}
variable "bucket_location" {
}
variable "table_name" {
}
terraform.tfvars
database_name = "mydatabase"
bucket_location = "kgvjgfkjhglbg"
table_name = "mytable"
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
这不是模块的工作方式。如果您定义一个变量,则希望您在调用它时提供一个值,除非它具有按照您已经指出的默认值定义。为了使此工作起作用,调用模块时必须提供值:
另一个选项是在同一目录中定义
变量
file,以便从中调用该模块,例如,:然后,将
terraform.tfvars
复制到同一目录中,您从demo.tf
中调用模块模块的逻辑名称从
模块
到glue
,因为它更具描述性,但不是必需的。目录的最终前景应该是:
This is not how modules work. If you define a variable, it is expecting you to provide a value when you are calling it unless it has a default value defined as you have already noted. In order for this to work, you would have to provide values when calling the module:
The other option would be to define a
variables.tf
file in the same directory where you are calling the module from, e.g.,:Then, copy the
terraform.tfvars
to the same directory where you are calling the module from and in thedemo.tf
do the following:Note that I have changed the logical name of the module from
modules
toglue
as it is more descriptive, but it's not necessary.The final outlook of the directories should be:
在您的demo.tf文件中,在“模块”模块中,您需要提供输入变量值。
例如:
Within your demo.tf file, in the "modules" module you need to provide the input variables value.
For example: